Cargo: Reproducible builds: Automatically remap $CARGO_HOME and $PWD

Created on 10 May 2018  路  8Comments  路  Source: rust-lang/cargo

As a followup of https://github.com/rust-lang/rust/issues/41555, I think $CARGO_HOME and $PWD (the location of the project) should be remapped to fixed values automatically.

I found both of those paths inside binaries and I have to add boilerplate to all of my [reprotest] scripts to normalize them.

The motivation behind this is that alice and bob can both download the same release of a rust project, cargo build --release it and end up with a 100% identical binary, given a sufficiently similar build environment (rustc version and system libraries).

A-reproducibility

Most helpful comment

The question is what to map the paths to. In Debian we install source code into /usr/share/cargo/registry but other systems might be different. Ideally we'd map it to a virtual path like $CARGO_REGISTRY and put the logic of "where is $CARGO_REGISTRY" into the system debugger itself.

All 8 comments

Thanks for the report! I think this is plausible to do but currently if done naively I think it would break all debugger integrations, so we probably don't want to do this until that's fixed.

Maybe we can do this only on release builds?

If we can solve the debug problem, yes we may be able to do it by default on release builds as well.

@alexcrichton debugging in rust depends on debug symbols, correct?

[profile.dev]
debug = true       # include debug information (debug symbols). Equivalent to
                   # `-C debuginfo=2` compiler flag.

couldn't we remap those paths if debug is set to false?

Perhaps, but I believe they still show up in panic paths

@alexcrichton Any additional colour on what could/would break wrt debuggers? I am somewhat surprised $PWD makes it into the binaries at all.

Edit:
When I run strings on a 1.29.2 release or debug binary, I don't see $PWD in there at all.

@mfarrugi debuggers use the paths in debuginfo (which don't show up in strings output) for setting breakpoints and showing code whiel you're stepping through code. Anything which references a registry crate has an absolute path and can be debugged by setting breakpoints on the file and such. Crates in the cwd, if referenced via an absolute path, are also loaded by the debugger and would break as $PWD/foo.rs doesn't actually exist

The question is what to map the paths to. In Debian we install source code into /usr/share/cargo/registry but other systems might be different. Ideally we'd map it to a virtual path like $CARGO_REGISTRY and put the logic of "where is $CARGO_REGISTRY" into the system debugger itself.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

oblique picture oblique  路  3Comments

sdroege picture sdroege  路  3Comments

fprijate picture fprijate  路  3Comments

rodoufu picture rodoufu  路  3Comments

JustAPerson picture JustAPerson  路  3Comments