Exemple #1
0
    def call_vcvarsall_bat(self):
        import struct
        from distutils._msvccompiler import _get_vc_env

        arch = "x64" if struct.calcsize("P") * 8 == 64 else "x86"
        vc_env = _get_vc_env(arch)
        self._compiler_env.update(vc_env)
Exemple #2
0
    def build_extensions(self):
        DEPS_PATH.mkdir(exist_ok=True)

        download_oniguruma()

        if sys.platform == "win32":
            from distutils import _msvccompiler
            from distutils.util import get_platform

            platform_name = self.compiler.plat_name or get_platform()
            platform_spec = _msvccompiler.PLAT_TO_VCVARS[platform_name]

            vc_env = _msvccompiler._get_vc_env(platform_spec)

            # if "CL" not in vc_env:
            #     vc_env["CL"] = ""
            # vc_env["CL"] += " /DONIGURUMA_EXPORT="

            build_oniguruma(environment=vc_env)
        elif sys.platform == "linux":
            environ = dict(os.environ)
            if "CFLAGS" not in environ:
                environ["CFLAGS"] = ""
            environ["CFLAGS"] += " -fPIC"
            build_oniguruma(environment=environ)
        else:
            raise Exception(f"cannot build Oniguruma for platform {sys.platform!r}")

        build_ext.build_extensions(self)
Exemple #3
0
 def run(self):
     if not ONIGMO_SRC.exists():
         download_onigmo()
         with tarfile.open(ONIGMO_TAR_GZ, "r:gz") as onigmo_tar_gz:
             onigmo_tar_gz.extractall(path=".")
     if sys.platform == "win32":
         from distutils import _msvccompiler
         from distutils.util import get_platform
         platform_name = self.compiler.plat_name or get_platform()
         platform_spec = _msvccompiler.PLAT_TO_VCVARS[platform_name]
         environ = _msvccompiler._get_vc_env(platform_spec)
         subprocess.check_call(["build_nmake.cmd"],
                               shell=True,
                               cwd=ONIGMO_SRC,
                               env=environ)
     elif sys.platform in ["linux", "darwin"]:
         environ = dict(os.environ)
         subprocess.check_call(["./autogen.sh"],
                               cwd=ONIGMO_SRC,
                               env=environ)
         subprocess.check_call(["./configure"], cwd=ONIGMO_SRC, env=environ)
         subprocess.check_call(["make"], cwd=ONIGMO_SRC, env=environ)
         subprocess.check_call(["make", "install"],
                               cwd=ONIGMO_SRC,
                               env=environ)
     else:
         raise Exception(
             f"cannot build Onigmo for platform {sys.platform!r}")
     build_py.run(self)
def overlay_windows_vcvars(env):
    from distutils._msvccompiler import _get_vc_env
    vc_env = _get_vc_env('x64')
    for k, v in env.items():
        lk = k.lower()
        if lk not in vc_env:
            vc_env[lk] = v
    return vc_env
Exemple #5
0
def _find_msbuild(plat_spec="x64"):
    # https://github.com/python/cpython/blob/master/Lib/distutils/_msvccompiler.py
    import distutils._msvccompiler as msvc
    vc_env = msvc._get_vc_env(plat_spec)
    if "vsinstalldir" not in vc_env:
        raise Exception("Unable to find any Visual Studio installation")
    return os.path.join(vc_env["vsinstalldir"], "MSBuild", "Current", "Bin",
                        "MSBuild.exe")  # noqa
def overlay_windows_vcvars(env):
    from distutils._msvccompiler import _get_vc_env
    vc_arch = 'x64' if IS_64BIT else 'x86'
    vc_env = _get_vc_env(vc_arch)
    for k, v in env.items():
        lk = k.lower()
        if lk not in vc_env:
            vc_env[lk] = v
    return vc_env
Exemple #7
0
def get_install_dir() -> str:
    """Get the installation directory of MSVC"""
    plat_name = get_platform()
    # sanity check for platforms to prevent obscure errors later.
    if plat_name not in PLAT_TO_VCVARS:
        raise DistutilsPlatformError("--plat-name must be one of {}"
                                     .format(tuple(PLAT_TO_VCVARS)))

    # Get the vcvarsall.bat spec for the requested platform.
    plat_spec = PLAT_TO_VCVARS[plat_name]
    vc_env = _get_vc_env(plat_spec)

    return vc_env["VCToolsInstallDir"]
Exemple #8
0
 def test_get_vc_env_unicode(self):
     import distutils._msvccompiler as _msvccompiler
     test_var = 'ṰḖṤṪ┅ṼẨṜ'
     test_value = '₃⁴₅'
     old_distutils_use_sdk = os.environ.pop('DISTUTILS_USE_SDK', None)
     os.environ[test_var] = test_value
     try:
         env = _msvccompiler._get_vc_env('x86')
         self.assertIn(test_var.lower(), env)
         self.assertEqual(test_value, env[test_var.lower()])
     finally:
         os.environ.pop(test_var)
         if old_distutils_use_sdk:
             os.environ['DISTUTILS_USE_SDK'] = old_distutils_use_sdk
def _overlay_windows_vcvars(env):
    from distutils._msvccompiler import _get_vc_env
    vc_arch = 'x64' if IS_64BIT else 'x86'
    vc_env = _get_vc_env(vc_arch)
    # Keys in `_get_vc_env` are always lowercase.
    # We turn them into uppercase before overlaying vcvars
    # because OS environ keys are always uppercase on Windows.
    # https://stackoverflow.com/a/7797329
    vc_env = {k.upper(): v for k, v in vc_env.items()}
    for k, v in env.items():
        uk = k.upper()
        if uk not in vc_env:
            vc_env[uk] = v
    return vc_env
    def test_get_vc_env_unicode(self):
        import distutils._msvccompiler as _msvccompiler

        test_var = 'ṰḖṤṪ┅ṼẨṜ'
        test_value = '₃⁴₅'

        # Ensure we don't early exit from _get_vc_env
        old_distutils_use_sdk = os.environ.pop('DISTUTILS_USE_SDK', None)
        os.environ[test_var] = test_value
        try:
            env = _msvccompiler._get_vc_env('x86')
            self.assertIn(test_var.lower(), env)
            self.assertEqual(test_value, env[test_var.lower()])
        finally:
            os.environ.pop(test_var)
            if old_distutils_use_sdk:
                os.environ['DISTUTILS_USE_SDK'] = old_distutils_use_sdk
Exemple #11
0
def build_skia(build_base):
    log.info("building 'skia' library")
    build_dir = os.path.join(build_base, "src", "cpp", "skia")
    build_cmd = [PYTHON2_EXE, "build_skia.py", build_dir]

    env = os.environ.copy()
    if sys.platform == "win32":
        from distutils._msvccompiler import _get_vc_env

        # for Windows, we want to build a shared skia.dll. If we build a static lib
        # then gn/ninja pass the /MT flag (static runtime library) instead of /MD,
        # and produce linker errors when building the python extension module
        build_cmd.append("--shared-lib")

        # update Visual C++ toolchain environment depending on python architecture
        arch = "x64" if struct.calcsize("P") * 8 == 64 else "x86"
        env.update(_get_vc_env(arch))

        build_cmd.extend(["--target-cpu", arch])

    subprocess.run(build_cmd, check=True, env=env)
    return build_dir