travisdowns opened issue #13121:
Summary
The
build.rsscripts forcranelift-codegenandcranelift-assembler-x64embed absolute filesystem paths into generated Rust source files. These paths change across different build environments (different machines, different--target-dirvalues, sandboxed build systems like Bazel or Nix), producing non-reproducible build artifacts.Both issues are present on
mainas of d5f1b973e48b.Affected crates
1.
cranelift-assembler-x64
cranelift/assembler-x64/build.rswrites absoluteOUT_DIRpaths directly intogenerated-files.rswith no attempt to relativize:for file in &built_files { writeln!(vec_of_built_files, " {:?}.into(),", file.display()).unwrap(); }
built_filescontains absolute paths derived fromOUT_DIR, sogenerated-files.rsends up with:vec![ "/home/alice/wasmtime/target/debug/build/cranelift-assembler-x64-abc123/out/assembler.rs".into(), ]This path changes with the build directory, user home directory, or sandbox instance.
2.
cranelift-codegen
make_isle_source_path_relative()incranelift/codegen/build.rstries to stripcur_dir(the crate's source directory) from file paths:fn make_isle_source_path_relative( cur_dir: &std::path::Path, filename: &std::path::Path, ) -> std::path::PathBuf { if let Ok(suffix) = filename.strip_prefix(&cur_dir) { suffix.to_path_buf() } else { filename.to_path_buf() // ← falls back to absolute path } }This function is called with
isle_dir(=OUT_DIR) as the filename. SinceOUT_DIRis under thetarget/directory and not under the crate source directory,strip_prefixfails, and the absolute path falls through unchanged. These absolute paths then get embedded into ISLE-generated source files (isle_x64.rs, etc.) as:
- Error string literals:
"no rule matched for term ... at /home/alice/wasmtime/target/debug/build/cranelift-codegen-XXX/out/assembler.isle line 18"- Source location comments:
// Rule at /home/alice/.../assembler.isle line 19The paths for source inputs (under
crate_dir) ARE correctly relativized becausecrate_diris the current working directory. Only paths underOUT_DIRleak through.Impact
- Standard Cargo builds: building on different machines, or with different
--target-dir, produces different generated source and different final binaries- Sandboxed builds (Bazel, Nix, etc.): each build action runs in a unique sandbox directory, so every build produces a different binary even on the same machine with the same inputs
Reproducer
Tested on v32.0.0 (cranelift 0.119.0) and confirmed still present on
main.cd wasmtime # Build with two different target directories CARGO_TARGET_DIR=/tmp/build1 cargo build -p cranelift-codegen --features x86 -p cranelift-assembler-x64 CARGO_TARGET_DIR=/tmp/build2 cargo build -p cranelift-codegen --features x86 -p cranelift-assembler-x64 # cranelift-assembler-x64: absolute paths in generated-files.rs cat /tmp/build1/debug/build/cranelift-assembler-x64-*/out/generated-files.rs # vec![ # "/tmp/build1/debug/build/cranelift-assembler-x64-8eadefadaa0bb4cd/out/assembler.rs".into(), # ] # cranelift-codegen: absolute paths in ISLE-generated source # (despite make_isle_source_path_relative trying to strip them) grep -c "/tmp/build1" /tmp/build1/debug/build/cranelift-codegen-*/out/isle_x64.rs # → 297 matches — all from OUT_DIR paths where strip_prefix failedEnvironment
- Discovered building wasmtime 32.0.0 via Bazel (rules_rust) with sandboxed execution
- Confirmed present on
main(d5f1b973e48b)- Also reproducible with standard Cargo using different
--target-dirvalues
travisdowns edited issue #13121:
Summary
The
build.rsscripts forcranelift-codegenandcranelift-assembler-x64embed absolute filesystem paths into generated Rust source files. These paths change across different build environments (different machines, different--target-dirvalues, sandboxed build systems like Bazel or Nix), producing non-reproducible build artifacts.Both issues are present on
mainas of d5f1b973e48b.Affected crates
1.
cranelift-assembler-x64
cranelift/assembler-x64/build.rswrites absoluteOUT_DIRpaths directly intogenerated-files.rswith no attempt to relativize:for file in &built_files { writeln!(vec_of_built_files, " {:?}.into(),", file.display()).unwrap(); }\`built_files\` contains absolute paths derived from \`OUT_DIR\`, so \`generated-files.rs\` ends up with:
vec![ "/home/alice/wasmtime/target/debug/build/cranelift-assembler-x64-abc123/out/assembler.rs".into(), ]This path changes with the build directory, user home directory, or sandbox instance.
2.
cranelift-codegen
make_isle_source_path_relative()incranelift/codegen/build.rstries to stripcur_dir(the crate's source directory) from file paths:fn make_isle_source_path_relative( cur_dir: &std::path::Path, filename: &std::path::Path, ) -> std::path::PathBuf { if let Ok(suffix) = filename.strip_prefix(&cur_dir) { suffix.to_path_buf() } else { filename.to_path_buf() // ← falls back to absolute path } }This function is called with
isle_dir(=OUT_DIR) as the filename. WhenOUT_DIRis a descendant ofcur_dir,strip_prefixsucceeds and paths are correctly relativized — this is the common case in standard Cargo builds wheretarget/is under the workspace root and the crate source is also under the workspace root. However, whenOUT_DIRis NOT undercur_dir,strip_prefixfails and the absolute path falls through unchanged. This happens in:
- Sandboxed builds (Bazel, Nix, etc.) where
OUT_DIRandCWDare under different subtrees of the sandbox- Cargo builds with
--target-dirpointing outside the workspace (e.g.CARGO_TARGET_DIR=/tmp/build)- Any build where the output directory tree doesn't share a prefix with the source directory
These absolute paths get embedded into ISLE-generated source files (
isle_x64.rs, etc.) as:
- Error string literals:
"no rule matched for term ... at /home/alice/wasmtime/target/debug/build/cranelift-codegen-XXX/out/assembler.isle line 18"- Source location comments:
// Rule at /home/alice/.../assembler.isle line 19The paths for source inputs (under
crate_dir) ARE correctly relativized becausecrate_diris the current working directory. Only paths underOUT_DIRleak through when it's outside the CWD tree.Impact
- Standard Cargo builds: building on different machines, or with
--target-diroutside the workspace, produces different generated source and different final binaries- Sandboxed builds (Bazel, Nix, etc.): each build action runs in a unique sandbox directory, so every build produces a different binary even on the same machine with the same inputs
Reproducer
Tested on v32.0.0 (cranelift 0.119.0) and confirmed still present on
main.cd wasmtime # Build with two different target directories (outside the workspace) CARGO_TARGET_DIR=/tmp/build1 cargo build -p cranelift-codegen --features x86 -p cranelift-assembler-x64 CARGO_TARGET_DIR=/tmp/build2 cargo build -p cranelift-codegen --features x86 -p cranelift-assembler-x64 # cranelift-assembler-x64: absolute paths in generated-files.rs cat /tmp/build1/debug/build/cranelift-assembler-x64-*/out/generated-files.rs # vec![ # "/tmp/build1/debug/build/cranelift-assembler-x64-8eadefadaa0bb4cd/out/assembler.rs".into(), # ] # cranelift-codegen: absolute paths in ISLE-generated source # (make_isle_source_path_relative's strip_prefix fails because # /tmp/build1/... is not under the CWD) grep -c "/tmp/build1" /tmp/build1/debug/build/cranelift-codegen-*/out/isle_x64.rs # → 297 matches — all from OUT_DIR paths where strip_prefix failedEnvironment
- Discovered building wasmtime 32.0.0 via Bazel (rules_rust) with sandboxed execution
- Confirmed present on
main(d5f1b973e48b)- Also reproducible with standard Cargo using different
--target-dirvalues
cfallin commented on issue #13121:
@travisdowns thanks for the report -- we're happy to take PRs to fix reproducible build issues!
travisdowns commented on issue #13121:
@travisdowns thanks for the report -- we're happy to take PRs to fix reproducible build issues!
I was in the middle of that, but just noticed on main there have been changes already in this which might fix it ... that escaped my attention. Will update shortly.
travisdowns edited issue #13121:
Summary
The
build.rsscripts forcranelift-codegenandcranelift-assembler-x64embed absolute filesystem paths into generated Rust source files. These paths change across different build environments (different machines, different--target-dirvalues, sandboxed build systems like Bazel or Nix), producing non-reproducible build artifacts.Status
cranelift-codegen: Fixed onmainby 0694bba38 ("Strip prefixes in file names"), which replacesOUT_DIRpaths with<OUT_DIR>in the ISLE-generated source. Sorry for the noise on this one — I was testing against v32.0.0 and missed that this was already fixed. I'll pick this up when the next release ships.
cranelift-assembler-x64: Still unfixed onmain. See details below.
cranelift-assembler-x64
cranelift/assembler-x64/build.rswrites absoluteOUT_DIRpaths directly intogenerated-files.rswith no attempt to relativize:for file in &built_files { writeln!(vec_of_built_files, " {:?}.into(),", file.display()).unwrap(); }\`built_files\` contains absolute paths derived from \`OUT_DIR\`, so \`generated-files.rs\` ends up with:
vec![ "/home/alice/wasmtime/target/debug/build/cranelift-assembler-x64-abc123/out/assembler.rs".into(), ]Verified still present on
main(d5f1b973e48b).Impact
- Standard Cargo builds: building on different machines, or with
--target-diroutside the workspace, produces different generated source and different final binaries- Sandboxed builds (Bazel, Nix, etc.): each build action runs in a unique sandbox directory, so every build produces a different binary even on the same machine with the same inputs
Reproducer
cd wasmtime CARGO_TARGET_DIR=/tmp/build1 cargo build -p cranelift-assembler-x64 CARGO_TARGET_DIR=/tmp/build2 cargo build -p cranelift-assembler-x64 # Different absolute paths in generated-files.rs: cat /tmp/build1/debug/build/cranelift-assembler-x64-*/out/generated-files.rs # vec![ # "/tmp/build1/debug/build/cranelift-assembler-x64-8eadefadaa0bb4cd/out/assembler.rs".into(), # ] cat /tmp/build2/debug/build/cranelift-assembler-x64-*/out/generated-files.rs # vec![ # "/tmp/build2/debug/build/cranelift-assembler-x64-8eadefadaa0bb4cd/out/assembler.rs".into(), # ]Environment
- Discovered building wasmtime 32.0.0 via Bazel (rules_rust) with sandboxed execution
- Also reproducible with standard Cargo using different
--target-dirvalues
travisdowns commented on issue #13121:
Updated the issue:
cranelift-codegenwas already fixed onmainby 0694bba38 ("Strip prefixes in file names"). Onlycranelift-assembler-x64remains affected. Working on a PR for that now.
travisdowns commented on issue #13121:
On closer look,
generated-files.rsis only consumed by thecranelift-assembler-x64utility binary (main.rs), not the library. For a utility that prints paths to generated code, absolute paths are the right behavior — relative or placeholder paths would make the output less useful.It's possible to make the
generated-files.rssource itself deterministic (e.g. by usingenv!("OUT_DIR")to defer path resolution to compile time), but the binary would still contain the absolute path afterenv!()expansion, so the non-determinism just moves from the source file to the compiled output. Not much of a win.I think this issue can be closed — the
cranelift-codegenside was already fixed by 0694bba38, and thecranelift-assembler-x64side doesn't need fixing.
travisdowns closed issue #13121:
Summary
The
build.rsscripts forcranelift-codegenandcranelift-assembler-x64embed absolute filesystem paths into generated Rust source files. These paths change across different build environments (different machines, different--target-dirvalues, sandboxed build systems like Bazel or Nix), producing non-reproducible build artifacts.Status
cranelift-codegen: Fixed onmainby 0694bba38 ("Strip prefixes in file names"), which replacesOUT_DIRpaths with<OUT_DIR>in the ISLE-generated source. Sorry for the noise on this one — I was testing against v32.0.0 and missed that this was already fixed. I'll pick this up when the next release ships.
cranelift-assembler-x64: Still unfixed onmain. See details below.
cranelift-assembler-x64
cranelift/assembler-x64/build.rswrites absoluteOUT_DIRpaths directly intogenerated-files.rswith no attempt to relativize:for file in &built_files { writeln!(vec_of_built_files, " {:?}.into(),", file.display()).unwrap(); }\`built_files\` contains absolute paths derived from \`OUT_DIR\`, so \`generated-files.rs\` ends up with:
vec![ "/home/alice/wasmtime/target/debug/build/cranelift-assembler-x64-abc123/out/assembler.rs".into(), ]Verified still present on
main(d5f1b973e48b).Impact
- Standard Cargo builds: building on different machines, or with
--target-diroutside the workspace, produces different generated source and different final binaries- Sandboxed builds (Bazel, Nix, etc.): each build action runs in a unique sandbox directory, so every build produces a different binary even on the same machine with the same inputs
Reproducer
cd wasmtime CARGO_TARGET_DIR=/tmp/build1 cargo build -p cranelift-assembler-x64 CARGO_TARGET_DIR=/tmp/build2 cargo build -p cranelift-assembler-x64 # Different absolute paths in generated-files.rs: cat /tmp/build1/debug/build/cranelift-assembler-x64-*/out/generated-files.rs # vec![ # "/tmp/build1/debug/build/cranelift-assembler-x64-8eadefadaa0bb4cd/out/assembler.rs".into(), # ] cat /tmp/build2/debug/build/cranelift-assembler-x64-*/out/generated-files.rs # vec![ # "/tmp/build2/debug/build/cranelift-assembler-x64-8eadefadaa0bb4cd/out/assembler.rs".into(), # ]Environment
- Discovered building wasmtime 32.0.0 via Bazel (rules_rust) with sandboxed execution
- Also reproducible with standard Cargo using different
--target-dirvalues
travisdowns edited a comment on issue #13121:
On closer look,
generated-files.rsis only consumed by thecranelift-assembler-x64utility binary (main.rs), not the library. For a utility that prints paths to generated code, absolute paths are the right behavior — relative or placeholder paths would make the output less useful.It's possible to make the
generated-files.rssource itself deterministic (e.g. by usingenv!("OUT_DIR")to defer path resolution to compile time), but the binary would still contain the absolute path afterenv!()expansion, so the non-determinism just moves from the source file to the compiled output. Not much of a win.I think this issue can be closed — the
cranelift-codegenside was already fixed by 0694bba38, and thecranelift-assembler-x64side doesn't need fixing.Sorry for the noise!
Last updated: May 03 2026 at 22:13 UTC