-
Notifications
You must be signed in to change notification settings - Fork 317
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(IDX): make replica build more deterministic (#2441)
This includes a couple of fixes to make the replica build more deterministic. This in theory allows anyone building `//rs/replica` with Bazel in the Docker image to get a bit-for-bit reproducible replica executable, and this should also improve Bazel cache hit rates. This fixes for the following issues: * Non-reproducible `jemalloc` build: the `tikv-jemalloc-sys` crate vendors `jemalloc` and builds it as part of `build.rs`. Unfortunately that build in not deterministic. To make it more deterministic we build `jemalloc` separately, which also speeds up rebuilds as the C code does not need to be rebuilt when rust versions change. We only enable this in Linux; this also includes a patch to support this in `rules_rust`: bazelbuild/rules_rust#2981 * Non-reproducible `rules_rust` build log: this includes a backport of a fix that disables build logs in `rules_rust` by default (backported because our build is not compatible with the latest `rules_rust`) bazelbuild/rules_rust#2974 * Non-reproducible make & pkgconfig toolchains: some toolchains packaged by `rules_foreign_cc` cause build determinism issues so instead we use the ones installed in the container and remove build logs: bazel-contrib/rules_foreign_cc#1313 * Non-reproducible obj file generation in cc-rs: the `cc-rs` crate used in many C builds, including the (ASM) build of `ring`'s crypto bits, generates object files that include the Bazel sandbox full path: rust-lang/cc-rs#1271 * Non-reproducible codegen: `cranelift-isle` and `cranelift-codegen-meta` include references to source files as absolute paths that include the Bazel sandbox path: bytecodealliance/wasmtime#9553
- Loading branch information
1 parent
e1508be
commit fc88220
Showing
13 changed files
with
328 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
diff --git a/src/lib.rs b/src/lib.rs | ||
index 2fe30b9..88cd566 100644 | ||
--- a/src/lib.rs | ||
+++ b/src/lib.rs | ||
@@ -1121,6 +1121,13 @@ impl Build { | ||
.ok_or_else(|| Error::new(ErrorKind::InvalidArgument, "parent() failure"))? | ||
.to_string_lossy(); | ||
let mut hasher = hash_map::DefaultHasher::new(); | ||
+ let out_dir = self.get_out_dir().expect("Could not get out dir"); | ||
+ | ||
+ let prefix = out_dir.parent().expect("Could not get parent"); | ||
+ let prefix: &str = &prefix.to_string_lossy(); | ||
+ | ||
+ let err = format!("could not strip prefix {prefix} from {dirname}"); | ||
+ let dirname = dirname.strip_prefix(prefix).expect(&err); | ||
hasher.write(dirname.to_string().as_bytes()); | ||
dst.join(format!("{:016x}-{}", hasher.finish(), basename)) | ||
.with_extension("o") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Fix for https://github.com/bytecodealliance/wasmtime/issues/9553 | ||
diff --git a/cranelift/codegen/meta/src/srcgen.rs b/cranelift/codegen/meta/src/srcgen.rs | ||
index d3c321e5b..5b94ddd19 100644 | ||
--- a/cranelift/codegen/meta/src/srcgen.rs | ||
+++ b/cranelift/codegen/meta/src/srcgen.rs | ||
@@ -94,7 +94,6 @@ impl Formatter { | ||
directory: &std::path::Path, | ||
) -> Result<(), error::Error> { | ||
let path = directory.join(&filename); | ||
- eprintln!("Writing generated file: {}", path.display()); | ||
let mut f = fs::File::create(path)?; | ||
|
||
for l in self.lines.iter().map(|l| l.as_bytes()) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Fix for https://github.com/bytecodealliance/wasmtime/issues/9553 | ||
diff --git a/cranelift/isle/isle/src/codegen.rs b/cranelift/isle/isle/src/codegen.rs | ||
index 158285832..d292e43c0 100644 | ||
--- a/cranelift/isle/isle/src/codegen.rs | ||
+++ b/cranelift/isle/isle/src/codegen.rs | ||
@@ -127,9 +127,6 @@ impl<'a> Codegen<'a> { | ||
"// Generated automatically from the instruction-selection DSL code in:", | ||
) | ||
.unwrap(); | ||
- for file in &self.files.file_names { | ||
- writeln!(code, "// - {file}").unwrap(); | ||
- } | ||
|
||
if !options.exclude_global_allow_pragmas { | ||
writeln!( | ||
@@ -641,12 +638,11 @@ impl<L: Length, C> Length for ContextIterWrapper<L, C> {{ | ||
stack.push((Self::validate_block(ret_kind, body), "", scope)); | ||
} | ||
|
||
- &ControlFlow::Return { pos, result } => { | ||
+ &ControlFlow::Return { pos: _pos, result } => { | ||
writeln!( | ||
ctx.out, | ||
- "{}// Rule at {}.", | ||
+ "{}", | ||
&ctx.indent, | ||
- pos.pretty_print_line(&self.files) | ||
)?; | ||
write!(ctx.out, "{}", &ctx.indent)?; | ||
match ret_kind { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Avoid build logs that create sources of non-determinism | ||
diff --git a/foreign_cc/private/framework.bzl b/foreign_cc/private/framework.bzl | ||
index 33129b8..7326107 100644 | ||
--- a/foreign_cc/private/framework.bzl | ||
+++ b/foreign_cc/private/framework.bzl | ||
@@ -616,7 +616,7 @@ def wrap_outputs(ctx, lib_name, configure_name, script_text, env_prelude, build_ | ||
cleanup_on_success_function = create_function( | ||
ctx, | ||
"cleanup_on_success", | ||
- "rm -rf $$BUILD_TMPDIR$$ $$EXT_BUILD_DEPS$$", | ||
+ "rm -rf $$BUILD_TMPDIR$$ $$EXT_BUILD_DEPS$$ && echo > $$BUILD_LOG$$", | ||
) | ||
cleanup_on_failure_function = create_function( | ||
ctx, |
Oops, something went wrong.