Make rust reproducible!

Rust is not clean programming language:

[kreyren@leonid:~]$ cat shell.nix
# NixOS shell configuration to bootstrap the required dependencies
# NOTE(Krey): Uses mozilla's overlay, because nix's upstream is slow

	moz_overlay = import (builtins.fetchTarball;
	nixpkgs = import <nixpkgs> { overlays = [ moz_overlay ]; };
	with nixpkgs;
	stdenv.mkDerivation {
		name = "moz_overlay_shell";
		buildInputs = [
			# NOTE(Krey): Using nightly for 2021 edition

[nix-shell:/tmp]$ cd dirty-rust/

[nix-shell:/tmp/dirty-rust]$ for file in; do printf '%s\n' 'fn main() { println!("Hello, World!"); }' > "$file" && rustc "$file"; done

[nix-shell:/tmp/dirty-rust]$ sha256sum hello{1,2}
469e4a490b1e51356e8c23a3d3bfe72e9feb5cbef895c21f7add5b38ab95efcb  hello1
df0f08665258fc13c21e8b2ae28481d1c98aada9fc5920bb2d321bd307a9f3de  hello
[kreyren@leonid:/tmp/dirty-rust]$ nix-shell -p diffoscope --run "diffoscope hello{1,2}"

Which makes it unsuitable for mission critical development.


I am trying to define a framework for modular software development on rustlang by defining Kconfig-like handling for feature-gates that are reading a source-independent file governed by a written standard, but the rustc is making it impossible to develop a test for bit-by-bit cleaness to ensure that the feature gates are not included in assuming it being designed for mission-critical environment (aviation) to avoid random software failure by the feature gate influencing the runtime e.g. airspeed indicator to cause a low altitude aerodynamic stall in the worst case scenario in fly-by-wire aircraft.

Relevant: Creates unexpected dirty binaries · Issue #4 · reitermarkus/cargo-eval · GitHub


You can get reproducible builds by making the source filenames match and by using the --remap-path-prefix option to make the source paths map to the same thing. For example, this command:

for DIR in hello1 hello2; do \
    mkdir -p "$DIR"; \
    rm -f "$DIR/"; \
    echo 'fn main() { println!("hello") }' >"$DIR/"; \
    rustc --remap-path-prefix "$DIR=." "$DIR/" -o "$DIR/hello"; \
    md5sum "$DIR/hello"; \

Produces this output (using rustc 1.54.0 on Linux x86_64):

37dd3b6b9db6724d458ec8e74b90ea26  hello1/hello
37dd3b6b9db6724d458ec8e74b90ea26  hello2/hello

For more information, see:


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.