From 356ae9cce558b2fa1916548c74acf995de9ce5e1 Mon Sep 17 00:00:00 2001 From: Nicolas Luck Date: Mon, 16 Sep 2024 17:50:39 +0200 Subject: [PATCH 01/43] Change build scripts to build V8 to a dynamic library and link rusty_v8 accordingly (cherry picked from commit 3bea357418d8f26418792b0a15149533c5836cf6) (cherry picked from commit 987cd984d0b86fa55c20fcadc6730314a08de1c5) (cherry picked from commit 47ec3a0da5a1f7c3ba2377678c7c9b021ae14647) --- .gn | 2 +- build.rs | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/.gn b/.gn index b90b382106..21d2808333 100644 --- a/.gn +++ b/.gn @@ -18,7 +18,7 @@ secondary_source = "//v8/" default_args = { clang_use_chrome_plugins = false - is_component_build = false + is_component_build = true linux_use_bundled_binutils = false use_dummy_lastchange = true use_sysroot = false diff --git a/build.rs b/build.rs index 48221b6e54..6977b0c925 100644 --- a/build.rs +++ b/build.rs @@ -617,6 +617,25 @@ fn copy_archive(url: &str, filename: &Path) { fn print_link_flags() { println!("cargo:rustc-link-lib=static=rusty_v8"); + println!("cargo:rustc-link-search=native=./target/release/gn_out"); + + // Link dynamic V8 libraries + println!("cargo:rustc-link-lib=dylib=v8"); + println!("cargo:rustc-link-lib=dylib=v8_libplatform"); + println!("cargo:rustc-link-lib=dylib=v8_libbase"); + // Add other necessary libraries... + + // Platform-specific linker arguments + if cfg!(target_os = "macos") { + // macOS specific rpath + println!("cargo:rustc-link-arg=-Wl,-rpath,@loader_path/../lib"); + } else if cfg!(target_os = "linux") { + // Linux specific rpath + println!("cargo:rustc-link-arg=-Wl,-rpath,$ORIGIN/../lib"); + } else if cfg!(target_os = "windows") { + // Windows uses a different mechanism; rpath is not used + // You might need to copy the DLLs next to the executable + } let should_dyn_link_libcxx = env::var("CARGO_FEATURE_USE_CUSTOM_LIBCXX") .is_err() || env::var("GN_ARGS").map_or(false, |gn_args| { From 683815c504d23bf5205c320a31f3f7af5440a5b8 Mon Sep 17 00:00:00 2001 From: Nicolas Luck Date: Mon, 16 Sep 2024 18:27:08 +0200 Subject: [PATCH 02/43] Force V8_FROM_SOURCE (cherrypicked from 79d4c81fb174968735b7759c1eb641c19fd55bf8) (cherry picked from commit 213dbb93829b1765b69c63cd5b6221f405a70c4d) --- build.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/build.rs b/build.rs index 6977b0c925..3574a8d7f0 100644 --- a/build.rs +++ b/build.rs @@ -91,8 +91,10 @@ fn main() { false }; - // Build from source - if env::var_os("V8_FROM_SOURCE").is_some() { + + // Build from source -- FORCED for dynamic library build + // if env_bool("V8_FROM_SOURCE") { + if true { if is_asan && std::env::var_os("OPT_LEVEL").unwrap_or_default() == "0" { panic!("v8 crate cannot be compiled with OPT_LEVEL=0 and ASAN.\nTry `[profile.dev.package.v8] opt-level = 1`.\nAborting before miscompilations cause issues."); } From 9e5b8e38c185ce1caf03afb7ac68336f08f69951 Mon Sep 17 00:00:00 2001 From: Nicolas Luck Date: Thu, 19 Sep 2024 13:46:09 +0200 Subject: [PATCH 03/43] v8_monolithic = true --- .gn | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gn b/.gn index 21d2808333..6dcb54ecf8 100644 --- a/.gn +++ b/.gn @@ -81,4 +81,6 @@ default_args = { # Enable Deno-specific extra bindings deno_enable_extras = true + + v8_monolithic = true } From 793011f4bf012482ed5fd3eeb2f6bfb4a408446e Mon Sep 17 00:00:00 2001 From: Nicolas Luck Date: Thu, 19 Sep 2024 15:34:40 +0200 Subject: [PATCH 04/43] Change build settings trying to get cppgc and other unresolved symbols build --- .gn | 11 +++++++++-- build.rs | 10 +++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/.gn b/.gn index 6dcb54ecf8..e3f7e5a3c3 100644 --- a/.gn +++ b/.gn @@ -19,6 +19,15 @@ secondary_source = "//v8/" default_args = { clang_use_chrome_plugins = false is_component_build = true + v8_use_external_startup_data = false + v8_enable_symbol_visibility = true + symbol_level = 2 + use_custom_libcxx = false + # trying to get cppgc build + v8_enable_oilpan=true + is_debug = false + + linux_use_bundled_binutils = false use_dummy_lastchange = true use_sysroot = false @@ -81,6 +90,4 @@ default_args = { # Enable Deno-specific extra bindings deno_enable_extras = true - - v8_monolithic = true } diff --git a/build.rs b/build.rs index 3574a8d7f0..a84e724651 100644 --- a/build.rs +++ b/build.rs @@ -622,9 +622,17 @@ fn print_link_flags() { println!("cargo:rustc-link-search=native=./target/release/gn_out"); // Link dynamic V8 libraries - println!("cargo:rustc-link-lib=dylib=v8"); + println!("cargo:rustc-link-lib=dylib=v8_libplatform"); println!("cargo:rustc-link-lib=dylib=v8_libbase"); + println!("cargo:rustc-link-lib=dylib=v8"); + println!("cargo:rustc-link-lib=dylib=c++_chrome"); + println!("cargo:rustc-link-lib=dylib=third_party_icu_icui18n"); + println!("cargo:rustc-link-lib=dylib=icuuc"); + println!("cargo:rustc-link-lib=dylib=third_party_abseil-cpp_absl"); + println!("cargo:rustc-link-lib=dylib=cppgc"); + println!("cargo:rustc-link-lib=dylib=cppgc_base"); + println!("cargo:rustc-link-lib=dylib=cppgc_shared"); // Add other necessary libraries... // Platform-specific linker arguments From 1a380fcaa1ba72fa92bacf9452f9a66cdb0a5ac6 Mon Sep 17 00:00:00 2001 From: Nicolas Luck Date: Fri, 20 Sep 2024 16:33:36 +0200 Subject: [PATCH 05/43] use_custom_libcxx = true --- .gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gn b/.gn index e3f7e5a3c3..a2a938942a 100644 --- a/.gn +++ b/.gn @@ -22,7 +22,7 @@ default_args = { v8_use_external_startup_data = false v8_enable_symbol_visibility = true symbol_level = 2 - use_custom_libcxx = false + use_custom_libcxx = true # trying to get cppgc build v8_enable_oilpan=true is_debug = false From 24dce9f8db0cd4e18a03401890659366e58283f5 Mon Sep 17 00:00:00 2001 From: Nicolas Luck Date: Fri, 20 Sep 2024 16:34:11 +0200 Subject: [PATCH 06/43] Remove cppgc linking and set LIBCPP_ABI_VERSION to 1 --- build.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build.rs b/build.rs index a84e724651..40cf5328ce 100644 --- a/build.rs +++ b/build.rs @@ -630,9 +630,9 @@ fn print_link_flags() { println!("cargo:rustc-link-lib=dylib=third_party_icu_icui18n"); println!("cargo:rustc-link-lib=dylib=icuuc"); println!("cargo:rustc-link-lib=dylib=third_party_abseil-cpp_absl"); - println!("cargo:rustc-link-lib=dylib=cppgc"); - println!("cargo:rustc-link-lib=dylib=cppgc_base"); - println!("cargo:rustc-link-lib=dylib=cppgc_shared"); + + println!("cargo:rustc-cdylib-link-arg=-D_LIBCPP_ABI_VERSION=1"); + // Add other necessary libraries... // Platform-specific linker arguments From 7eb8ec1b434b863c16702e17d851ef79130b7872 Mon Sep 17 00:00:00 2001 From: Nicolas Luck Date: Mon, 23 Sep 2024 13:09:33 +0200 Subject: [PATCH 07/43] Fix setting of LIBCPP_ABI_VERSION --- build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.rs b/build.rs index 40cf5328ce..89928d9750 100644 --- a/build.rs +++ b/build.rs @@ -631,7 +631,7 @@ fn print_link_flags() { println!("cargo:rustc-link-lib=dylib=icuuc"); println!("cargo:rustc-link-lib=dylib=third_party_abseil-cpp_absl"); - println!("cargo:rustc-cdylib-link-arg=-D_LIBCPP_ABI_VERSION=1"); + println!("cargo:rustc-dylib-link-arg=-D_LIBCPP_ABI_VERSION=1"); // Add other necessary libraries... From c36471f10ff1f3643f9df865e95e0563d977af6f Mon Sep 17 00:00:00 2001 From: Nicolas Luck Date: Mon, 23 Sep 2024 15:04:43 +0200 Subject: [PATCH 08/43] Instead of downgrading LIBCPP_ABI, use system clang on macos --- build.rs | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/build.rs b/build.rs index 89928d9750..940fbb1505 100644 --- a/build.rs +++ b/build.rs @@ -168,7 +168,7 @@ fn build_v8(is_asan: bool) { gn_args.push("is_clang=false".into()); // -gline-tables-only is Clang-only gn_args.push("line_tables_only=false".into()); - } else if let Some(clang_base_path) = find_compatible_system_clang() { + } else if let Some(clang_base_path) = find_compatible_system_clang(target_os) { println!("clang_base_path (system): {}", clang_base_path.display()); gn_args.push(format!("clang_base_path={:?}", clang_base_path)); gn_args.push("treat_warnings_as_errors=false".to_string()); @@ -630,8 +630,6 @@ fn print_link_flags() { println!("cargo:rustc-link-lib=dylib=third_party_icu_icui18n"); println!("cargo:rustc-link-lib=dylib=icuuc"); println!("cargo:rustc-link-lib=dylib=third_party_abseil-cpp_absl"); - - println!("cargo:rustc-dylib-link-arg=-D_LIBCPP_ABI_VERSION=1"); // Add other necessary libraries... @@ -728,16 +726,37 @@ fn is_compatible_clang_version(clang_path: &Path) -> bool { false } -fn find_compatible_system_clang() -> Option { +fn find_compatible_system_clang(target_os: &str) -> Option { if let Ok(p) = env::var("CLANG_BASE_PATH") { let base_path = Path::new(&p); let clang_path = base_path.join("bin").join("clang"); if is_compatible_clang_version(&clang_path) { return Some(base_path.to_path_buf()); + } else { + None + } + } else if target_os == "macos" { + let clang_path = Path::new("/usr").join("bin").join("clang"); + if is_compatible_clang_version(&clang_path) { + // Add use_lld=false to GN_ARGS environment variable + if let Ok(mut gn_args) = env::var("GN_ARGS") { + if !gn_args.contains("use_lld=false") { + if !gn_args.is_empty() { + gn_args.push(' '); + } + gn_args.push_str("use_lld=false"); + env::set_var("GN_ARGS", gn_args); + } + } else { + env::set_var("GN_ARGS", "use_lld=false"); + } + return Some(Path::new("/usr").to_path_buf()); + } else { + None } + } else { + None } - - None } // Download chromium's clang into OUT_DIR because Cargo will not allow us to From 10f02b6828ae5098a4a53b9ca1fc5ba151d09b95 Mon Sep 17 00:00:00 2001 From: Nicolas Luck Date: Mon, 23 Sep 2024 15:06:33 +0200 Subject: [PATCH 09/43] Fix compilation of build.rs after last commit --- build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.rs b/build.rs index 940fbb1505..baace33554 100644 --- a/build.rs +++ b/build.rs @@ -168,7 +168,7 @@ fn build_v8(is_asan: bool) { gn_args.push("is_clang=false".into()); // -gline-tables-only is Clang-only gn_args.push("line_tables_only=false".into()); - } else if let Some(clang_base_path) = find_compatible_system_clang(target_os) { + } else if let Some(clang_base_path) = find_compatible_system_clang(&target_os) { println!("clang_base_path (system): {}", clang_base_path.display()); gn_args.push(format!("clang_base_path={:?}", clang_base_path)); gn_args.push("treat_warnings_as_errors=false".to_string()); From d1717ef00700a8c00163e88143a009bfb9e7bc0d Mon Sep 17 00:00:00 2001 From: Nicolas Luck Date: Mon, 30 Sep 2024 17:56:34 +0200 Subject: [PATCH 10/43] Detect and use system clang on Windows too --- build.rs | 46 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/build.rs b/build.rs index baace33554..0f63fcc95a 100644 --- a/build.rs +++ b/build.rs @@ -726,6 +726,21 @@ fn is_compatible_clang_version(clang_path: &Path) -> bool { false } +fn deactivate_lld() { + // Add use_lld=false to GN_ARGS environment variable + if let Ok(mut gn_args) = env::var("GN_ARGS") { + if !gn_args.contains("use_lld=false") { + if !gn_args.is_empty() { + gn_args.push(' '); + } + gn_args.push_str("use_lld=false"); + env::set_var("GN_ARGS", gn_args); + } + } else { + env::set_var("GN_ARGS", "use_lld=false"); + } +} + fn find_compatible_system_clang(target_os: &str) -> Option { if let Ok(p) = env::var("CLANG_BASE_PATH") { let base_path = Path::new(&p); @@ -738,22 +753,29 @@ fn find_compatible_system_clang(target_os: &str) -> Option { } else if target_os == "macos" { let clang_path = Path::new("/usr").join("bin").join("clang"); if is_compatible_clang_version(&clang_path) { - // Add use_lld=false to GN_ARGS environment variable - if let Ok(mut gn_args) = env::var("GN_ARGS") { - if !gn_args.contains("use_lld=false") { - if !gn_args.is_empty() { - gn_args.push(' '); - } - gn_args.push_str("use_lld=false"); - env::set_var("GN_ARGS", gn_args); - } - } else { - env::set_var("GN_ARGS", "use_lld=false"); - } + deactivate_lld(); return Some(Path::new("/usr").to_path_buf()); } else { None } + } else if target_os == "windows" { + let llvm_path = Path::new("C:") + .join("Program Files (x86)") + .join("Microsoft Visual Studio") + .join("2022") + .join("BuildTools") + .join("VC") + .join("Tools") + .join("Llvm"); + let clang_path = llvm_path.clone() + .join("bin") + .join("clang-cl"); + if is_compatible_clang_version(&clang_path) { + deactivate_lld(); + return Some(llvm_path); + } else { + None + } } else { None } From 81aa290104b8cebb5c41933aa7647fe23bbc2d64 Mon Sep 17 00:00:00 2001 From: jhweir Date: Mon, 30 Sep 2024 17:26:02 +0100 Subject: [PATCH 11/43] Detect and use system clang on Windows too --- build.rs | 46 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/build.rs b/build.rs index baace33554..0f63fcc95a 100644 --- a/build.rs +++ b/build.rs @@ -726,6 +726,21 @@ fn is_compatible_clang_version(clang_path: &Path) -> bool { false } +fn deactivate_lld() { + // Add use_lld=false to GN_ARGS environment variable + if let Ok(mut gn_args) = env::var("GN_ARGS") { + if !gn_args.contains("use_lld=false") { + if !gn_args.is_empty() { + gn_args.push(' '); + } + gn_args.push_str("use_lld=false"); + env::set_var("GN_ARGS", gn_args); + } + } else { + env::set_var("GN_ARGS", "use_lld=false"); + } +} + fn find_compatible_system_clang(target_os: &str) -> Option { if let Ok(p) = env::var("CLANG_BASE_PATH") { let base_path = Path::new(&p); @@ -738,22 +753,29 @@ fn find_compatible_system_clang(target_os: &str) -> Option { } else if target_os == "macos" { let clang_path = Path::new("/usr").join("bin").join("clang"); if is_compatible_clang_version(&clang_path) { - // Add use_lld=false to GN_ARGS environment variable - if let Ok(mut gn_args) = env::var("GN_ARGS") { - if !gn_args.contains("use_lld=false") { - if !gn_args.is_empty() { - gn_args.push(' '); - } - gn_args.push_str("use_lld=false"); - env::set_var("GN_ARGS", gn_args); - } - } else { - env::set_var("GN_ARGS", "use_lld=false"); - } + deactivate_lld(); return Some(Path::new("/usr").to_path_buf()); } else { None } + } else if target_os == "windows" { + let llvm_path = Path::new("C:") + .join("Program Files (x86)") + .join("Microsoft Visual Studio") + .join("2022") + .join("BuildTools") + .join("VC") + .join("Tools") + .join("Llvm"); + let clang_path = llvm_path.clone() + .join("bin") + .join("clang-cl"); + if is_compatible_clang_version(&clang_path) { + deactivate_lld(); + return Some(llvm_path); + } else { + None + } } else { None } From b99a608d64bfd433327295b7702db161b5774212 Mon Sep 17 00:00:00 2001 From: Nicolas Luck Date: Tue, 1 Oct 2024 16:09:20 +0200 Subject: [PATCH 12/43] Try fix handling of clang_path in build.rs to avoid problem with spaces in filenames (not working yet) --- build.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/build.rs b/build.rs index 0f63fcc95a..b2beecc63e 100644 --- a/build.rs +++ b/build.rs @@ -170,7 +170,8 @@ fn build_v8(is_asan: bool) { gn_args.push("line_tables_only=false".into()); } else if let Some(clang_base_path) = find_compatible_system_clang(&target_os) { println!("clang_base_path (system): {}", clang_base_path.display()); - gn_args.push(format!("clang_base_path={:?}", clang_base_path)); + let clang_base_path_str = format!("'{}'", clang_base_path.display()); + gn_args.push(format!("clang_base_path={}", clang_base_path_str)); gn_args.push("treat_warnings_as_errors=false".to_string()); } else { println!("using Chromium's clang"); @@ -715,7 +716,7 @@ fn need_gn_ninja_download() -> bool { // * unversioned (Linux) packages of clang (if recent enough) // but unfortunately it doesn't work with version-suffixed packages commonly // found in Linux packet managers -fn is_compatible_clang_version(clang_path: &Path) -> bool { +fn is_compatible_clang_version(clang_path: &str) -> bool { if let Ok(o) = Command::new(clang_path).arg("--version").output() { let _output = String::from_utf8(o.stdout).unwrap(); // TODO check version output to make sure it's supported. @@ -745,32 +746,36 @@ fn find_compatible_system_clang(target_os: &str) -> Option { if let Ok(p) = env::var("CLANG_BASE_PATH") { let base_path = Path::new(&p); let clang_path = base_path.join("bin").join("clang"); - if is_compatible_clang_version(&clang_path) { + if is_compatible_clang_version(&clang_path.display().to_string()) { return Some(base_path.to_path_buf()); } else { None } } else if target_os == "macos" { let clang_path = Path::new("/usr").join("bin").join("clang"); - if is_compatible_clang_version(&clang_path) { + if is_compatible_clang_version(&clang_path.display().to_string()) { deactivate_lld(); return Some(Path::new("/usr").to_path_buf()); } else { None } } else if target_os == "windows" { - let llvm_path = Path::new("C:") - .join("Program Files (x86)") + let llvm_path = Path::new("C:\\") + .join("\"Program Files (x86)\"") .join("Microsoft Visual Studio") .join("2022") .join("BuildTools") .join("VC") .join("Tools") .join("Llvm"); + let clang_path = llvm_path.clone() .join("bin") - .join("clang-cl"); - if is_compatible_clang_version(&clang_path) { + .join("clang-cl.exe"); + + let clang_path_str = format!("\"{}\"", clang_path.display()); + + if is_compatible_clang_version(&clang_path_str) { deactivate_lld(); return Some(llvm_path); } else { From ca086ff6ddd852db4159663fcaf7b6e96973b862 Mon Sep 17 00:00:00 2001 From: Fayeed Pawaskar Date: Mon, 14 Oct 2024 18:49:07 +0530 Subject: [PATCH 13/43] Refactor build.rs to improve dynamic library linking --- build.rs | 60 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/build.rs b/build.rs index b2beecc63e..49d8d7bb31 100644 --- a/build.rs +++ b/build.rs @@ -550,7 +550,7 @@ where let mut inflate_state = InflateState::default(); let mut input_buffer = [0; 16 * 1024]; let mut output_buffer = [0; 16 * 1024]; - let mut input_offset = 0; + let mut input_offset = 0; // Skip the gzip header gzip_header::read_gz_header(input).unwrap(); @@ -622,23 +622,27 @@ fn print_link_flags() { println!("cargo:rustc-link-lib=static=rusty_v8"); println!("cargo:rustc-link-search=native=./target/release/gn_out"); - // Link dynamic V8 libraries - - println!("cargo:rustc-link-lib=dylib=v8_libplatform"); - println!("cargo:rustc-link-lib=dylib=v8_libbase"); - println!("cargo:rustc-link-lib=dylib=v8"); - println!("cargo:rustc-link-lib=dylib=c++_chrome"); - println!("cargo:rustc-link-lib=dylib=third_party_icu_icui18n"); - println!("cargo:rustc-link-lib=dylib=icuuc"); - println!("cargo:rustc-link-lib=dylib=third_party_abseil-cpp_absl"); - - // Add other necessary libraries... - // Platform-specific linker arguments if cfg!(target_os = "macos") { + // Link dynamic V8 libraries + println!("cargo:rustc-link-lib=dylib=v8_libplatform"); + println!("cargo:rustc-link-lib=dylib=v8_libbase"); + println!("cargo:rustc-link-lib=dylib=v8"); + println!("cargo:rustc-link-lib=dylib=c++_chrome"); + println!("cargo:rustc-link-lib=dylib=third_party_icu_icui18n"); + println!("cargo:rustc-link-lib=dylib=icuuc"); + println!("cargo:rustc-link-lib=dylib=third_party_abseil-cpp_absl"); // macOS specific rpath println!("cargo:rustc-link-arg=-Wl,-rpath,@loader_path/../lib"); } else if cfg!(target_os = "linux") { + // Link dynamic V8 libraries + println!("cargo:rustc-link-lib=so=libv8_libplatform"); + println!("cargo:rustc-link-lib=so=libv8_libbase"); + println!("cargo:rustc-link-lib=so=libv8"); + println!("cargo:rustc-link-lib=so=libc++"); + println!("cargo:rustc-link-lib=so=libthird_party_icu_icui18n"); + println!("cargo:rustc-link-lib=so=libicuuc"); + println!("cargo:rustc-link-lib=so=libthird_party_abseil-cpp_absl"); // Linux specific rpath println!("cargo:rustc-link-arg=-Wl,-rpath,$ORIGIN/../lib"); } else if cfg!(target_os = "windows") { @@ -694,6 +698,7 @@ fn print_link_flags() { } } + // Chromium depot_tools contains helpers // which delegate to the "relevant" `buildtools` // directory when invoked, so they don't count. @@ -724,7 +729,7 @@ fn is_compatible_clang_version(clang_path: &str) -> bool { const _MIN_LLVM_CLANG_VER: f32 = 8.0; return true; } - false + true } fn deactivate_lld() { @@ -761,13 +766,13 @@ fn find_compatible_system_clang(target_os: &str) -> Option { } } else if target_os == "windows" { let llvm_path = Path::new("C:\\") - .join("\"Program Files (x86)\"") - .join("Microsoft Visual Studio") - .join("2022") - .join("BuildTools") - .join("VC") - .join("Tools") - .join("Llvm"); + .join("Program Files") + .join("Microsoft Visual Studio") + .join("2022") + .join("Community") + .join("VC") + .join("Tools") + .join("Llvm"); let clang_path = llvm_path.clone() .join("bin") @@ -777,7 +782,7 @@ fn find_compatible_system_clang(target_os: &str) -> Option { if is_compatible_clang_version(&clang_path_str) { deactivate_lld(); - return Some(llvm_path); + return Some(clang_path); } else { None } @@ -895,7 +900,9 @@ pub fn is_debug() -> bool { } fn gn() -> String { - env::var("GN").unwrap_or_else(|_| "gn".to_owned()) + let gn = env::var("GN").unwrap_or_else(|_| "gn".to_owned()); + println!("Using gn: {}", gn.clone()); + gn } /* @@ -903,13 +910,16 @@ fn gn() -> String { * variable or defaulting to `python3`. */ fn python() -> String { - env::var("PYTHON").unwrap_or_else(|_| "python3".to_owned()) + let python = env::var("PYTHON").unwrap_or_else(|_| "python3".to_owned()); + println!("Using python: {}", python); + env::var("PYTHON").unwrap_or_else(|_| "python".to_owned()) } type NinjaEnv = Vec<(String, String)>; fn ninja(gn_out_dir: &Path, maybe_env: Option) -> Command { - let cmd_string = env::var("NINJA").unwrap_or_else(|_| "ninja".to_owned()); + let cmd_string = env::var("NINJA").unwrap_or_else(|_| "C:\\Strawberry\\c\\bin\\ninja.exe".to_owned()); + println!("Using ninja: {}", cmd_string); let mut cmd = Command::new(cmd_string); cmd.arg("-C"); cmd.arg(gn_out_dir); From a9be97c35913e58b87e52a2595f12be437500b69 Mon Sep 17 00:00:00 2001 From: Fayeed Pawaskar Date: Thu, 17 Oct 2024 09:38:34 +0530 Subject: [PATCH 14/43] Refactor build.rs to improve dynamic library linking --- build.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/build.rs b/build.rs index 49d8d7bb31..c120b58edd 100644 --- a/build.rs +++ b/build.rs @@ -633,18 +633,18 @@ fn print_link_flags() { println!("cargo:rustc-link-lib=dylib=icuuc"); println!("cargo:rustc-link-lib=dylib=third_party_abseil-cpp_absl"); // macOS specific rpath - println!("cargo:rustc-link-arg=-Wl,-rpath,@loader_path/../lib"); + // println!("cargo:rustc-link-arg=-Wl,-rpath,@loader_path/../lib"); } else if cfg!(target_os = "linux") { // Link dynamic V8 libraries - println!("cargo:rustc-link-lib=so=libv8_libplatform"); - println!("cargo:rustc-link-lib=so=libv8_libbase"); - println!("cargo:rustc-link-lib=so=libv8"); - println!("cargo:rustc-link-lib=so=libc++"); - println!("cargo:rustc-link-lib=so=libthird_party_icu_icui18n"); - println!("cargo:rustc-link-lib=so=libicuuc"); - println!("cargo:rustc-link-lib=so=libthird_party_abseil-cpp_absl"); - // Linux specific rpath - println!("cargo:rustc-link-arg=-Wl,-rpath,$ORIGIN/../lib"); + println!("cargo:rustc-link-lib=v8_libplatform"); + println!("cargo:rustc-link-lib=v8_libbase"); + println!("cargo:rustc-link-lib=v8"); + println!("cargo:rustc-link-lib=c++"); + println!("cargo:rustc-link-lib=third_party_icu_icui18n"); + println!("cargo:rustc-link-lib=icuuc"); + println!("cargo:rustc-link-lib=third_party_abseil-cpp_absl"); + + // println!("cargo:rustc-link-arg=-Wl,-rpath,$ORIGIN/../lib"); } else if cfg!(target_os = "windows") { // Windows uses a different mechanism; rpath is not used // You might need to copy the DLLs next to the executable From 55ad4469f10b20cf8988b1103232778dcd74b073 Mon Sep 17 00:00:00 2001 From: Fayeed Pawaskar Date: Thu, 17 Oct 2024 19:43:07 +0530 Subject: [PATCH 15/43] Refactor build.rs to improve dynamic library linking --- build.rs | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/build.rs b/build.rs index c120b58edd..32ad572eb9 100644 --- a/build.rs +++ b/build.rs @@ -622,29 +622,18 @@ fn print_link_flags() { println!("cargo:rustc-link-lib=static=rusty_v8"); println!("cargo:rustc-link-search=native=./target/release/gn_out"); + println!("cargo:rustc-link-lib=dylib=v8_libplatform"); + println!("cargo:rustc-link-lib=dylib=v8_libbase"); + println!("cargo:rustc-link-lib=dylib=v8"); + println!("cargo:rustc-link-lib=dylib=third_party_icu_icui18n"); + println!("cargo:rustc-link-lib=dylib=icuuc"); + println!("cargo:rustc-link-lib=dylib=third_party_abseil-cpp_absl"); + // Platform-specific linker arguments if cfg!(target_os = "macos") { - // Link dynamic V8 libraries - println!("cargo:rustc-link-lib=dylib=v8_libplatform"); - println!("cargo:rustc-link-lib=dylib=v8_libbase"); - println!("cargo:rustc-link-lib=dylib=v8"); println!("cargo:rustc-link-lib=dylib=c++_chrome"); - println!("cargo:rustc-link-lib=dylib=third_party_icu_icui18n"); - println!("cargo:rustc-link-lib=dylib=icuuc"); - println!("cargo:rustc-link-lib=dylib=third_party_abseil-cpp_absl"); - // macOS specific rpath - // println!("cargo:rustc-link-arg=-Wl,-rpath,@loader_path/../lib"); } else if cfg!(target_os = "linux") { - // Link dynamic V8 libraries - println!("cargo:rustc-link-lib=v8_libplatform"); - println!("cargo:rustc-link-lib=v8_libbase"); - println!("cargo:rustc-link-lib=v8"); - println!("cargo:rustc-link-lib=c++"); - println!("cargo:rustc-link-lib=third_party_icu_icui18n"); - println!("cargo:rustc-link-lib=icuuc"); - println!("cargo:rustc-link-lib=third_party_abseil-cpp_absl"); - - // println!("cargo:rustc-link-arg=-Wl,-rpath,$ORIGIN/../lib"); + println!("cargo:rustc-link-lib=dylib=c++"); } else if cfg!(target_os = "windows") { // Windows uses a different mechanism; rpath is not used // You might need to copy the DLLs next to the executable From b6b08398eb85e12910952b044f67b5de552906bd Mon Sep 17 00:00:00 2001 From: Fayeed Pawaskar Date: Fri, 18 Oct 2024 15:09:41 +0530 Subject: [PATCH 16/43] Refactor build.rs to improve dynamic library linking and fix handling of clang_path to avoid problem with spaces in filenames --- .gn | 1 - build.rs | 6 ++++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.gn b/.gn index a2a938942a..9dea6310ba 100644 --- a/.gn +++ b/.gn @@ -22,7 +22,6 @@ default_args = { v8_use_external_startup_data = false v8_enable_symbol_visibility = true symbol_level = 2 - use_custom_libcxx = true # trying to get cppgc build v8_enable_oilpan=true is_debug = false diff --git a/build.rs b/build.rs index 32ad572eb9..e778ec4442 100644 --- a/build.rs +++ b/build.rs @@ -159,6 +159,12 @@ fn build_v8(is_asan: bool) { gn_args.push("use_custom_libcxx=false".to_string()); } + if cfg!(target_os = "macos") { + gn_args.push("use_custom_libcxx=true".to_string()); + } else { + gn_args.push("use_custom_libcxx=false".to_string()); + } + // Fix GN's host_cpu detection when using x86_64 bins on Apple Silicon if cfg!(target_os = "macos") && cfg!(target_arch = "aarch64") { gn_args.push("host_cpu=\"arm64\"".to_string()) From 9fed747cf7dd741c66a916f8c8cd8dd445ba2f84 Mon Sep 17 00:00:00 2001 From: Nicolas Luck Date: Mon, 28 Oct 2024 15:15:26 +0100 Subject: [PATCH 17/43] Fix macOS build (' => ") and write build artifacts to gn_out/TARGET_ARCH --- build.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/build.rs b/build.rs index e778ec4442..53664ea71d 100644 --- a/build.rs +++ b/build.rs @@ -176,7 +176,7 @@ fn build_v8(is_asan: bool) { gn_args.push("line_tables_only=false".into()); } else if let Some(clang_base_path) = find_compatible_system_clang(&target_os) { println!("clang_base_path (system): {}", clang_base_path.display()); - let clang_base_path_str = format!("'{}'", clang_base_path.display()); + let clang_base_path_str = format!("\"{}\"", clang_base_path.display()); gn_args.push(format!("clang_base_path={}", clang_base_path_str)); gn_args.push("treat_warnings_as_errors=false".to_string()); } else { @@ -907,7 +907,8 @@ fn gn() -> String { fn python() -> String { let python = env::var("PYTHON").unwrap_or_else(|_| "python3".to_owned()); println!("Using python: {}", python); - env::var("PYTHON").unwrap_or_else(|_| "python".to_owned()) + //env::var("PYTHON").unwrap_or_else(|_| "python".to_owned()) + python } type NinjaEnv = Vec<(String, String)>; @@ -934,7 +935,8 @@ pub type GnArgs = Vec; pub fn maybe_gen(manifest_dir: &str, gn_args: GnArgs) -> PathBuf { let dirs = get_dirs(Some(manifest_dir)); - let gn_out_dir = dirs.out.join("gn_out"); + let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap(); + let gn_out_dir = dirs.out.join("gn_out").join(target_arch); if !gn_out_dir.exists() || !gn_out_dir.join("build.ninja").exists() { let args = if let Ok(extra_args) = env::var("EXTRA_GN_ARGS") { @@ -967,7 +969,11 @@ pub fn maybe_gen(manifest_dir: &str, gn_args: GnArgs) -> PathBuf { } pub fn build(target: &str, maybe_env: Option) { - let gn_out_dir = get_dirs(None).out.join("gn_out"); + let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap(); + let gn_out_dir = get_dirs(None).out.join("gn_out").join(target_arch); + if !gn_out_dir.exists() { + fs::create_dir_all(&gn_out_dir).expect("Failed to create gn_out_dir"); + } rerun_if_changed(&gn_out_dir, maybe_env.clone(), target); From 3d3fe7438fc1420b2ac67e46018db0ab81815ca7 Mon Sep 17 00:00:00 2001 From: Nicolas Luck Date: Mon, 28 Oct 2024 15:17:33 +0100 Subject: [PATCH 18/43] Don't always turn debug symbols off, so debug builds of consuming crates still work --- .gn | 1 - 1 file changed, 1 deletion(-) diff --git a/.gn b/.gn index 9dea6310ba..759313ad37 100644 --- a/.gn +++ b/.gn @@ -24,7 +24,6 @@ default_args = { symbol_level = 2 # trying to get cppgc build v8_enable_oilpan=true - is_debug = false linux_use_bundled_binutils = false From 33ade85da1987685bf416861adfb28328a2dbb8b Mon Sep 17 00:00:00 2001 From: Nicolas Luck Date: Mon, 28 Oct 2024 16:55:47 +0100 Subject: [PATCH 19/43] Change linker search path to include architecture directory --- build.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/build.rs b/build.rs index 53664ea71d..37ba7cbc50 100644 --- a/build.rs +++ b/build.rs @@ -625,8 +625,10 @@ fn copy_archive(url: &str, filename: &Path) { } fn print_link_flags() { + let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap(); + println!("cargo:rustc-link-lib=static=rusty_v8"); - println!("cargo:rustc-link-search=native=./target/release/gn_out"); + println!("cargo:rustc-link-search=native=./target/release/gn_out/{}", target_arch); println!("cargo:rustc-link-lib=dylib=v8_libplatform"); println!("cargo:rustc-link-lib=dylib=v8_libbase"); From 28280bf899f263ae673b08e0db8b998db2e15c43 Mon Sep 17 00:00:00 2001 From: Nicolas Luck Date: Mon, 28 Oct 2024 17:00:55 +0100 Subject: [PATCH 20/43] don't treat warnings as errors --- .gn | 1 + 1 file changed, 1 insertion(+) diff --git a/.gn b/.gn index 759313ad37..4d2dca28c5 100644 --- a/.gn +++ b/.gn @@ -24,6 +24,7 @@ default_args = { symbol_level = 2 # trying to get cppgc build v8_enable_oilpan=true + treat_warnings_as_errors = false linux_use_bundled_binutils = false From 066d2719f54d8fa007f8b2a2a15113a36d74e294 Mon Sep 17 00:00:00 2001 From: Nicolas Luck Date: Tue, 29 Oct 2024 13:28:43 +0100 Subject: [PATCH 21/43] Revert "Refactor build.rs to improve dynamic library linking and fix handling of clang_path to avoid problem with spaces in filenames" This reverts commit b6b08398eb85e12910952b044f67b5de552906bd. --- .gn | 1 + build.rs | 6 ------ 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/.gn b/.gn index 4d2dca28c5..c2d59ae3fb 100644 --- a/.gn +++ b/.gn @@ -22,6 +22,7 @@ default_args = { v8_use_external_startup_data = false v8_enable_symbol_visibility = true symbol_level = 2 + use_custom_libcxx = true # trying to get cppgc build v8_enable_oilpan=true treat_warnings_as_errors = false diff --git a/build.rs b/build.rs index 37ba7cbc50..4ce602270a 100644 --- a/build.rs +++ b/build.rs @@ -159,12 +159,6 @@ fn build_v8(is_asan: bool) { gn_args.push("use_custom_libcxx=false".to_string()); } - if cfg!(target_os = "macos") { - gn_args.push("use_custom_libcxx=true".to_string()); - } else { - gn_args.push("use_custom_libcxx=false".to_string()); - } - // Fix GN's host_cpu detection when using x86_64 bins on Apple Silicon if cfg!(target_os = "macos") && cfg!(target_arch = "aarch64") { gn_args.push("host_cpu=\"arm64\"".to_string()) From 20befe0bc1044b153d44113cc77186ad6578a637 Mon Sep 17 00:00:00 2001 From: Nicolas Luck Date: Thu, 31 Oct 2024 14:04:57 +0100 Subject: [PATCH 22/43] On Linux, go back to static lib but with special abseil::v8 namespace --- .gn | 2 +- build.rs | 64 ++++++++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 54 insertions(+), 12 deletions(-) diff --git a/.gn b/.gn index c2d59ae3fb..97018fe8dd 100644 --- a/.gn +++ b/.gn @@ -18,9 +18,9 @@ secondary_source = "//v8/" default_args = { clang_use_chrome_plugins = false - is_component_build = true v8_use_external_startup_data = false v8_enable_symbol_visibility = true + default_symbol_visibility = "hidden" symbol_level = 2 use_custom_libcxx = true # trying to get cppgc build diff --git a/build.rs b/build.rs index 4ce602270a..64c0d85d0b 100644 --- a/build.rs +++ b/build.rs @@ -164,6 +164,21 @@ fn build_v8(is_asan: bool) { gn_args.push("host_cpu=\"arm64\"".to_string()) } + if cfg!(target_os = "linux") { let repo_root = env::current_dir().unwrap(); + let abseil_options_path = repo_root + .join("third_party") + .join("abseil-cpp") + .join("absl") + .join("base") + .join("options.h"); + + modify_abseil_options(&abseil_options_path).expect("Failed to modify options.h"); + gn_args.push(r#"extra_cflags = [ "-fvisibility=hidden", "-fvisibility-inlines-hidden" ]"#.to_string()); + gn_args.push(r#"extra_ldflags = [ "-Wl,-Bsymbolic" ]"#.to_string()); + } else { + gn_args.push(r#"is_component_build = true"#.to_string()); + } + if env::var_os("DISABLE_CLANG").is_some() { gn_args.push("is_clang=false".into()); // -gline-tables-only is Clang-only @@ -619,23 +634,23 @@ fn copy_archive(url: &str, filename: &Path) { } fn print_link_flags() { - let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap(); + println!("cargo:rustc-link-lib=static=rusty_v8"); - println!("cargo:rustc-link-search=native=./target/release/gn_out/{}", target_arch); - - println!("cargo:rustc-link-lib=dylib=v8_libplatform"); - println!("cargo:rustc-link-lib=dylib=v8_libbase"); - println!("cargo:rustc-link-lib=dylib=v8"); - println!("cargo:rustc-link-lib=dylib=third_party_icu_icui18n"); - println!("cargo:rustc-link-lib=dylib=icuuc"); - println!("cargo:rustc-link-lib=dylib=third_party_abseil-cpp_absl"); // Platform-specific linker arguments if cfg!(target_os = "macos") { - println!("cargo:rustc-link-lib=dylib=c++_chrome"); + let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap(); + println!("cargo:rustc-link-search=native=./target/release/gn_out/{}", target_arch); + println!("cargo:rustc-link-lib=dylib=v8_libplatform"); + println!("cargo:rustc-link-lib=dylib=v8_libbase"); + println!("cargo:rustc-link-lib=dylib=v8"); + println!("cargo:rustc-link-lib=dylib=third_party_icu_icui18n"); + println!("cargo:rustc-link-lib=dylib=icuuc"); + println!("cargo:rustc-link-lib=dylib=third_party_abseil-cpp_absl"); + println!("cargo:rustc-link-lib=dylib=c++_chrome"); } else if cfg!(target_os = "linux") { - println!("cargo:rustc-link-lib=dylib=c++"); + //println!("cargo:rustc-link-lib=dylib=c++"); } else if cfg!(target_os = "windows") { // Windows uses a different mechanism; rpath is not used // You might need to copy the DLLs next to the executable @@ -1057,6 +1072,33 @@ pub fn parse_ninja_graph(s: &str) -> HashSet { out } +fn modify_abseil_options(options_path: &PathBuf) -> io::Result<()> { + // Read the contents of options.h + let mut options_content = fs::read_to_string(&options_path)?; + + // Modify the necessary lines + // Replace the definitions of ABSL_OPTION_USE_INLINE_NAMESPACE and ABSL_OPTION_INLINE_NAMESPACE_NAME + options_content = options_content + .lines() + .map(|line| { + if line.contains("#define ABSL_OPTION_USE_INLINE_NAMESPACE") { + "#define ABSL_OPTION_USE_INLINE_NAMESPACE 1".to_string() + } else if line.contains("#define ABSL_OPTION_INLINE_NAMESPACE_NAME") { + "#define ABSL_OPTION_INLINE_NAMESPACE_NAME v8".to_string() + } else { + line.to_string() + } + }) + .collect::>() + .join("\n"); + + // Write the modified content back to options.h + let mut file = fs::File::create(&options_path)?; + file.write_all(options_content.as_bytes())?; + + Ok(()) +} + #[cfg(test)] mod test { use super::*; From 00e051dcbf3dafb13226c2f90ba60066779d81cb Mon Sep 17 00:00:00 2001 From: Nicolas Luck Date: Mon, 4 Nov 2024 14:27:23 +0100 Subject: [PATCH 23/43] Modify abseil namespace and build static for linux and windows --- build.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/build.rs b/build.rs index 64c0d85d0b..98359d8965 100644 --- a/build.rs +++ b/build.rs @@ -164,21 +164,27 @@ fn build_v8(is_asan: bool) { gn_args.push("host_cpu=\"arm64\"".to_string()) } - if cfg!(target_os = "linux") { let repo_root = env::current_dir().unwrap(); + if cfg!(target_os = "macos") { + gn_args.push(r#"is_component_build = true"#.to_string()); + } else { + let repo_root = env::current_dir().unwrap(); let abseil_options_path = repo_root .join("third_party") .join("abseil-cpp") .join("absl") .join("base") .join("options.h"); - + modify_abseil_options(&abseil_options_path).expect("Failed to modify options.h"); - gn_args.push(r#"extra_cflags = [ "-fvisibility=hidden", "-fvisibility-inlines-hidden" ]"#.to_string()); - gn_args.push(r#"extra_ldflags = [ "-Wl,-Bsymbolic" ]"#.to_string()); - } else { - gn_args.push(r#"is_component_build = true"#.to_string()); + + if cfg!(target_os = "linux") { + gn_args.push(r#"extra_cflags = [ "-fvisibility=hidden", "-fvisibility-inlines-hidden" ]"#.to_string()); + gn_args.push(r#"extra_ldflags = [ "-Wl,-Bsymbolic" ]"#.to_string()); + } } + + if env::var_os("DISABLE_CLANG").is_some() { gn_args.push("is_clang=false".into()); // -gline-tables-only is Clang-only From e929104e3dffef93c0dae14a2312d70749dde434 Mon Sep 17 00:00:00 2001 From: Nicolas Luck Date: Mon, 4 Nov 2024 15:30:16 +0100 Subject: [PATCH 24/43] Fix Windows clang path --- build.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/build.rs b/build.rs index 98359d8965..d5e377e443 100644 --- a/build.rs +++ b/build.rs @@ -777,15 +777,16 @@ fn find_compatible_system_clang(target_os: &str) -> Option { None } } else if target_os == "windows" { - let llvm_path = Path::new("C:\\") - .join("Program Files") + let _llvm_path = Path::new("C:\\") + .join("Program Files (x86)") .join("Microsoft Visual Studio") .join("2022") - .join("Community") + .join("BuildTools") .join("VC") .join("Tools") .join("Llvm"); + let llvm_path = Path::new("C:\\").join("LLVM"); let clang_path = llvm_path.clone() .join("bin") .join("clang-cl.exe"); @@ -794,7 +795,7 @@ fn find_compatible_system_clang(target_os: &str) -> Option { if is_compatible_clang_version(&clang_path_str) { deactivate_lld(); - return Some(clang_path); + return Some(llvm_path); } else { None } From 1dfa63b2593bd4ee767b432d28092017f20f1f72 Mon Sep 17 00:00:00 2001 From: Nicolas Luck Date: Wed, 6 Nov 2024 19:54:35 +0100 Subject: [PATCH 25/43] Don't have symbol_visibility = "hidden" on macOS where we still build dylibs --- .gn | 1 - build.rs | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/.gn b/.gn index 97018fe8dd..81edfd71ac 100644 --- a/.gn +++ b/.gn @@ -20,7 +20,6 @@ default_args = { clang_use_chrome_plugins = false v8_use_external_startup_data = false v8_enable_symbol_visibility = true - default_symbol_visibility = "hidden" symbol_level = 2 use_custom_libcxx = true # trying to get cppgc build diff --git a/build.rs b/build.rs index d5e377e443..caa53e3349 100644 --- a/build.rs +++ b/build.rs @@ -167,6 +167,7 @@ fn build_v8(is_asan: bool) { if cfg!(target_os = "macos") { gn_args.push(r#"is_component_build = true"#.to_string()); } else { + gn_args.push(r#"default_symbol_visibility = "hidden""#.to_string()); let repo_root = env::current_dir().unwrap(); let abseil_options_path = repo_root .join("third_party") From ae67c90c28b0cbfac0fe79477b5c34613f7adfb2 Mon Sep 17 00:00:00 2001 From: Nicolas Luck Date: Wed, 6 Nov 2024 20:45:21 +0100 Subject: [PATCH 26/43] Switch macOS back to static build with abseil namespace too --- build.rs | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/build.rs b/build.rs index caa53e3349..fc1ad56d76 100644 --- a/build.rs +++ b/build.rs @@ -164,27 +164,26 @@ fn build_v8(is_asan: bool) { gn_args.push("host_cpu=\"arm64\"".to_string()) } - if cfg!(target_os = "macos") { - gn_args.push(r#"is_component_build = true"#.to_string()); - } else { - gn_args.push(r#"default_symbol_visibility = "hidden""#.to_string()); - let repo_root = env::current_dir().unwrap(); - let abseil_options_path = repo_root - .join("third_party") - .join("abseil-cpp") - .join("absl") - .join("base") - .join("options.h"); - - modify_abseil_options(&abseil_options_path).expect("Failed to modify options.h"); - - if cfg!(target_os = "linux") { - gn_args.push(r#"extra_cflags = [ "-fvisibility=hidden", "-fvisibility-inlines-hidden" ]"#.to_string()); - gn_args.push(r#"extra_ldflags = [ "-Wl,-Bsymbolic" ]"#.to_string()); - } + gn_args.push(r#"default_symbol_visibility = "hidden""#.to_string()); + let repo_root = env::current_dir().unwrap(); + let abseil_options_path = repo_root + .join("third_party") + .join("abseil-cpp") + .join("absl") + .join("base") + .join("options.h"); + + modify_abseil_options(&abseil_options_path).expect("Failed to modify options.h"); + + if cfg!(target_os = "linux") { + gn_args.push(r#"extra_cflags = [ "-fvisibility=hidden", "-fvisibility-inlines-hidden" ]"#.to_string()); + gn_args.push(r#"extra_ldflags = [ "-Wl,-Bsymbolic" ]"#.to_string()); } - + if cfg!(target_os = "macos") { + gn_args.push(r#"extra_cflags = [ "-fvisibility=hidden", "-fvisibility-inlines-hidden" ]"#.to_string()); + gn_args.push(r#"extra_ldflags = [ "-Wl,-x" ]"#.to_string()); + } if env::var_os("DISABLE_CLANG").is_some() { gn_args.push("is_clang=false".into()); @@ -641,10 +640,9 @@ fn copy_archive(url: &str, filename: &Path) { } fn print_link_flags() { - - println!("cargo:rustc-link-lib=static=rusty_v8"); + /* // Platform-specific linker arguments if cfg!(target_os = "macos") { let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap(); @@ -662,6 +660,7 @@ fn print_link_flags() { // Windows uses a different mechanism; rpath is not used // You might need to copy the DLLs next to the executable } + */ let should_dyn_link_libcxx = env::var("CARGO_FEATURE_USE_CUSTOM_LIBCXX") .is_err() || env::var("GN_ARGS").map_or(false, |gn_args| { From ff3f64eb1b7f9b30cf0b92137bb1aa51c190429b Mon Sep 17 00:00:00 2001 From: Nicolas Luck Date: Thu, 7 Nov 2024 12:14:22 +0100 Subject: [PATCH 27/43] Rebuild if target arch has changed --- build.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/build.rs b/build.rs index fc1ad56d76..015e43ad6e 100644 --- a/build.rs +++ b/build.rs @@ -993,6 +993,7 @@ pub fn build(target: &str, maybe_env: Option) { fs::create_dir_all(&gn_out_dir).expect("Failed to create gn_out_dir"); } + println!("cargo:rerun-if-env-changed=CARGO_CFG_TARGET_ARCH"); rerun_if_changed(&gn_out_dir, maybe_env.clone(), target); // This helps Rust source files locate the snapshot, source map etc. From 60b32bee9691bfb07e04b345620c8c2f05336f94 Mon Sep 17 00:00:00 2001 From: Nicolas Luck Date: Thu, 7 Nov 2024 15:27:34 +0100 Subject: [PATCH 28/43] Explicitly pass arch through to clang on macOS --- build.rs | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/build.rs b/build.rs index 015e43ad6e..a6f9b9cbb8 100644 --- a/build.rs +++ b/build.rs @@ -160,8 +160,32 @@ fn build_v8(is_asan: bool) { } // Fix GN's host_cpu detection when using x86_64 bins on Apple Silicon - if cfg!(target_os = "macos") && cfg!(target_arch = "aarch64") { - gn_args.push("host_cpu=\"arm64\"".to_string()) + if cfg!(target_os = "macos") { + let host_arch = std::env::var("HOST_ARCH").unwrap_or_else(|_| { + // Detect the host architecture + match std::env::consts::ARCH { + "x86_64" => "x64".to_string(), + "aarch64" => "arm64".to_string(), + other => other.to_string(), + } + }); + + let target_cpu = match target_arch.as_str() { + "x86_64" => "x64", + "aarch64" => "arm64", + _ => panic!("Unsupported architecture"), + }; + + gn_args.push(format!("target_cpu=\"{}\"", target_cpu)); + gn_args.push(format!("host_cpu=\"{}\"", host_arch)); + + if target_arch == "x86_64" { + gn_args.push(r#"extra_cflags = [ "-arch", "x86_64" ]"#.to_string()); + gn_args.push(r#"extra_ldflags = [ "-arch", "x86_64" ]"#.to_string()); + } else if target_arch == "aarch64" { + gn_args.push(r#"extra_cflags = [ "-arch", "arm64" ]"#.to_string()); + gn_args.push(r#"extra_ldflags = [ "-arch", "arm64" ]"#.to_string()); + } } gn_args.push(r#"default_symbol_visibility = "hidden""#.to_string()); From e3849ca37abdc3e81c5d7a8fc7bb97330b5d25c3 Mon Sep 17 00:00:00 2001 From: Nicolas Luck Date: Thu, 7 Nov 2024 15:27:55 +0100 Subject: [PATCH 29/43] Rebuild if PROFILE (debug/release) changed --- build.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/build.rs b/build.rs index a6f9b9cbb8..61a17e5699 100644 --- a/build.rs +++ b/build.rs @@ -1018,6 +1018,7 @@ pub fn build(target: &str, maybe_env: Option) { } println!("cargo:rerun-if-env-changed=CARGO_CFG_TARGET_ARCH"); + println!("cargo:rerun-if-env-changed=PROFILE"); rerun_if_changed(&gn_out_dir, maybe_env.clone(), target); // This helps Rust source files locate the snapshot, source map etc. From 203fe5d42f6002006a6da62b97bc2cc32ba500e1 Mon Sep 17 00:00:00 2001 From: Nicolas Luck Date: Thu, 7 Nov 2024 17:16:25 +0100 Subject: [PATCH 30/43] Fix reassignment of extra_cflags --- build.rs | 50 ++++++++++++++++++++++++-------------------------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/build.rs b/build.rs index 61a17e5699..ad657779e2 100644 --- a/build.rs +++ b/build.rs @@ -159,8 +159,27 @@ fn build_v8(is_asan: bool) { gn_args.push("use_custom_libcxx=false".to_string()); } - // Fix GN's host_cpu detection when using x86_64 bins on Apple Silicon + gn_args.push(r#"default_symbol_visibility = "hidden""#.to_string()); + let repo_root = env::current_dir().unwrap(); + let abseil_options_path = repo_root + .join("third_party") + .join("abseil-cpp") + .join("absl") + .join("base") + .join("options.h"); + + modify_abseil_options(&abseil_options_path).expect("Failed to modify options.h"); + + if cfg!(target_os = "linux") { + gn_args.push(r#"extra_cflags = [ "-fvisibility=hidden", "-fvisibility-inlines-hidden" ]"#.to_string()); + gn_args.push(r#"extra_ldflags = [ "-Wl,-Bsymbolic" ]"#.to_string()); + } + if cfg!(target_os = "macos") { + gn_args.push(r#"extra_cflags = [ "-fvisibility=hidden", "-fvisibility-inlines-hidden" ]"#.to_string()); + gn_args.push(r#"extra_ldflags = [ "-Wl,-x" ]"#.to_string()); + + // Fix GN's host_cpu detection when using x86_64 bins on Apple Silicon let host_arch = std::env::var("HOST_ARCH").unwrap_or_else(|_| { // Detect the host architecture match std::env::consts::ARCH { @@ -180,35 +199,14 @@ fn build_v8(is_asan: bool) { gn_args.push(format!("host_cpu=\"{}\"", host_arch)); if target_arch == "x86_64" { - gn_args.push(r#"extra_cflags = [ "-arch", "x86_64" ]"#.to_string()); - gn_args.push(r#"extra_ldflags = [ "-arch", "x86_64" ]"#.to_string()); + gn_args.push(r#"extra_cflags += [ "-arch", "x86_64" ]"#.to_string()); + gn_args.push(r#"extra_ldflags += [ "-arch", "x86_64" ]"#.to_string()); } else if target_arch == "aarch64" { - gn_args.push(r#"extra_cflags = [ "-arch", "arm64" ]"#.to_string()); - gn_args.push(r#"extra_ldflags = [ "-arch", "arm64" ]"#.to_string()); + gn_args.push(r#"extra_cflags += [ "-arch", "arm64" ]"#.to_string()); + gn_args.push(r#"extra_ldflags += [ "-arch", "arm64" ]"#.to_string()); } } - gn_args.push(r#"default_symbol_visibility = "hidden""#.to_string()); - let repo_root = env::current_dir().unwrap(); - let abseil_options_path = repo_root - .join("third_party") - .join("abseil-cpp") - .join("absl") - .join("base") - .join("options.h"); - - modify_abseil_options(&abseil_options_path).expect("Failed to modify options.h"); - - if cfg!(target_os = "linux") { - gn_args.push(r#"extra_cflags = [ "-fvisibility=hidden", "-fvisibility-inlines-hidden" ]"#.to_string()); - gn_args.push(r#"extra_ldflags = [ "-Wl,-Bsymbolic" ]"#.to_string()); - } - - if cfg!(target_os = "macos") { - gn_args.push(r#"extra_cflags = [ "-fvisibility=hidden", "-fvisibility-inlines-hidden" ]"#.to_string()); - gn_args.push(r#"extra_ldflags = [ "-Wl,-x" ]"#.to_string()); - } - if env::var_os("DISABLE_CLANG").is_some() { gn_args.push("is_clang=false".into()); // -gline-tables-only is Clang-only From 30a2496d83f459b4d85c13c9d90e028527754ced Mon Sep 17 00:00:00 2001 From: Nicolas Luck Date: Mon, 11 Nov 2024 15:25:06 +0100 Subject: [PATCH 31/43] Don't rerun build if PROFILE changes (seems to trigger rebuild every time) --- build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.rs b/build.rs index ad657779e2..8a565fa698 100644 --- a/build.rs +++ b/build.rs @@ -1016,7 +1016,7 @@ pub fn build(target: &str, maybe_env: Option) { } println!("cargo:rerun-if-env-changed=CARGO_CFG_TARGET_ARCH"); - println!("cargo:rerun-if-env-changed=PROFILE"); + //println!("cargo:rerun-if-env-changed=PROFILE"); rerun_if_changed(&gn_out_dir, maybe_env.clone(), target); // This helps Rust source files locate the snapshot, source map etc. From 1f2f017eea9473ebbb83d8f2e1ce1e0cad330df8 Mon Sep 17 00:00:00 2001 From: Nicolas Luck Date: Thu, 21 Nov 2024 15:03:02 +0100 Subject: [PATCH 32/43] Don't touch abseil code files if they were changed before to prevent rebuilds every time --- build.rs | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/build.rs b/build.rs index 8a565fa698..2d9429d386 100644 --- a/build.rs +++ b/build.rs @@ -1104,30 +1104,31 @@ pub fn parse_ninja_graph(s: &str) -> HashSet { } fn modify_abseil_options(options_path: &PathBuf) -> io::Result<()> { - // Read the contents of options.h - let mut options_content = fs::read_to_string(&options_path)?; - - // Modify the necessary lines - // Replace the definitions of ABSL_OPTION_USE_INLINE_NAMESPACE and ABSL_OPTION_INLINE_NAMESPACE_NAME - options_content = options_content - .lines() - .map(|line| { - if line.contains("#define ABSL_OPTION_USE_INLINE_NAMESPACE") { - "#define ABSL_OPTION_USE_INLINE_NAMESPACE 1".to_string() - } else if line.contains("#define ABSL_OPTION_INLINE_NAMESPACE_NAME") { - "#define ABSL_OPTION_INLINE_NAMESPACE_NAME v8".to_string() - } else { - line.to_string() - } - }) - .collect::>() - .join("\n"); - - // Write the modified content back to options.h - let mut file = fs::File::create(&options_path)?; - file.write_all(options_content.as_bytes())?; + // Read the contents of options.h + let current_content = fs::read_to_string(&options_path)?; + + // Create the expected content + let new_content = current_content + .lines() + .map(|line| { + if line.contains("#define ABSL_OPTION_USE_INLINE_NAMESPACE") { + "#define ABSL_OPTION_USE_INLINE_NAMESPACE 1".to_string() + } else if line.contains("#define ABSL_OPTION_INLINE_NAMESPACE_NAME") { + "#define ABSL_OPTION_INLINE_NAMESPACE_NAME v8".to_string() + } else { + line.to_string() + } + }) + .collect::>() + .join("\n"); + + // Only write if content actually changed + if current_content != new_content { + let mut file = fs::File::create(&options_path)?; + file.write_all(new_content.as_bytes())?; + } - Ok(()) + Ok(()) } #[cfg(test)] From bd08cbdf91684219766fc3b6ef32a80003904f28 Mon Sep 17 00:00:00 2001 From: Nicolas Luck Date: Fri, 22 Nov 2024 12:34:46 +0100 Subject: [PATCH 33/43] Remove visibility=hidden flags again, namespacing abseil is the actual fix --- build.rs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/build.rs b/build.rs index 2d9429d386..d4d10b4cae 100644 --- a/build.rs +++ b/build.rs @@ -170,15 +170,7 @@ fn build_v8(is_asan: bool) { modify_abseil_options(&abseil_options_path).expect("Failed to modify options.h"); - if cfg!(target_os = "linux") { - gn_args.push(r#"extra_cflags = [ "-fvisibility=hidden", "-fvisibility-inlines-hidden" ]"#.to_string()); - gn_args.push(r#"extra_ldflags = [ "-Wl,-Bsymbolic" ]"#.to_string()); - } - if cfg!(target_os = "macos") { - gn_args.push(r#"extra_cflags = [ "-fvisibility=hidden", "-fvisibility-inlines-hidden" ]"#.to_string()); - gn_args.push(r#"extra_ldflags = [ "-Wl,-x" ]"#.to_string()); - // Fix GN's host_cpu detection when using x86_64 bins on Apple Silicon let host_arch = std::env::var("HOST_ARCH").unwrap_or_else(|_| { // Detect the host architecture From 22f07e668ca8d0763f93f69c40a081d00ca334cf Mon Sep 17 00:00:00 2001 From: Nicolas Luck Date: Fri, 22 Nov 2024 12:35:15 +0100 Subject: [PATCH 34/43] Rerun if PROFILE (debug/release) has changed --- build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.rs b/build.rs index d4d10b4cae..a47cccba6a 100644 --- a/build.rs +++ b/build.rs @@ -1008,7 +1008,7 @@ pub fn build(target: &str, maybe_env: Option) { } println!("cargo:rerun-if-env-changed=CARGO_CFG_TARGET_ARCH"); - //println!("cargo:rerun-if-env-changed=PROFILE"); + println!("cargo:rerun-if-env-changed=PROFILE"); rerun_if_changed(&gn_out_dir, maybe_env.clone(), target); // This helps Rust source files locate the snapshot, source map etc. From 8525ceed3b851a114afc05cba72544780462aec1 Mon Sep 17 00:00:00 2001 From: Nicolas Luck Date: Fri, 22 Nov 2024 13:32:58 +0100 Subject: [PATCH 35/43] Fix extra_cflags syntax --- build.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/build.rs b/build.rs index a47cccba6a..e7033c9219 100644 --- a/build.rs +++ b/build.rs @@ -191,11 +191,11 @@ fn build_v8(is_asan: bool) { gn_args.push(format!("host_cpu=\"{}\"", host_arch)); if target_arch == "x86_64" { - gn_args.push(r#"extra_cflags += [ "-arch", "x86_64" ]"#.to_string()); - gn_args.push(r#"extra_ldflags += [ "-arch", "x86_64" ]"#.to_string()); + gn_args.push(r#"extra_cflags = [ "-arch", "x86_64" ]"#.to_string()); + gn_args.push(r#"extra_ldflags = [ "-arch", "x86_64" ]"#.to_string()); } else if target_arch == "aarch64" { - gn_args.push(r#"extra_cflags += [ "-arch", "arm64" ]"#.to_string()); - gn_args.push(r#"extra_ldflags += [ "-arch", "arm64" ]"#.to_string()); + gn_args.push(r#"extra_cflags = [ "-arch", "arm64" ]"#.to_string()); + gn_args.push(r#"extra_ldflags = [ "-arch", "arm64" ]"#.to_string()); } } From cc7271b9338e11af1a47c2483c26f67dbee69147 Mon Sep 17 00:00:00 2001 From: Nicolas Luck Date: Fri, 22 Nov 2024 14:39:53 +0100 Subject: [PATCH 36/43] Set symbol_level to 2 for debug, 1 for release builds --- .gn | 2 -- build.rs | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gn b/.gn index 81edfd71ac..eacbbf424a 100644 --- a/.gn +++ b/.gn @@ -20,7 +20,6 @@ default_args = { clang_use_chrome_plugins = false v8_use_external_startup_data = false v8_enable_symbol_visibility = true - symbol_level = 2 use_custom_libcxx = true # trying to get cppgc build v8_enable_oilpan=true @@ -35,7 +34,6 @@ default_args = { # Minimize size of debuginfo in distributed static library. line_tables_only = true no_inline_line_tables = true - symbol_level = 1 use_debug_fission = false v8_enable_sandbox = false diff --git a/build.rs b/build.rs index e7033c9219..703a26f098 100644 --- a/build.rs +++ b/build.rs @@ -152,6 +152,8 @@ fn build_v8(is_asan: bool) { } else { vec!["is_debug=false".to_string()] }; + let symbol_level = if is_debug() { "2" } else { "1" }; + gn_args.push(format!("symbol_level={}", symbol_level)); if is_asan { gn_args.push("is_asan=true".to_string()); } From 50b4f614e9b0263e297a86df4dfa3bccefa120f1 Mon Sep 17 00:00:00 2001 From: Nicolas Luck Date: Fri, 22 Nov 2024 14:40:40 +0100 Subject: [PATCH 37/43] cflag: -D_LIBCPP_DISABLE_ASSERTS --- build.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/build.rs b/build.rs index 703a26f098..562d067167 100644 --- a/build.rs +++ b/build.rs @@ -161,6 +161,8 @@ fn build_v8(is_asan: bool) { gn_args.push("use_custom_libcxx=false".to_string()); } + gn_args.push(r#"extra_cflags = [ "-D_LIBCPP_DISABLE_ASSERTS" ]"#.to_string()); + gn_args.push(r#"default_symbol_visibility = "hidden""#.to_string()); let repo_root = env::current_dir().unwrap(); let abseil_options_path = repo_root @@ -193,10 +195,10 @@ fn build_v8(is_asan: bool) { gn_args.push(format!("host_cpu=\"{}\"", host_arch)); if target_arch == "x86_64" { - gn_args.push(r#"extra_cflags = [ "-arch", "x86_64" ]"#.to_string()); + gn_args.push(r#"extra_cflags += [ "-arch", "x86_64" ]"#.to_string()); gn_args.push(r#"extra_ldflags = [ "-arch", "x86_64" ]"#.to_string()); } else if target_arch == "aarch64" { - gn_args.push(r#"extra_cflags = [ "-arch", "arm64" ]"#.to_string()); + gn_args.push(r#"extra_cflags += [ "-arch", "arm64" ]"#.to_string()); gn_args.push(r#"extra_ldflags = [ "-arch", "arm64" ]"#.to_string()); } } From 7efd271408acc90335cdca5caaca6f998a71efdd Mon Sep 17 00:00:00 2001 From: Nicolas Luck Date: Fri, 22 Nov 2024 17:00:15 +0100 Subject: [PATCH 38/43] is_component_build=false in .gn to always build a static lib --- .gn | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.gn b/.gn index eacbbf424a..c3488a4744 100644 --- a/.gn +++ b/.gn @@ -18,13 +18,8 @@ secondary_source = "//v8/" default_args = { clang_use_chrome_plugins = false - v8_use_external_startup_data = false - v8_enable_symbol_visibility = true - use_custom_libcxx = true - # trying to get cppgc build - v8_enable_oilpan=true + is_component_build = false treat_warnings_as_errors = false - linux_use_bundled_binutils = false use_dummy_lastchange = true From 4a13d4083e0abe291c2b1c769b7b612e26f6ab5d Mon Sep 17 00:00:00 2001 From: Nicolas Luck Date: Fri, 22 Nov 2024 17:48:02 +0100 Subject: [PATCH 39/43] Keep symbol level to 1 to prevent B/BL out of range errors --- .gn | 1 + build.rs | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.gn b/.gn index c3488a4744..8bcc1f92ea 100644 --- a/.gn +++ b/.gn @@ -29,6 +29,7 @@ default_args = { # Minimize size of debuginfo in distributed static library. line_tables_only = true no_inline_line_tables = true + symbol_level = 1 use_debug_fission = false v8_enable_sandbox = false diff --git a/build.rs b/build.rs index 562d067167..a782eb484b 100644 --- a/build.rs +++ b/build.rs @@ -152,8 +152,6 @@ fn build_v8(is_asan: bool) { } else { vec!["is_debug=false".to_string()] }; - let symbol_level = if is_debug() { "2" } else { "1" }; - gn_args.push(format!("symbol_level={}", symbol_level)); if is_asan { gn_args.push("is_asan=true".to_string()); } From 2aa8167dbca5026c3c29b7c3af2109aff44a7987 Mon Sep 17 00:00:00 2001 From: Nicolas Luck Date: Mon, 24 Feb 2025 17:43:33 +0100 Subject: [PATCH 40/43] Patch v8 sources to avoid non standard use of C++ template, preventing build on XXcode 15 toolchain --- build.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/build.rs b/build.rs index a782eb484b..f880c0488a 100644 --- a/build.rs +++ b/build.rs @@ -182,6 +182,10 @@ fn build_v8(is_asan: bool) { other => other.to_string(), } }); + + if host_arch == "x64" { + patch_v8_files(); + } let target_cpu = match target_arch.as_str() { "x86_64" => "x64", @@ -1125,6 +1129,34 @@ fn modify_abseil_options(options_path: &PathBuf) -> io::Result<()> { Ok(()) } + +fn patch_v8_files() { + // List all files that need patching. + let files_to_patch = [ + "v8/src/compiler/turboshaft/wasm-revec-reducer.h", + "v8/src/compiler/turboshaft/wasm-revec-phase.cc", + ]; + + for file in &files_to_patch { + if Path::new(file).exists() { + println!("Patching {}", file); + let status = Command::new("sed") + .args(&[ + "-i.bak", + "s/\\.TryCast Date: Mon, 3 Mar 2025 20:40:49 +0100 Subject: [PATCH 41/43] Fix maybe_symlink_root_dir to treat C:\ and c:\ as same drive --- build.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/build.rs b/build.rs index f880c0488a..b86dfbc6b3 100644 --- a/build.rs +++ b/build.rs @@ -890,12 +890,13 @@ fn maybe_symlink_root_dir(dirs: &mut Dirs) { use std::os::windows::fs::symlink_dir; let get_prefix = |p: &Path| { - p.components() + let prefix = p.components() .find_map(|c| match c { std::path::Component::Prefix(p) => Some(p), _ => None, }) - .map(|p| p.as_os_str().to_owned()) + .map(|p| p.as_os_str().to_string_lossy().to_lowercase()); + prefix }; let Dirs { out, root } = dirs; From d78e718dd0d202cbbb9befcf2898982d57624fbd Mon Sep 17 00:00:00 2001 From: Nicolas Luck Date: Mon, 3 Mar 2025 20:50:36 +0100 Subject: [PATCH 42/43] Add patch to build.rs, fixing inspector_protocol.gni to turn /C:/ into C:/ --- build.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/build.rs b/build.rs index b86dfbc6b3..cab2872745 100644 --- a/build.rs +++ b/build.rs @@ -172,6 +172,10 @@ fn build_v8(is_asan: bool) { modify_abseil_options(&abseil_options_path).expect("Failed to modify options.h"); + if cfg!(target_os = "windows" ) { + patch_inspector_protocol(); + } + if cfg!(target_os = "macos") { // Fix GN's host_cpu detection when using x86_64 bins on Apple Silicon let host_arch = std::env::var("HOST_ARCH").unwrap_or_else(|_| { @@ -1158,6 +1162,31 @@ fn patch_v8_files() { } } +fn patch_inspector_protocol() { + let v8_root = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()).join("v8"); + let gni_path = v8_root.join("third_party/inspector_protocol/inspector_protocol.gni"); + + // Read the original content + let mut content = fs::read_to_string(&gni_path) + .expect("Failed to read inspector_protocol.gni"); + + // Patch the outputs_pre line + let old_line = "outputs_pre = get_path_info(rebase_path(invoker.outputs, \".\", invoker.out_dir), \"abspath\")"; + let new_lines = r#"outputs_pre = get_path_info(rebase_path(invoker.outputs, ".", invoker.out_dir), "abspath") + outputs = [] + foreach(out, outputs_pre) { + outputs += [ string_replace(out, "/C:/", "C:/") ] + }"#; + if content.contains(old_line) { + content = content.replace(old_line, new_lines); + fs::write(&gni_path, content) + .expect("Failed to write patched inspector_protocol.gni"); + println!("Patched inspector_protocol.gni to fix /C:/ paths"); + } else { + println!("Warning: Could not find outputs_pre line to patch in inspector_protocol.gni"); + } +} + #[cfg(test)] mod test { use super::*; From 06b344d6e621a35b69250dc90a6724bf11f6b82e Mon Sep 17 00:00:00 2001 From: Nicolas Luck Date: Mon, 3 Mar 2025 21:17:39 +0100 Subject: [PATCH 43/43] Fix match line in last commit --- build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.rs b/build.rs index cab2872745..ab6601143f 100644 --- a/build.rs +++ b/build.rs @@ -1171,7 +1171,7 @@ fn patch_inspector_protocol() { .expect("Failed to read inspector_protocol.gni"); // Patch the outputs_pre line - let old_line = "outputs_pre = get_path_info(rebase_path(invoker.outputs, \".\", invoker.out_dir), \"abspath\")"; + let old_line = "outputs = get_path_info(rebase_path(invoker.outputs, \".\", invoker.out_dir),\n \"abspath\")"; let new_lines = r#"outputs_pre = get_path_info(rebase_path(invoker.outputs, ".", invoker.out_dir), "abspath") outputs = [] foreach(out, outputs_pre) {