Files
codex/patches/rusty_v8_prebuilt_out_dir.patch
T
Sean Huang d63fe536ee Generate Rust bindings that match Bazel-built V8 archives (#57644)
## Why

Pre-generated bindings can disagree with native V8 layouts, including CppGC member storage and the inline typed-array size. Source archives need bindings generated with the same headers, defines, and target configuration.

## What changed

- Generate bindings through Bazel using the archive's C++ compilation metadata, and include them in Darwin and Linux release pairs and source builds.
- Select native Windows MSVC archives and matching bindings together with `--//:rusty_v8_from_source=true`, and generate target-specific Windows GNU bindings.
- Pin a corrected `rusty_v8` revision for Cargo and Bazel, and track native Windows LLVM tools and resources as action inputs so pin changes invalidate cached actions.
- Run release and canary Cargo smoke tests with explicit target triples, required Linux linkers, and `--include-ignored`.

## Testing

Add `codex-v8-poc` coverage for CppGC member size, alignment, tracing, and weak references; typed-array contents and backing-store promotion; and microtask queues across garbage collection and context reassignment. Enable the otherwise ignored CppGC ABI checks for Bazel source builds and staged release smoke tests.

GitOrigin-RevId: 9edfa057a0ef2e323543bb8132c070d336ded1b2
2026-10-28 04:48:23 +00:00

79 lines
2.4 KiB
Diff

# Make rusty_v8 use the Bazel-provided archive and bindings. Mark the Git
# checkout's vendored third_party directory as a package so rules_rs does not
# stage libc++ test names containing '=' as Cargo build-script runfiles.
--- a/build.rs
+++ b/build.rs
@@ -543,10 +543,15 @@
}
fn static_lib_name(suffix: &str) -> String {
- let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();
- if target_os == "windows" {
+ let target = env::var("TARGET").unwrap();
+ let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();
+ if target.contains("windows-gnullvm") {
+ // rustc looks for GNU-style archive names when bundling `-lstatic` on the
+ // gnullvm targets, even though the prebuilt release is a COFF `.lib`.
+ format!("librusty_v8{suffix}.a")
+ } else if target_os == "windows" {
format!("rusty_v8{suffix}.lib")
} else {
format!("librusty_v8{suffix}.a")
}
}
@@ -577,7 +577,23 @@
path
}
+fn out_dir_abs() -> PathBuf {
+ let cwd = env::current_dir().unwrap();
+
+ // target/debug/build/rusty_v8-d9e5a424d4f96994/out/
+ let out_dir = env::var_os("OUT_DIR").expect(
+ "The 'OUT_DIR' environment is not set (it should be something like \
+ 'target/debug/rusty_v8-{hash}').",
+ );
+
+ cwd.join(out_dir)
+}
+
fn static_lib_dir() -> PathBuf {
+ if env::var_os("RUSTY_V8_ARCHIVE").is_some() {
+ return out_dir_abs().join("gn_out").join("obj");
+ }
+
build_dir().join("gn_out").join("obj")
}
@@ -794,22 +810,23 @@
}
fn print_link_flags() {
+ let target = env::var("TARGET").unwrap();
println!("cargo:rustc-link-lib=static=rusty_v8");
let should_dyn_link_libcxx = env::var("CARGO_FEATURE_USE_CUSTOM_LIBCXX")
.is_err()
+ || (target.contains("apple") && env::var("RUSTY_V8_ARCHIVE").is_ok())
|| env::var("GN_ARGS").is_ok_and(|gn_args| {
gn_args
.split_whitespace()
.any(|ba| ba == "use_custom_libcxx=false")
});
if should_dyn_link_libcxx {
// Based on https://github.com/alexcrichton/cc-rs/blob/fba7feded71ee4f63cfe885673ead6d7b4f2f454/src/lib.rs#L2462
if let Ok(stdlib) = env::var("CXXSTDLIB") {
if !stdlib.is_empty() {
println!("cargo:rustc-link-lib=dylib={stdlib}");
}
} else {
- let target = env::var("TARGET").unwrap();
if target.contains("msvc") {
// nothing to link to
} else if target.contains("apple")
--- /dev/null
+++ b/third_party/BUILD.bazel
@@ -0,0 +1 @@
+package(default_visibility = ["//visibility:private"])