mirror of
https://github.com/openai/codex.git
synced 2026-09-05 15:18:41 +00:00
bazel: keep V8 snapshot tools host-native
This commit is contained in:
@@ -16,7 +16,7 @@ index b432f86..16e254b 100644
|
||||
load(":bazel/v8-non-pointer-compression.bzl", "v8_binary_non_pointer_compression")
|
||||
|
||||
# =================================================
|
||||
@@ -148,6 +149,14 @@ v8_flag(name = "v8_enable_trace_maps")
|
||||
@@ -148,6 +149,12 @@ v8_flag(name = "v8_enable_trace_maps")
|
||||
|
||||
v8_flag(name = "v8_enable_v8_checks")
|
||||
|
||||
@@ -25,13 +25,11 @@ index b432f86..16e254b 100644
|
||||
+v8_flag(name = "v8_use_rusty_v8_custom_libcxx")
|
||||
+
|
||||
+v8_flag(name = "v8_use_target_mksnapshot")
|
||||
+
|
||||
+v8_string(name = "v8_snapshot_target_os", default = "none")
|
||||
+
|
||||
v8_flag(name = "v8_enable_verify_csa")
|
||||
|
||||
v8_flag(name = "v8_enable_verify_heap")
|
||||
@@ -313,7 +322,7 @@ v8_int(
|
||||
@@ -313,7 +320,7 @@ v8_int(
|
||||
# If no explicit value for v8_enable_pointer_compression, we set it to 'none'.
|
||||
v8_string(
|
||||
name = "v8_enable_pointer_compression",
|
||||
@@ -40,7 +38,7 @@ index b432f86..16e254b 100644
|
||||
)
|
||||
|
||||
# Default setting for v8_enable_pointer_compression.
|
||||
@@ -513,6 +522,7 @@ v8_config(
|
||||
@@ -513,6 +520,7 @@ v8_config(
|
||||
"v8_enable_slow_dchecks": "ENABLE_SLOW_DCHECKS",
|
||||
"v8_enable_runtime_call_stats": "V8_RUNTIME_CALL_STATS",
|
||||
"v8_enable_snapshot_native_code_counters": "V8_SNAPSHOT_NATIVE_CODE_COUNTERS",
|
||||
@@ -48,137 +46,7 @@ index b432f86..16e254b 100644
|
||||
"v8_enable_trace_maps": "V8_TRACE_MAPS",
|
||||
"v8_enable_turbofan": "V8_ENABLE_TURBOFAN",
|
||||
"v8_enable_v8_checks": "V8_ENABLE_CHECKS",
|
||||
@@ -579,19 +589,19 @@ v8_config(
|
||||
},
|
||||
no_match_error = "Please specify a target cpu supported by v8",
|
||||
) + select({
|
||||
- "@v8//bazel/config:is_android": [
|
||||
+ ":v8_snapshot_target_is_android": [
|
||||
"V8_HAVE_TARGET_OS",
|
||||
"V8_TARGET_OS_ANDROID",
|
||||
],
|
||||
- "@v8//bazel/config:is_linux": [
|
||||
+ ":v8_snapshot_target_is_linux": [
|
||||
"V8_HAVE_TARGET_OS",
|
||||
"V8_TARGET_OS_LINUX",
|
||||
],
|
||||
- "@v8//bazel/config:is_macos": [
|
||||
+ ":v8_snapshot_target_is_mac": [
|
||||
"V8_HAVE_TARGET_OS",
|
||||
"V8_TARGET_OS_MACOS",
|
||||
],
|
||||
- "@v8//bazel/config:is_windows": [
|
||||
+ ":v8_snapshot_target_is_win": [
|
||||
"V8_HAVE_TARGET_OS",
|
||||
"V8_TARGET_OS_WIN",
|
||||
"UNICODE",
|
||||
@@ -661,6 +671,105 @@ filegroup(
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
+config_setting(
|
||||
+ name = "v8_snapshot_target_os_none",
|
||||
+ flag_values = {
|
||||
+ ":v8_snapshot_target_os": "none",
|
||||
+ },
|
||||
+)
|
||||
+
|
||||
+config_setting(
|
||||
+ name = "v8_snapshot_target_os_android",
|
||||
+ flag_values = {
|
||||
+ ":v8_snapshot_target_os": "android",
|
||||
+ },
|
||||
+)
|
||||
+
|
||||
+config_setting(
|
||||
+ name = "v8_snapshot_target_os_linux",
|
||||
+ flag_values = {
|
||||
+ ":v8_snapshot_target_os": "linux",
|
||||
+ },
|
||||
+)
|
||||
+
|
||||
+config_setting(
|
||||
+ name = "v8_snapshot_target_os_mac",
|
||||
+ flag_values = {
|
||||
+ ":v8_snapshot_target_os": "mac",
|
||||
+ },
|
||||
+)
|
||||
+
|
||||
+config_setting(
|
||||
+ name = "v8_snapshot_target_os_win",
|
||||
+ flag_values = {
|
||||
+ ":v8_snapshot_target_os": "win",
|
||||
+ },
|
||||
+)
|
||||
+
|
||||
+selects.config_setting_group(
|
||||
+ name = "v8_snapshot_target_default_android",
|
||||
+ match_all = [
|
||||
+ ":v8_snapshot_target_os_none",
|
||||
+ "@v8//bazel/config:is_android",
|
||||
+ ],
|
||||
+)
|
||||
+
|
||||
+selects.config_setting_group(
|
||||
+ name = "v8_snapshot_target_default_linux",
|
||||
+ match_all = [
|
||||
+ ":v8_snapshot_target_os_none",
|
||||
+ "@v8//bazel/config:is_linux",
|
||||
+ ],
|
||||
+)
|
||||
+
|
||||
+selects.config_setting_group(
|
||||
+ name = "v8_snapshot_target_default_mac",
|
||||
+ match_all = [
|
||||
+ ":v8_snapshot_target_os_none",
|
||||
+ "@v8//bazel/config:is_macos",
|
||||
+ ],
|
||||
+)
|
||||
+
|
||||
+selects.config_setting_group(
|
||||
+ name = "v8_snapshot_target_default_win",
|
||||
+ match_all = [
|
||||
+ ":v8_snapshot_target_os_none",
|
||||
+ "@v8//bazel/config:is_windows",
|
||||
+ ],
|
||||
+)
|
||||
+
|
||||
+selects.config_setting_group(
|
||||
+ name = "v8_snapshot_target_is_android",
|
||||
+ match_any = [
|
||||
+ ":v8_snapshot_target_os_android",
|
||||
+ ":v8_snapshot_target_default_android",
|
||||
+ ],
|
||||
+)
|
||||
+
|
||||
+selects.config_setting_group(
|
||||
+ name = "v8_snapshot_target_is_linux",
|
||||
+ match_any = [
|
||||
+ ":v8_snapshot_target_os_linux",
|
||||
+ ":v8_snapshot_target_default_linux",
|
||||
+ ],
|
||||
+)
|
||||
+
|
||||
+selects.config_setting_group(
|
||||
+ name = "v8_snapshot_target_is_mac",
|
||||
+ match_any = [
|
||||
+ ":v8_snapshot_target_os_mac",
|
||||
+ ":v8_snapshot_target_default_mac",
|
||||
+ ],
|
||||
+)
|
||||
+
|
||||
+selects.config_setting_group(
|
||||
+ name = "v8_snapshot_target_is_win",
|
||||
+ match_any = [
|
||||
+ ":v8_snapshot_target_os_win",
|
||||
+ ":v8_snapshot_target_default_win",
|
||||
+ ],
|
||||
+)
|
||||
+
|
||||
filegroup(
|
||||
name = "public_wasm_c_api_header_files",
|
||||
srcs = [
|
||||
@@ -4125,28 +4234,14 @@ filegroup(
|
||||
@@ -4125,28 +4133,14 @@ filegroup(
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -213,7 +81,7 @@ index b432f86..16e254b 100644
|
||||
)
|
||||
|
||||
filegroup(
|
||||
@@ -4441,6 +4536,20 @@ genrule(
|
||||
@@ -4441,6 +4435,20 @@ genrule(
|
||||
srcs = [
|
||||
"include/js_protocol.pdl",
|
||||
"src/inspector/inspector_protocol_config.json",
|
||||
@@ -234,7 +102,7 @@ index b432f86..16e254b 100644
|
||||
],
|
||||
outs = [
|
||||
"include/inspector/Debugger.h",
|
||||
@@ -4462,15 +4571,19 @@ genrule(
|
||||
@@ -4462,15 +4470,19 @@ genrule(
|
||||
"src/inspector/protocol/Schema.cpp",
|
||||
"src/inspector/protocol/Schema.h",
|
||||
],
|
||||
@@ -258,7 +126,7 @@ index b432f86..16e254b 100644
|
||||
],
|
||||
)
|
||||
|
||||
@@ -4484,6 +4597,35 @@ filegroup(
|
||||
@@ -4484,6 +4496,35 @@ filegroup(
|
||||
],
|
||||
)
|
||||
|
||||
@@ -294,7 +162,7 @@ index b432f86..16e254b 100644
|
||||
filegroup(
|
||||
name = "d8_files",
|
||||
srcs = [
|
||||
@@ -4543,6 +4685,8 @@ v8_mksnapshot(
|
||||
@@ -4543,6 +4584,8 @@ v8_mksnapshot(
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -303,7 +171,7 @@ index b432f86..16e254b 100644
|
||||
# =================================================
|
||||
# Libraries rules
|
||||
# =================================================
|
||||
@@ -4603,16 +4747,9 @@ cc_library(
|
||||
@@ -4603,16 +4646,9 @@ cc_library(
|
||||
],
|
||||
)
|
||||
|
||||
@@ -323,7 +191,7 @@ index b432f86..16e254b 100644
|
||||
)
|
||||
|
||||
v8_library(
|
||||
@@ -4629,7 +4766,7 @@ v8_library(
|
||||
@@ -4629,7 +4665,7 @@ v8_library(
|
||||
copts = ["-Wno-implicit-fallthrough"],
|
||||
icu_deps = [
|
||||
":icu/generated_torque_definitions_headers",
|
||||
@@ -332,7 +200,7 @@ index b432f86..16e254b 100644
|
||||
],
|
||||
icu_srcs = [
|
||||
":generated_regexp_special_case",
|
||||
@@ -4644,7 +4781,7 @@ v8_library(
|
||||
@@ -4644,7 +4680,7 @@ v8_library(
|
||||
],
|
||||
deps = [
|
||||
":lib_dragonbox",
|
||||
@@ -341,7 +209,7 @@ index b432f86..16e254b 100644
|
||||
":lib_fp16",
|
||||
":simdutf",
|
||||
":v8_libbase",
|
||||
@@ -4700,6 +4837,7 @@ alias(
|
||||
@@ -4700,6 +4736,7 @@ alias(
|
||||
alias(
|
||||
name = "core_lib_icu",
|
||||
actual = "icu/v8",
|
||||
@@ -349,7 +217,7 @@ index b432f86..16e254b 100644
|
||||
)
|
||||
|
||||
v8_library(
|
||||
@@ -4751,7 +4889,7 @@ v8_binary(
|
||||
@@ -4751,7 +4788,7 @@ v8_binary(
|
||||
],
|
||||
deps = [
|
||||
":v8_libbase",
|
||||
@@ -358,7 +226,7 @@ index b432f86..16e254b 100644
|
||||
],
|
||||
)
|
||||
|
||||
@@ -4791,9 +4929,20 @@ v8_binary(
|
||||
@@ -4791,9 +4828,20 @@ v8_binary(
|
||||
":icu/generated_torque_initializers",
|
||||
":icu/v8_initializers_files",
|
||||
],
|
||||
@@ -584,57 +452,15 @@ index bbe1495..934d074 100644
|
||||
}) + select({
|
||||
":should_add_rdynamic": ["-rdynamic"],
|
||||
"//conditions:default": [],
|
||||
@@ -420,12 +449,16 @@ def v8_torque_files(name, noicu_srcs, icu_srcs, args, definition_extras, initial
|
||||
)
|
||||
|
||||
def _v8_target_cpu_transition_impl(settings,
|
||||
- attr, # @unused
|
||||
+ attr,
|
||||
):
|
||||
+ outputs = {
|
||||
+ "@v8//:v8_snapshot_target_os": attr.target_os,
|
||||
+ "@v8//bazel/config:v8_target_cpu": settings["@v8//bazel/config:v8_target_cpu"],
|
||||
+ }
|
||||
+
|
||||
# Check for an existing v8_target_cpu flag.
|
||||
- if "@v8//bazel/config:v8_target_cpu" in settings:
|
||||
- if settings["@v8//bazel/config:v8_target_cpu"] != "none":
|
||||
- return {}
|
||||
+ if settings["@v8//bazel/config:v8_target_cpu"] != "none":
|
||||
+ return outputs
|
||||
|
||||
# Auto-detect target architecture based on the --cpu flag.
|
||||
mapping = {
|
||||
@@ -446,19 +479,26 @@ def _v8_target_cpu_transition_impl(settings,
|
||||
"ppc": "ppc64le",
|
||||
}
|
||||
v8_target_cpu = mapping[settings["//command_line_option:cpu"]]
|
||||
- return {"@v8//bazel/config:v8_target_cpu": v8_target_cpu}
|
||||
+ outputs["@v8//bazel/config:v8_target_cpu"] = v8_target_cpu
|
||||
+ return outputs
|
||||
|
||||
# Set the v8_target_cpu to be the correct architecture given the cpu specified
|
||||
# on the command line.
|
||||
v8_target_cpu_transition = transition(
|
||||
implementation = _v8_target_cpu_transition_impl,
|
||||
inputs = ["@v8//bazel/config:v8_target_cpu", "//command_line_option:cpu"],
|
||||
- outputs = ["@v8//bazel/config:v8_target_cpu"],
|
||||
+ outputs = [
|
||||
+ "@v8//:v8_snapshot_target_os",
|
||||
+ "@v8//bazel/config:v8_target_cpu",
|
||||
+ ],
|
||||
)
|
||||
|
||||
@@ -459,6 +488,7 @@ def _mksnapshot(ctx):
|
||||
def _mksnapshot(ctx):
|
||||
prefix = ctx.attr.prefix
|
||||
suffix = ctx.attr.suffix
|
||||
+ if ctx.attr._exec_snapshot_target_os[FlagInfo].value != ctx.attr.target_os:
|
||||
+ fail("snapshot target OS was not preserved in the exec configuration")
|
||||
+ tool = ctx.executable.target_tool if ctx.attr.use_target_tool else ctx.executable.tool
|
||||
outs = [
|
||||
ctx.actions.declare_file(prefix + "/snapshot" + suffix + ".cc"),
|
||||
ctx.actions.declare_file(prefix + "/embedded" + suffix + ".S"),
|
||||
@@ -476,7 +516,7 @@ def _mksnapshot(ctx):
|
||||
@@ -476,7 +506,7 @@ def _mksnapshot(ctx):
|
||||
"--embedded_src",
|
||||
outs[1].path,
|
||||
] + ctx.attr.args,
|
||||
@@ -643,7 +469,7 @@ index bbe1495..934d074 100644
|
||||
progress_message = "Running mksnapshot",
|
||||
)
|
||||
return [DefaultInfo(files = depset(outs))]
|
||||
@@ -491,9 +531,20 @@ _v8_mksnapshot = rule(
|
||||
@@ -491,9 +521,16 @@ _v8_mksnapshot = rule(
|
||||
executable = True,
|
||||
cfg = "exec",
|
||||
),
|
||||
@@ -657,14 +483,10 @@ index bbe1495..934d074 100644
|
||||
"target_os": attr.string(mandatory = True),
|
||||
"prefix": attr.string(mandatory = True),
|
||||
"suffix": attr.string(mandatory = True),
|
||||
+ "_exec_snapshot_target_os": attr.label(
|
||||
+ default = "@v8//:v8_snapshot_target_os",
|
||||
+ cfg = "exec",
|
||||
+ ),
|
||||
},
|
||||
cfg = v8_target_cpu_transition,
|
||||
)
|
||||
@@ -504,11 +555,17 @@ def v8_mksnapshot(name, args, suffix = ""):
|
||||
@@ -504,11 +541,17 @@ def v8_mksnapshot(name, args, suffix = ""):
|
||||
args = args,
|
||||
prefix = "noicu",
|
||||
tool = ":noicu/mksnapshot" + suffix,
|
||||
@@ -683,7 +505,7 @@ index bbe1495..934d074 100644
|
||||
}),
|
||||
)
|
||||
_v8_mksnapshot(
|
||||
@@ -516,11 +573,17 @@ def v8_mksnapshot(name, args, suffix = ""):
|
||||
@@ -516,11 +559,17 @@ def v8_mksnapshot(name, args, suffix = ""):
|
||||
args = args,
|
||||
prefix = "icu",
|
||||
tool = ":icu/mksnapshot" + suffix,
|
||||
@@ -704,12 +526,13 @@ index bbe1495..934d074 100644
|
||||
|
||||
diff --git a/mod/v8-14.9.207.2/bazel/mksnapshot_test.bzl b/mod/v8-14.9.207.2/bazel/mksnapshot_test.bzl
|
||||
new file mode 100644
|
||||
index 0000000..8970137
|
||||
index 0000000..78cbdc5
|
||||
--- /dev/null
|
||||
+++ b/mod/v8-14.9.207.2/bazel/mksnapshot_test.bzl
|
||||
@@ -0,0 +1,83 @@
|
||||
@@ -0,0 +1,121 @@
|
||||
+"""Analysis tests for V8 snapshot tool configuration."""
|
||||
+
|
||||
+load("//:bazel/defs.bzl", "v8_target_cpu_transition")
|
||||
+load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts")
|
||||
+load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
|
||||
+
|
||||
@@ -729,19 +552,36 @@ index 0000000..8970137
|
||||
+ else:
|
||||
+ asserts.true(env, executable.endswith("/mksnapshot"))
|
||||
+ target_os_index = argv.index("--target_os")
|
||||
+ asserts.equals(env, "win", argv[target_os_index + 1])
|
||||
+ asserts.equals(env, ctx.attr.expected_target_os, argv[target_os_index + 1])
|
||||
+ return analysistest.end(env)
|
||||
+
|
||||
+def _snapshot_target_defines_test_impl(ctx):
|
||||
+def _exec_define_flags_probe_impl(ctx):
|
||||
+ return [ctx.attr._define_flags[CcInfo]]
|
||||
+
|
||||
+_exec_define_flags_probe = rule(
|
||||
+ implementation = _exec_define_flags_probe_impl,
|
||||
+ attrs = {
|
||||
+ "target_os": attr.string(mandatory = True),
|
||||
+ "_define_flags": attr.label(
|
||||
+ default = "//:define_flags",
|
||||
+ cfg = "exec",
|
||||
+ providers = [CcInfo],
|
||||
+ ),
|
||||
+ },
|
||||
+ cfg = v8_target_cpu_transition,
|
||||
+)
|
||||
+
|
||||
+def _snapshot_exec_defines_test_impl(ctx):
|
||||
+ env = analysistest.begin(ctx)
|
||||
+ defines = analysistest.target_under_test(env)[CcInfo].compilation_context.defines.to_list()
|
||||
+ asserts.true(env, "V8_TARGET_OS_WIN" in defines)
|
||||
+ asserts.false(env, "V8_TARGET_OS_LINUX" in defines)
|
||||
+ asserts.true(env, "V8_TARGET_OS_LINUX" in defines)
|
||||
+ asserts.false(env, "V8_TARGET_OS_MACOS" in defines)
|
||||
+ return analysistest.end(env)
|
||||
+
|
||||
+_host_mksnapshot_tool_test = analysistest.make(
|
||||
+_windows_host_mksnapshot_tool_test = analysistest.make(
|
||||
+ _mksnapshot_tool_test_impl,
|
||||
+ attrs = {
|
||||
+ "expected_target_os": attr.string(),
|
||||
+ "expect_target_tool": attr.bool(),
|
||||
+ },
|
||||
+ config_settings = {
|
||||
@@ -749,9 +589,10 @@ index 0000000..8970137
|
||||
+ },
|
||||
+)
|
||||
+
|
||||
+_target_mksnapshot_tool_test = analysistest.make(
|
||||
+_windows_target_mksnapshot_tool_test = analysistest.make(
|
||||
+ _mksnapshot_tool_test_impl,
|
||||
+ attrs = {
|
||||
+ "expected_target_os": attr.string(),
|
||||
+ "expect_target_tool": attr.bool(),
|
||||
+ },
|
||||
+ config_settings = {
|
||||
@@ -760,34 +601,53 @@ index 0000000..8970137
|
||||
+ },
|
||||
+)
|
||||
+
|
||||
+_snapshot_target_defines_test = analysistest.make(
|
||||
+ _snapshot_target_defines_test_impl,
|
||||
+_mac_host_mksnapshot_tool_test = analysistest.make(
|
||||
+ _mksnapshot_tool_test_impl,
|
||||
+ attrs = {
|
||||
+ "expected_target_os": attr.string(),
|
||||
+ "expect_target_tool": attr.bool(),
|
||||
+ },
|
||||
+ config_settings = {
|
||||
+ "@@v8+//:v8_snapshot_target_os": "win",
|
||||
+ "//command_line_option:platforms": "@@//:local_linux",
|
||||
+ "//command_line_option:platforms": "@@llvm+//platforms:macos_amd64",
|
||||
+ },
|
||||
+)
|
||||
+
|
||||
+_snapshot_exec_defines_test = analysistest.make(
|
||||
+ _snapshot_exec_defines_test_impl,
|
||||
+)
|
||||
+
|
||||
+def mksnapshot_test_suite(name):
|
||||
+ _host_mksnapshot_tool_test(
|
||||
+ name = name + "_uses_host_tool_test",
|
||||
+ _windows_host_mksnapshot_tool_test(
|
||||
+ name = name + "_windows_uses_host_tool_test",
|
||||
+ expected_target_os = "win",
|
||||
+ target_under_test = "//:icu/generated_snapshot_files",
|
||||
+ )
|
||||
+ _target_mksnapshot_tool_test(
|
||||
+ name = name + "_uses_target_tool_test",
|
||||
+ _windows_target_mksnapshot_tool_test(
|
||||
+ name = name + "_windows_uses_target_tool_test",
|
||||
+ expected_target_os = "win",
|
||||
+ expect_target_tool = True,
|
||||
+ target_under_test = "//:icu/generated_snapshot_files",
|
||||
+ )
|
||||
+ _snapshot_target_defines_test(
|
||||
+ name = name + "_host_uses_target_defines_test",
|
||||
+ target_under_test = "//:define_flags",
|
||||
+ _mac_host_mksnapshot_tool_test(
|
||||
+ name = name + "_mac_uses_host_tool_test",
|
||||
+ expected_target_os = "mac",
|
||||
+ target_under_test = "//:icu/generated_snapshot_files",
|
||||
+ )
|
||||
+ _exec_define_flags_probe(
|
||||
+ name = name + "_mac_exec_define_flags",
|
||||
+ target_os = "mac",
|
||||
+ )
|
||||
+ _snapshot_exec_defines_test(
|
||||
+ name = name + "_mac_exec_uses_linux_defines_test",
|
||||
+ target_under_test = ":" + name + "_mac_exec_define_flags",
|
||||
+ )
|
||||
+
|
||||
+ native.test_suite(
|
||||
+ name = name,
|
||||
+ tests = [
|
||||
+ name + "_host_uses_target_defines_test",
|
||||
+ name + "_uses_host_tool_test",
|
||||
+ name + "_uses_target_tool_test",
|
||||
+ name + "_mac_exec_uses_linux_defines_test",
|
||||
+ name + "_mac_uses_host_tool_test",
|
||||
+ name + "_windows_uses_host_tool_test",
|
||||
+ name + "_windows_uses_target_tool_test",
|
||||
+ ],
|
||||
+ )
|
||||
|
||||
Reference in New Issue
Block a user