Skip to content

Commit

Permalink
fix(IDX): work around proc-macro2 non-determinism (#2176)
Browse files Browse the repository at this point in the history
This is a patch for `rules_rust` to work around some build determinism
issues in the `proc-macro2` Bazel build.

For more information, see:
* dtolnay/proc-macro2#473
* bazelbuild/rules_rust#2952
  • Loading branch information
nmattia authored Oct 22, 2024
1 parent 8f6e8ca commit 6afff64
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
4 changes: 3 additions & 1 deletion WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ sol_register_toolchains(

http_archive(
name = "rules_rust",
integrity = "sha256-JLN47ZcAbx9wEr5Jiib4HduZATGLiDgK7oUi/fvotzU=",
patch_args = ["-p1"],
patches = ["//bazel:rules_rust.patch"],
sha256 = "24b378ed97006f1f7012be498a26f81ddb9901318b88380aee8522fdfbe8b735",
urls = ["https://github.com/bazelbuild/rules_rust/releases/download/0.42.1/rules_rust-v0.42.1.tar.gz"],
)

Expand Down
27 changes: 27 additions & 0 deletions bazel/rules_rust.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# workaround for proc-macro2 build determinism issues
# https://github.com/dtolnay/proc-macro2/issues/473
diff --git a/cargo/cargo_build_script_runner/bin.rs b/cargo/cargo_build_script_runner/bin.rs
index 8730c809..f8eda5db 100644
--- a/cargo/cargo_build_script_runner/bin.rs
+++ b/cargo/cargo_build_script_runner/bin.rs
@@ -84,7 +84,7 @@ fn run_buildrs() -> Result<(), String> {
command
.current_dir(&working_directory)
.envs(target_env_vars)
- .env("OUT_DIR", out_dir_abs)
+ .env("OUT_DIR", out_dir_abs.clone())
.env("CARGO_MANIFEST_DIR", manifest_dir)
.env("RUSTC", rustc)
.env("RUST_BACKTRACE", "full");
@@ -195,6 +195,11 @@ fn run_buildrs() -> Result<(), String> {
.unwrap_or_else(|_| panic!("Unable to write file {:?}", link_flags_file));
write(&link_search_paths_file, link_search_paths.as_bytes())
.unwrap_or_else(|_| panic!("Unable to write file {:?}", link_search_paths_file));
+
+ let proc_macro2_d = out_dir_abs.join("proc_macro2.d");
+ if Path::new(&proc_macro2_d).exists() {
+ std::fs::remove_file(proc_macro2_d).unwrap();
+ }
Ok(())
}

0 comments on commit 6afff64

Please sign in to comment.