Description
While experimenting with rules_rust build reproducibility, I found that the process_wrapper
binary build is not deterministic.
How I reproduced the problem:
I created 2 identical directories on my macOS machine with the following content:
$ cat panic.rs
fn main() {
panic!("boom!")
}
$ cat WORKSPACE.bazel
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "rules_rust",
sha256 = "6bfe75125e74155955d8a9854a8811365e6c0f3d33ed700bc17f39e32522c822",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_rust/releases/download/0.9.0/rules_rust-v0.9.0.tar.gz",
"https://github.com/bazelbuild/rules_rust/releases/download/0.9.0/rules_rust-v0.9.0.tar.gz",
],
)
load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_register_toolchains")
rules_rust_dependencies()
rust_register_toolchains(version = "1.60.0")
$ cat BUILD.bazel
load("@rules_rust//rust:defs.bzl", "rust_binary")
rust_binary(
name = "panic",
srcs = ["panic.rs"],
edition = "2018",
)
$ cat .bazelrc
build --@rules_rust//:source_path_prefix=/source/
build --execution_log_json_file=bazel-build-log.json
Running bazel build :panic
produced slightly different binaries.
An inspection of bazel-build-log.json
file showed that process_wrapper
had different hashes in the two workspaces:
***************
*** 509,513 ****
"path": "bazel-out/darwin-opt-exec-2B5CBBC6/bin/external/rules_rust_tinyjson/libtinyjson-4031717389.rlib",
"digest": {
! "hash": "8532cb231d123c1a6f64e3129d11461c4062c1ee499ae37654445582d8dd3e15",
"sizeBytes": "630696",
"hashFunctionName": "SHA-256"
--- 509,513 ----
"path": "bazel-out/darwin-opt-exec-2B5CBBC6/bin/external/rules_rust_tinyjson/libtinyjson-4031717389.rlib",
"digest": {
! "hash": "2b96b6712a77e791792f9be2d7de9ac89ffda7648724ef3b121071607201eb69",
"sizeBytes": "630696",
"hashFunctionName": "SHA-256"
***************
*** 915,919 ****
"path": "bazel-out/darwin-opt-exec-2B5CBBC6/bin/external/rules_rust/util/process_wrapper/process_wrapper",
"digest": {
! "hash": "20cbe0042ca135fad3f79c7dc37176b2d9b274d29e2abf4c7707a5eda31fab88",
"sizeBytes": "760720",
"hashFunctionName": "SHA-256"
--- 915,919 ----
"path": "bazel-out/darwin-opt-exec-2B5CBBC6/bin/external/rules_rust/util/process_wrapper/process_wrapper",
"digest": {
! "hash": "e32aa301edcfd8ff12584c886befc2cc2a6409a399679dcd91f46e3fc58dc0a9",
"sizeBytes": "760720",
"hashFunctionName": "SHA-256"
***************
The source of non-determinism is likely the libtinyjson.rlib
file that has different file paths embedded into it:
The first workspace had path "/tmp/sandbox/darwin-sandbox/1/execroot/main/...", the second workspace had path "/private/var/tmp/_bazel_lifted/dba7...561c/sandbox/darwin-sandbox/1/execroot/main/...".
Comment from Rosica Dejanovska:
Looks like we need to temporarily bring back a tiny part of the old C++ process wrapper that does what --subst pwd=${pwd} does. Long term rust-lang/rust#89434 should save us.