def check_environment(): try: winenv.get_msvs_installation_dir() winenv.get_winxp_sdk() winenv.get_win10_sdk() except MissingDependencyError as e: print("ERROR: {}".format(e), file=sys.stderr) sys.exit(1) for tool in ["7z", "git", "py"]: if shutil.which(tool) is None: print("ERROR: {} not found".format(tool), file=sys.stderr) sys.exit(1)
def check_environment(): ensure_bootstrap_toolchain() try: winenv.get_msvs_installation_dir() winenv.get_winxp_sdk() winenv.get_win10_sdk() except MissingDependencyError as e: print("ERROR: {}".format(e), file=sys.stderr) sys.exit(1) for tool in ["git", "py"]: if shutil.which(tool) is None: print("ERROR: {} not found".format(tool), file=sys.stderr) sys.exit(1)
def build_v8(arch: str, config: str, runtime: str, spec: PackageSpec, extra_options: List[str]): depot_dir = DEPS_DIR / "depot_tools" gn = depot_dir / "gn.bat" env = make_v8_env(depot_dir) source_dir = DEPS_DIR / "v8-checkout" / "v8" build_dir = get_tmp_path(arch, config, runtime) / "v8" if not (build_dir / "build.ninja").exists(): if build_dir.exists(): shutil.rmtree(build_dir) if config == 'Release': configuration_args = [ "is_official_build=true", "is_debug=false", "v8_enable_v8_checks=false", ] else: configuration_args = [ "is_debug=true", "v8_enable_v8_checks=true", ] (win10_sdk_dir, win10_sdk_version) = winenv.get_win10_sdk() args = " ".join([ "target_cpu=\"{}\"".format(msvc_platform_from_arch(arch)), ] + configuration_args + [ "use_crt=\"{}\"".format(runtime), "is_clang=false", "visual_studio_path=\"{}\"".format( winenv.get_msvs_installation_dir()), "visual_studio_version=\"{}\"".format(winenv.get_msvs_version()), "wdk_path=\"{}\"".format(win10_sdk_dir), "windows_sdk_path=\"{}\"".format(win10_sdk_dir), "symbol_level=0", "strip_absolute_paths_from_debug_symbols=true", ] + spec.options + extra_options) perform(gn, "gen", PurePath("..", "..", "..") / build_dir.relative_to(ROOT_DIR), "--args=" + args, cwd=source_dir, env=env) monolith_path = build_dir / "obj" / "v8_monolith.lib" perform(NINJA, "v8_monolith", cwd=build_dir, env=env) version, api_version = v8.detect_version(source_dir) prefix = get_prefix_path(arch, config, runtime) include_dir = prefix / "include" / ("v8-" + api_version) / "v8" header_dirs = [ source_dir / "include", build_dir / "gen" / "include", ] for header_dir in header_dirs: header_files = [ PurePath(path.relative_to(header_dir)) for path in header_dir.glob("**/*.h") ] copy_files(header_dir, header_files, include_dir) v8.patch_config_header(include_dir / "v8config.h", source_dir, build_dir, gn, env) lib_dir = prefix / "lib" pkgconfig_dir = lib_dir / "pkgconfig" pkgconfig_dir.mkdir(parents=True, exist_ok=True) libv8_path = lib_dir / "libv8-{}.a".format(api_version) shutil.copyfile(monolith_path, libv8_path) (pkgconfig_dir / "v8-{}.pc".format(api_version)).write_text("""\ prefix={prefix} libdir=${{prefix}}/lib includedir=${{prefix}}/include/v8-{api_version} Name: V8 Description: V8 JavaScript Engine Version: {version} Libs: -L${{libdir}} -lv8-{api_version} Libs.private: {libs_private} Cflags: -I${{includedir}} -I${{includedir}}/v8""" \ .format( prefix=prefix.as_posix(), version=version, api_version=api_version, libs_private="-lshlwapi -lwinmm" ), encoding='utf-8') manifest_lines = [ line.format(api_version=api_version) for line in [ "lib/libv8-{api_version}.a", "lib/pkgconfig/v8-{api_version}.pc", ] ] for header in include_dir.glob("**/*"): manifest_lines.append(str(header.relative_to(prefix).as_posix())) manifest_lines.sort() manifest_path = get_manifest_path("v8", arch, config, runtime) manifest_path.parent.mkdir(parents=True, exist_ok=True) manifest_path.write_text("\n".join(manifest_lines), encoding='utf-8')
def generate_meson_env(arch: str, config: str, runtime: str) -> MesonEnv: prefix = get_prefix_path(arch, config, runtime) env_dir = get_tmp_path(arch, config, runtime) env_dir.mkdir(parents=True, exist_ok=True) vc_dir = Path(winenv.get_msvs_installation_dir()) / "VC" vc_install_dir = str(vc_dir) + "\\" msvc_platform = msvc_platform_from_arch(arch) msvc_dir = Path(winenv.get_msvc_tool_dir()) msvc_bin_dir = msvc_dir / "bin" / ( "Host" + msvc_platform_from_arch(build_arch)) / msvc_platform msvc_dll_dirs = [] if arch != build_arch: build_msvc_platform = msvc_platform_from_arch(build_arch) msvc_dll_dirs.append(msvc_dir / "bin" / ("Host" + build_msvc_platform) / build_msvc_platform) (winxp_sdk_dir, winxp_sdk_version) = winenv.get_winxp_sdk() winxp_sdk_dir = Path(winxp_sdk_dir) if arch == 'x86': winxp_bin_dir = winxp_sdk_dir / "Bin" winxp_lib_dir = winxp_sdk_dir / "Lib" else: winxp_bin_dir = winxp_sdk_dir / "Bin" / msvc_platform winxp_lib_dir = winxp_sdk_dir / "Lib" / msvc_platform clflags = "/D" + " /D".join([ "_USING_V110_SDK71_", "_UNICODE", "UNICODE", ]) platform_cflags = [] if arch == 'x86': platform_cflags += ["/arch:SSE2"] cflags = " ".join(platform_cflags) cxxflags = " ".join(platform_cflags + [ # Relax C++11 compliance for XP compatibility. "/Zc:threadSafeInit-", ]) (win10_sdk_dir, win10_sdk_version) = winenv.get_win10_sdk() win10_sdk_dir = Path(win10_sdk_dir) m4_path = BOOTSTRAP_TOOLCHAIN_DIR / "bin" / "m4.exe" bison_pkgdatadir = BOOTSTRAP_TOOLCHAIN_DIR / "share" / "bison" vala_flags = "--target-glib=" + detect_target_glib() exe_path = ";".join([ str(path) for path in [ prefix / "bin", env_dir, BOOTSTRAP_TOOLCHAIN_DIR / "bin", winxp_bin_dir, msvc_bin_dir, ] + msvc_dll_dirs ]) include_path = ";".join([ str(path) for path in [ msvc_dir / "include", msvc_dir / "atlmfc" / "include", vc_dir / "Auxiliary" / "VS" / "include", win10_sdk_dir / "Include" / win10_sdk_version / "ucrt", winxp_sdk_dir / "Include", ] ]) library_path = ";".join([ str(path) for path in [ msvc_dir / "lib" / msvc_platform, msvc_dir / "atlmfc" / "lib" / msvc_platform, vc_dir / "Auxiliary" / "VS" / "lib" / msvc_platform, win10_sdk_dir / "Lib" / win10_sdk_version / "ucrt" / msvc_platform, winxp_lib_dir, ] ]) env_path = env_dir / "env.bat" env_path.write_text("""@ECHO OFF set PATH={exe_path};%PATH% set INCLUDE={include_path} set LIB={library_path} set CL={clflags} set CFLAGS={cflags} set CXXFLAGS={cxxflags} set VCINSTALLDIR={vc_install_dir} set Platform={platform} set VALA={valac} set VALAFLAGS={vala_flags} set DEPOT_TOOLS_WIN_TOOLCHAIN=0 """.format( exe_path=exe_path, include_path=include_path, library_path=library_path, clflags=clflags, cflags=cflags, cxxflags=cxxflags, vc_install_dir=vc_install_dir, platform=msvc_platform, valac=detect_bootstrap_valac(), vala_flags=vala_flags, ), encoding='utf-8') rc_path = winxp_bin_dir / "rc.exe" rc_wrapper_path = env_dir / "rc.bat" rc_wrapper_path.write_text("""@ECHO OFF SETLOCAL EnableExtensions SET _res=0 "{rc_path}" {flags} %* || SET _res=1 ENDLOCAL & SET _res=%_res% EXIT /B %_res%""".format(rc_path=rc_path, flags=clflags), encoding='utf-8') (env_dir / "meson.bat").write_text("""@ECHO OFF SETLOCAL EnableExtensions SET _res=0 py -3 "{meson_path}" %* || SET _res=1 ENDLOCAL & SET _res=%_res% EXIT /B %_res%""".format(meson_path=MESON), encoding='utf-8') pkgconfig_path = BOOTSTRAP_TOOLCHAIN_DIR / "bin" / "pkg-config.exe" pkgconfig_lib_dir = prefix / "lib" / "pkgconfig" pkgconfig_wrapper_path = env_dir / "pkg-config.bat" pkgconfig_wrapper_path.write_text("""@ECHO OFF SETLOCAL EnableExtensions SET _res=0 SET PKG_CONFIG_PATH={pkgconfig_lib_dir} "{pkgconfig_path}" --static %* || SET _res=1 ENDLOCAL & SET _res=%_res% EXIT /B %_res%""".format( pkgconfig_path=pkgconfig_path, pkgconfig_lib_dir=pkgconfig_lib_dir, ), encoding='utf-8') flex_path = BOOTSTRAP_TOOLCHAIN_DIR / "bin" / "flex.exe" flex_wrapper_path = env_dir / "flex.py" (env_dir / "flex.bat").write_text("""@ECHO OFF SETLOCAL EnableExtensions SET _res=0 py -3 "{wrapper_path}" %* || SET _res=1 ENDLOCAL & SET _res=%_res% EXIT /B %_res%""".format(wrapper_path=flex_wrapper_path), encoding='utf-8') flex_wrapper_path.write_text("""import subprocess import sys args = [arg.replace("/", "\\\\") for arg in sys.argv[1:]] sys.exit(subprocess.call([r"{flex_path}"] + args)) """.format(flex_path=flex_path), encoding='utf-8') bison_path = BOOTSTRAP_TOOLCHAIN_DIR / "bin" / "bison.exe" bison_wrapper_path = env_dir / "bison.py" (env_dir / "bison.bat").write_text("""@ECHO OFF SETLOCAL EnableExtensions SET _res=0 py -3 "{wrapper_path}" %* || SET _res=1 ENDLOCAL & SET _res=%_res% EXIT /B %_res%""".format(wrapper_path=bison_wrapper_path), encoding='utf-8') bison_wrapper_path.write_text("""\ import os import subprocess import sys os.environ["BISON_PKGDATADIR"] = r"{bison_pkgdatadir}" os.environ["M4"] = r"{m4_path}" args = [arg.replace("/", "\\\\") for arg in sys.argv[1:]] sys.exit(subprocess.call([r"{bison_path}"] + args)) """.format(bison_path=bison_path, bison_pkgdatadir=bison_pkgdatadir, m4_path=m4_path), encoding='utf-8') shell_env = {} shell_env.update(os.environ) shell_env["PATH"] = exe_path + ";" + shell_env["PATH"] shell_env["INCLUDE"] = include_path shell_env["LIB"] = library_path shell_env["CL"] = clflags shell_env["CFLAGS"] = cflags shell_env["CXXFLAGS"] = cxxflags shell_env["VCINSTALLDIR"] = vc_install_dir shell_env["Platform"] = msvc_platform shell_env["VALAC"] = detect_bootstrap_valac() shell_env["VALAFLAGS"] = vala_flags return MesonEnv(env_dir, shell_env)
def build_v8(platform, configuration, runtime): prefix = get_prefix_path(platform, configuration, runtime) lib_dir = os.path.join(prefix, "lib") pkgconfig_dir = os.path.join(lib_dir, "pkgconfig") if len(glob.glob(os.path.join(pkgconfig_dir, "v8-*.pc"))) > 0: return checkout_dir = os.path.join(ROOT_DIR, "v8-checkout") depot_dir = os.path.join(checkout_dir, "depot_tools") if not os.path.exists(depot_dir): perform( "git", "clone", "--recurse-submodules", "https://chromium.googlesource.com/chromium/tools/depot_tools.git", r"v8-checkout\depot_tools", cwd=ROOT_DIR) gclient = os.path.join(depot_dir, "gclient.bat") gn = os.path.join(depot_dir, "gn.bat") env = {} env.update(os.environ) env["PATH"] = depot_dir + ";" + env["PATH"] env["DEPOT_TOOLS_WIN_TOOLCHAIN"] = "0" config_path = os.path.join(checkout_dir, ".gclient") if not os.path.exists(config_path): spec = """solutions = [ {{ "url": "{url}", "managed": False, "name": "v8", "deps_file": "DEPS", "custom_deps": {{}}, }}, ]""" \ .format(url=make_frida_repo_url("v8")) perform(gclient, "config", "--spec", spec, cwd=checkout_dir, env=env) source_dir = os.path.join(checkout_dir, "v8") if not os.path.exists(source_dir): perform(gclient, "sync", cwd=checkout_dir, env=env) build_dir = os.path.join(get_tmp_path(platform, configuration, runtime), "v8") if not os.path.exists(os.path.join(build_dir, "build.ninja")): if os.path.exists(build_dir): shutil.rmtree(build_dir) if configuration == 'Release': configuration_args = [ "is_official_build=true", "is_debug=false", "v8_enable_v8_checks=false", ] else: configuration_args = [ "is_debug=true", "v8_enable_v8_checks=true", ] (win10_sdk_dir, win10_sdk_version) = winenv.get_win10_sdk() args = " ".join([ "target_cpu=\"{}\"".format(platform_to_msvc(platform)), ] + configuration_args + [ "use_crt=\"{}\"".format(runtime), "is_clang=false", "visual_studio_path=\"{}\"".format( winenv.get_msvs_installation_dir()), "visual_studio_version=\"{}\"".format(winenv.get_msvs_version()), "wdk_path=\"{}\"".format(win10_sdk_dir), "windows_sdk_path=\"{}\"".format(win10_sdk_dir), "symbol_level=0", "use_thin_lto=false", "v8_monolithic=true", "v8_use_external_startup_data=false", "is_component_build=false", "v8_enable_debugging_features=false", "v8_enable_disassembler=false", "v8_enable_gdbjit=false", "v8_enable_i18n_support=false", "v8_untrusted_code_mitigations=false", "treat_warnings_as_errors=false", "strip_absolute_paths_from_debug_symbols=true", "use_goma=false", "v8_embedder_string=\"-frida\"", ]) perform(gn, "gen", os.path.relpath(build_dir, start=source_dir), "--args=" + args, cwd=source_dir, env=env) monolith_path = os.path.join(build_dir, "obj", "v8_monolith.lib") perform(NINJA, "v8_monolith", cwd=build_dir, env=env) version, api_version = v8.detect_version(source_dir) include_dir = os.path.join(prefix, "include", "v8-" + api_version, "v8") for header_dir in [ os.path.join(source_dir, "include"), os.path.join(build_dir, "gen", "include") ]: header_files = [ os.path.relpath(path, header_dir) for path in glob.glob(os.path.join(header_dir, "**", "*.h"), recursive=True) ] copy_files(header_dir, header_files, include_dir) v8.patch_config_header(os.path.join(include_dir, "v8config.h"), source_dir, build_dir, gn, env) if not os.path.exists(pkgconfig_dir): os.makedirs(pkgconfig_dir) libv8_path = os.path.join(lib_dir, "libv8-{}.a".format(api_version)) shutil.copyfile(monolith_path, libv8_path) with open(os.path.join(pkgconfig_dir, "v8-{}.pc".format(api_version)), "w", encoding='utf-8') as f: f.write("""\ prefix={prefix} libdir=${{prefix}}/lib includedir=${{prefix}}/include/v8-{api_version} Name: V8 Description: V8 JavaScript Engine Version: {version} Libs: -L${{libdir}} -lv8-{api_version} Libs.private: {libs_private} Cflags: -I${{includedir}} -I${{includedir}}/v8""".format( prefix=prefix.replace("\\", "/"), version=version, api_version=api_version, libs_private="-lshlwapi -lwinmm"))
def generate_meson_env(platform, configuration, runtime): prefix = get_prefix_path(platform, configuration, runtime) env_dir = get_tmp_path(platform, configuration, runtime) if not os.path.exists(env_dir): os.makedirs(env_dir) vc_dir = os.path.join(winenv.get_msvs_installation_dir(), "VC") vc_install_dir = vc_dir + "\\" msvc_platform = platform_to_msvc(platform) msvc_dir = winenv.get_msvc_tool_dir() msvc_bin_dir = os.path.join(msvc_dir, "bin", "Host" + platform_to_msvc(build_platform), msvc_platform) msvc_dll_dirs = [] if platform != build_platform: build_msvc_platform = platform_to_msvc(build_platform) msvc_dll_dirs.append( os.path.join(msvc_dir, "bin", "Host" + build_msvc_platform, build_msvc_platform)) (winxp_sdk_dir, winxp_sdk_version) = winenv.get_winxp_sdk() if platform == 'x86': winxp_bin_dir = os.path.join(winxp_sdk_dir, "Bin") winxp_lib_dir = os.path.join(winxp_sdk_dir, "Lib") else: winxp_bin_dir = os.path.join(winxp_sdk_dir, "Bin", msvc_platform) winxp_lib_dir = os.path.join(winxp_sdk_dir, "Lib", msvc_platform) clflags = "/D" + " /D".join([ "_USING_V110_SDK71_", "_UNICODE", "UNICODE", ]) platform_cflags = [] if platform == 'x86': platform_cflags += ["/arch:SSE2"] cflags = " ".join(platform_cflags) cxxflags = " ".join(platform_cflags + [ # Relax C++11 compliance for XP compatibility. "/Zc:threadSafeInit-", ]) (win10_sdk_dir, win10_sdk_version) = winenv.get_win10_sdk() m4_path = os.path.join(BOOTSTRAP_TOOLCHAIN_DIR, "bin", "m4.exe") bison_pkgdatadir = os.path.join(BOOTSTRAP_TOOLCHAIN_DIR, "share", "bison") vala_flags = "--target-glib=" + VALA_TARGET_GLIB exe_path = ";".join([ os.path.join(prefix, "bin"), env_dir, os.path.join(BOOTSTRAP_TOOLCHAIN_DIR, "bin"), winxp_bin_dir, msvc_bin_dir, ] + msvc_dll_dirs) include_path = ";".join([ os.path.join(msvc_dir, "include"), os.path.join(msvc_dir, "atlmfc", "include"), os.path.join(vc_dir, "Auxiliary", "VS", "include"), os.path.join(win10_sdk_dir, "Include", win10_sdk_version, "ucrt"), os.path.join(winxp_sdk_dir, "Include"), ]) library_path = ";".join([ os.path.join(msvc_dir, "lib", msvc_platform), os.path.join(msvc_dir, "atlmfc", "lib", msvc_platform), os.path.join(vc_dir, "Auxiliary", "VS", "lib", msvc_platform), os.path.join(win10_sdk_dir, "Lib", win10_sdk_version, "ucrt", msvc_platform), winxp_lib_dir, ]) env_path = os.path.join(env_dir, "env.bat") with open(env_path, "w", encoding='utf-8') as f: f.write("""@ECHO OFF set PATH={exe_path};%PATH% set INCLUDE={include_path} set LIB={library_path} set CL={clflags} set CFLAGS={cflags} set CXXFLAGS={cxxflags} set VCINSTALLDIR={vc_install_dir} set Platform={platform} set VALA={valac} set VALAFLAGS={vala_flags} set DEPOT_TOOLS_WIN_TOOLCHAIN=0 """.format(exe_path=exe_path, include_path=include_path, library_path=library_path, clflags=clflags, cflags=cflags, cxxflags=cxxflags, vc_install_dir=vc_install_dir, platform=msvc_platform, valac=BOOTSTRAP_VALAC, vala_flags=vala_flags)) rc_path = os.path.join(winxp_bin_dir, "rc.exe") rc_wrapper_path = os.path.join(env_dir, "rc.bat") with open(rc_wrapper_path, "w", encoding='utf-8') as f: f.write("""@ECHO OFF SETLOCAL EnableExtensions SET _res=0 "{rc_path}" {flags} %* || SET _res=1 ENDLOCAL & SET _res=%_res% EXIT /B %_res%""".format(rc_path=rc_path, flags=clflags)) with open(os.path.join(env_dir, "meson.bat"), "w", encoding='utf-8') as f: f.write("""@ECHO OFF SETLOCAL EnableExtensions SET _res=0 py -3 "{meson_path}" %* || SET _res=1 ENDLOCAL & SET _res=%_res% EXIT /B %_res%""".format(meson_path=MESON)) pkgconfig_path = os.path.join(BOOTSTRAP_TOOLCHAIN_DIR, "bin", "pkg-config.exe") pkgconfig_lib_dir = os.path.join(prefix, "lib", "pkgconfig") pkgconfig_wrapper_path = os.path.join(env_dir, "pkg-config.bat") with open(pkgconfig_wrapper_path, "w", encoding='utf-8') as f: f.write("""@ECHO OFF SETLOCAL EnableExtensions SET _res=0 SET PKG_CONFIG_PATH={pkgconfig_lib_dir} "{pkgconfig_path}" --static %* || SET _res=1 ENDLOCAL & SET _res=%_res% EXIT /B %_res%""".format(pkgconfig_path=pkgconfig_path, pkgconfig_lib_dir=pkgconfig_lib_dir)) flex_path = os.path.join(BOOTSTRAP_TOOLCHAIN_DIR, "bin", "flex.exe") flex_wrapper_path = os.path.join(env_dir, "flex.py") with open(os.path.join(env_dir, "flex.bat"), "w", encoding='utf-8') as f: f.write("""@ECHO OFF SETLOCAL EnableExtensions SET _res=0 py -3 "{wrapper_path}" %* || SET _res=1 ENDLOCAL & SET _res=%_res% EXIT /B %_res%""".format(wrapper_path=flex_wrapper_path)) with open(flex_wrapper_path, "w", encoding='utf-8') as f: f.write("""import subprocess import sys args = [arg.replace("/", "\\\\") for arg in sys.argv[1:]] sys.exit(subprocess.call([r"{flex_path}"] + args)) """.format(flex_path=flex_path)) bison_path = os.path.join(BOOTSTRAP_TOOLCHAIN_DIR, "bin", "bison.exe") bison_wrapper_path = os.path.join(env_dir, "bison.py") with open(os.path.join(env_dir, "bison.bat"), "w", encoding='utf-8') as f: f.write("""@ECHO OFF SETLOCAL EnableExtensions SET _res=0 py -3 "{wrapper_path}" %* || SET _res=1 ENDLOCAL & SET _res=%_res% EXIT /B %_res%""".format(wrapper_path=bison_wrapper_path)) with open(bison_wrapper_path, "w", encoding='utf-8') as f: f.write("""\ import os import subprocess import sys os.environ["BISON_PKGDATADIR"] = r"{bison_pkgdatadir}" os.environ["M4"] = r"{m4_path}" args = [arg.replace("/", "\\\\") for arg in sys.argv[1:]] sys.exit(subprocess.call([r"{bison_path}"] + args)) """.format(bison_path=bison_path, bison_pkgdatadir=bison_pkgdatadir, m4_path=m4_path)) shell_env = {} shell_env.update(os.environ) shell_env["PATH"] = exe_path + ";" + shell_env["PATH"] shell_env["INCLUDE"] = include_path shell_env["LIB"] = library_path shell_env["CL"] = clflags shell_env["CFLAGS"] = cflags shell_env["CXXFLAGS"] = cxxflags shell_env["VCINSTALLDIR"] = vc_install_dir shell_env["Platform"] = msvc_platform shell_env["VALAC"] = BOOTSTRAP_VALAC shell_env["VALAFLAGS"] = vala_flags return MesonEnv(env_dir, shell_env)
def build_v8(platform, configuration, runtime): prefix = get_prefix_path(platform, configuration, runtime) lib_dir = os.path.join(prefix, "lib") pkgconfig_dir = os.path.join(lib_dir, "pkgconfig") if len(glob.glob(os.path.join(pkgconfig_dir, "v8-*.pc"))) > 0: return checkout_dir = os.path.join(ROOT_DIR, "v8-checkout") depot_dir = os.path.join(checkout_dir, "depot_tools") if not os.path.exists(depot_dir): perform("git", "clone", "--recurse-submodules", "https://chromium.googlesource.com/chromium/tools/depot_tools.git", r"v8-checkout\depot_tools", cwd=ROOT_DIR) gclient = os.path.join(depot_dir, "gclient.bat") gn = os.path.join(depot_dir, "gn.bat") env = {} env.update(os.environ) env["PATH"] = depot_dir + ";" + env["PATH"] env["DEPOT_TOOLS_WIN_TOOLCHAIN"] = "0" config_path = os.path.join(checkout_dir, ".gclient") if not os.path.exists(config_path): spec = """solutions = [ {{ "url": "{url}", "managed": False, "name": "v8", "deps_file": "DEPS", "custom_deps": {{}}, }}, ]""" \ .format(url=make_frida_repo_url("v8")) perform(gclient, "config", "--spec", spec, cwd=checkout_dir, env=env) source_dir = os.path.join(checkout_dir, "v8") if not os.path.exists(source_dir): perform(gclient, "sync", cwd=checkout_dir, env=env) build_dir = os.path.join(get_tmp_path(platform, configuration, runtime), "v8") if not os.path.exists(os.path.join(build_dir, "build.ninja")): if os.path.exists(build_dir): shutil.rmtree(build_dir) if configuration == 'Release': configuration_args = [ "is_official_build=true", "is_debug=false", "v8_enable_v8_checks=false", ] else: configuration_args = [ "is_debug=true", "v8_enable_v8_checks=true", ] (win10_sdk_dir, win10_sdk_version) = winenv.get_win10_sdk() args = " ".join([ "target_cpu=\"{}\"".format(platform_to_msvc(platform)), ] + configuration_args + [ "use_crt=\"{}\"".format(runtime), "is_clang=false", "visual_studio_path=\"{}\"".format(winenv.get_msvs_installation_dir()), "visual_studio_version=\"{}\"".format(winenv.get_msvs_version()), "wdk_path=\"{}\"".format(win10_sdk_dir), "windows_sdk_path=\"{}\"".format(win10_sdk_dir), "symbol_level=0", "use_thin_lto=false", "v8_monolithic=true", "v8_use_external_startup_data=false", "is_component_build=false", "v8_enable_debugging_features=false", "v8_enable_disassembler=false", "v8_enable_gdbjit=false", "v8_enable_i18n_support=false", "v8_untrusted_code_mitigations=false", "treat_warnings_as_errors=false", "strip_absolute_paths_from_debug_symbols=true", "use_goma=false", "v8_embedder_string=\"-frida\"", ]) perform(gn, "gen", os.path.relpath(build_dir, start=source_dir), "--args=" + args, cwd=source_dir, env=env) monolith_path = os.path.join(build_dir, "obj", "v8_monolith.lib") perform(NINJA, "v8_monolith", cwd=build_dir, env=env) version, api_version = v8.detect_version(source_dir) include_dir = os.path.join(prefix, "include", "v8-" + api_version, "v8") for header_dir in [os.path.join(source_dir, "include"), os.path.join(build_dir, "gen", "include")]: header_files = [os.path.relpath(path, header_dir) for path in glob.glob(os.path.join(header_dir, "**", "*.h"), recursive=True)] copy_files(header_dir, header_files, include_dir) if not os.path.exists(pkgconfig_dir): os.makedirs(pkgconfig_dir) libv8_path = os.path.join(lib_dir, "libv8-{}.a".format(api_version)) shutil.copyfile(monolith_path, libv8_path) with codecs.open(os.path.join(pkgconfig_dir, "v8-{}.pc".format(api_version)), "w", 'utf-8') as f: f.write("""\ prefix={prefix} libdir=${{prefix}}/lib includedir=${{prefix}}/include/v8-{api_version} Name: V8 Description: V8 JavaScript Engine Version: {version} Libs: -L${{libdir}} -lv8-{api_version} Libs.private: {libs_private} Cflags: -I${{includedir}} -I${{includedir}}/v8""".format( prefix=prefix.replace("\\", "/"), version=version, api_version=api_version, libs_private="-lshlwapi -lwinmm" ))
def generate_meson_env(platform, configuration, runtime): prefix = get_prefix_path(platform, configuration, runtime) env_dir = get_tmp_path(platform, configuration, runtime) if not os.path.exists(env_dir): os.makedirs(env_dir) vc_dir = os.path.join(winenv.get_msvs_installation_dir(), "VC") vc_install_dir = vc_dir + "\\" msvc_platform = platform_to_msvc(platform) msvc_dir = winenv.get_msvc_tool_dir() msvc_bin_dir = os.path.join(msvc_dir, "bin", "Host" + platform_to_msvc(build_platform), msvc_platform) msvc_dll_dirs = [] if platform != build_platform: build_msvc_platform = platform_to_msvc(build_platform) msvc_dll_dirs.append(os.path.join(msvc_dir, "bin", "Host" + build_msvc_platform, build_msvc_platform)) (winxp_sdk_dir, winxp_sdk_version) = winenv.get_winxp_sdk() if platform == 'x86': winxp_bin_dir = os.path.join(winxp_sdk_dir, "Bin") winxp_lib_dir = os.path.join(winxp_sdk_dir, "Lib") else: winxp_bin_dir = os.path.join(winxp_sdk_dir, "Bin", msvc_platform) winxp_lib_dir = os.path.join(winxp_sdk_dir, "Lib", msvc_platform) clflags = "/D" + " /D".join([ "_USING_V110_SDK71_", "_UNICODE", "UNICODE", ]) platform_cflags = [] if platform == 'x86': platform_cflags += ["/arch:SSE2"] cflags = " ".join(platform_cflags) cxxflags = " ".join(platform_cflags + [ # Relax C++11 compliance for XP compatibility. "/Zc:threadSafeInit-", ]) (win10_sdk_dir, win10_sdk_version) = winenv.get_win10_sdk() m4_path = os.path.join(BOOTSTRAP_TOOLCHAIN_DIR, "bin", "m4.exe") bison_pkgdatadir = os.path.join(BOOTSTRAP_TOOLCHAIN_DIR, "share", "bison") vala_flags = "--target-glib=" + VALA_TARGET_GLIB exe_path = ";".join([ os.path.join(prefix, "bin"), env_dir, os.path.join(BOOTSTRAP_TOOLCHAIN_DIR, "bin"), winxp_bin_dir, msvc_bin_dir, ] + msvc_dll_dirs) include_path = ";".join([ os.path.join(msvc_dir, "include"), os.path.join(msvc_dir, "atlmfc", "include"), os.path.join(vc_dir, "Auxiliary", "VS", "include"), os.path.join(win10_sdk_dir, "Include", win10_sdk_version, "ucrt"), os.path.join(winxp_sdk_dir, "Include"), ]) library_path = ";".join([ os.path.join(msvc_dir, "lib", msvc_platform), os.path.join(msvc_dir, "atlmfc", "lib", msvc_platform), os.path.join(vc_dir, "Auxiliary", "VS", "lib", msvc_platform), os.path.join(win10_sdk_dir, "Lib", win10_sdk_version, "ucrt", msvc_platform), winxp_lib_dir, ]) env_path = os.path.join(env_dir, "env.bat") with codecs.open(env_path, "w", 'utf-8') as f: f.write("""@ECHO OFF set PATH={exe_path};%PATH% set INCLUDE={include_path} set LIB={library_path} set CL={clflags} set CFLAGS={cflags} set CXXFLAGS={cxxflags} set VCINSTALLDIR={vc_install_dir} set Platform={platform} set VALA={valac} set VALAFLAGS={vala_flags} set DEPOT_TOOLS_WIN_TOOLCHAIN=0 """.format( exe_path=exe_path, include_path=include_path, library_path=library_path, clflags=clflags, cflags=cflags, cxxflags=cxxflags, vc_install_dir=vc_install_dir, platform=msvc_platform, valac=BOOTSTRAP_VALAC, vala_flags=vala_flags )) rc_path = os.path.join(winxp_bin_dir, "rc.exe") rc_wrapper_path = os.path.join(env_dir, "rc.bat") with codecs.open(rc_wrapper_path, "w", 'utf-8') as f: f.write("""@ECHO OFF SETLOCAL EnableExtensions SET _res=0 "{rc_path}" {flags} %* || SET _res=1 ENDLOCAL & SET _res=%_res% EXIT /B %_res%""".format(rc_path=rc_path, flags=clflags)) with codecs.open(os.path.join(env_dir, "meson.bat"), "w", 'utf-8') as f: f.write("""@ECHO OFF SETLOCAL EnableExtensions SET _res=0 py -3 "{meson_path}" %* || SET _res=1 ENDLOCAL & SET _res=%_res% EXIT /B %_res%""".format(meson_path=MESON)) pkgconfig_path = os.path.join(BOOTSTRAP_TOOLCHAIN_DIR, "bin", "pkg-config.exe") pkgconfig_lib_dir = os.path.join(prefix, "lib", "pkgconfig") pkgconfig_wrapper_path = os.path.join(env_dir, "pkg-config.bat") with codecs.open(pkgconfig_wrapper_path, "w", 'utf-8') as f: f.write("""@ECHO OFF SETLOCAL EnableExtensions SET _res=0 SET PKG_CONFIG_PATH={pkgconfig_lib_dir} "{pkgconfig_path}" --static %* || SET _res=1 ENDLOCAL & SET _res=%_res% EXIT /B %_res%""".format(pkgconfig_path=pkgconfig_path, pkgconfig_lib_dir=pkgconfig_lib_dir)) flex_path = os.path.join(BOOTSTRAP_TOOLCHAIN_DIR, "bin", "flex.exe") flex_wrapper_path = os.path.join(env_dir, "flex.py") with codecs.open(os.path.join(env_dir, "flex.bat"), "w", 'utf-8') as f: f.write("""@ECHO OFF SETLOCAL EnableExtensions SET _res=0 py -3 "{wrapper_path}" %* || SET _res=1 ENDLOCAL & SET _res=%_res% EXIT /B %_res%""".format(wrapper_path=flex_wrapper_path)) with codecs.open(flex_wrapper_path, "w", 'utf-8') as f: f.write("""import subprocess import sys args = [arg.replace("/", "\\\\") for arg in sys.argv[1:]] sys.exit(subprocess.call([r"{flex_path}"] + args)) """.format(flex_path=flex_path)) bison_path = os.path.join(BOOTSTRAP_TOOLCHAIN_DIR, "bin", "bison.exe") bison_wrapper_path = os.path.join(env_dir, "bison.py") with codecs.open(os.path.join(env_dir, "bison.bat"), "w", 'utf-8') as f: f.write("""@ECHO OFF SETLOCAL EnableExtensions SET _res=0 py -3 "{wrapper_path}" %* || SET _res=1 ENDLOCAL & SET _res=%_res% EXIT /B %_res%""".format(wrapper_path=bison_wrapper_path)) with codecs.open(bison_wrapper_path, "w", 'utf-8') as f: f.write("""\ import os import subprocess import sys os.environ["BISON_PKGDATADIR"] = r"{bison_pkgdatadir}" os.environ["M4"] = r"{m4_path}" args = [arg.replace("/", "\\\\") for arg in sys.argv[1:]] sys.exit(subprocess.call([r"{bison_path}"] + args)) """.format( bison_path=bison_path, bison_pkgdatadir=bison_pkgdatadir, m4_path=m4_path )) shell_env = {} shell_env.update(os.environ) shell_env["PATH"] = exe_path + ";" + shell_env["PATH"] shell_env["INCLUDE"] = include_path shell_env["LIB"] = library_path shell_env["CL"] = clflags shell_env["CFLAGS"] = cflags shell_env["CXXFLAGS"] = cxxflags shell_env["VCINSTALLDIR"] = vc_install_dir shell_env["Platform"] = msvc_platform shell_env["VALAC"] = BOOTSTRAP_VALAC shell_env["VALAFLAGS"] = vala_flags return MesonEnv(env_dir, shell_env)