diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 808b833923..c89373ac04 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -317,6 +317,11 @@ jobs: pattern: src_binding_*.rs merge-multiple: true + - name: Commit modified abseil options.h + run: | + git add third_party/abseil-cpp/absl/base/options.h + git commit -m "chore: commit modified abseil options.h" + - name: Publish env: CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} diff --git a/build.rs b/build.rs index bb55f8ee58..0850c56790 100644 --- a/build.rs +++ b/build.rs @@ -325,6 +325,17 @@ fn build_v8(is_asan: bool) { gn_args.push(r#"target_cpu="x86""#.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"); + + set_abseil_options_to_use_namespace(&abseil_options_path) + .expect("Failed to modify options.h"); + let gn_out = run_gn_gen(&gn_args); assert!(gn_out.exists()); assert!(gn_out.join("args.gn").exists()); @@ -1079,6 +1090,36 @@ fn env_bool(key: &str) -> bool { ) } +fn set_abseil_options_to_use_namespace( + options_path: &PathBuf, +) -> io::Result<()> { + // 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(()) +} + #[cfg(test)] mod test { use super::*;