When compiling a rust program, and inspecting the resulting binary, I can see paths of the form $HOME/.cargo/registry/...
embedded inside.
cargo init --bin
regex = "1"
use regex::Regex;
fn main() {
Regex::new(r"{").unwrap();
}
cargo build --release
strings target/release/<name> | grep registry
to inspect the binary.Note that the crate and code example is completely arbitrary — the same behavior occurs with any combination of crates.
Software versions:
That's part of the debug/unwind info. You can map it to a different path via #41555 or remove it by stripping the resulting binary.
I ran strip
on the binary, but the paths appear to remain.
I was looking at this same problem yesterday. I can confirm stripping (either with strip
or with the nightly rustc stripping feature) does not remove the paths.
I have just found (thanks to folks on IRC) there's a rustc
flag that might help. Try to build with:
RUSTFLAGS='--remap-path-prefix foo=bar' cargo build
Reference
https://doc.rust-lang.org/rustc/command-line-arguments.html#--remap-path-prefix-remap-source-names-in-output
--remap-path-prefix
can mask the paths, but does not completely remove them. Additionally, this feature requires manually specifying the path prefix to use, which makes it more complicated to use.
There's also this: Remove panic string formatting, but it requires Xargo.
@danielhuang yes, I'm aware this does not solve the problem entirely and has the problems you mentioned. My comment was more of a workaround to solve part of the problem.
but does not completely remove them
--remap-path-prefix
exists to give users means to achieve reproducibility.
Given that there are quite many ways to eventually have file!
and similar macros invoked (including, but not limited to, panic machinery), I'm not exactly sure where the bug is.
Can you elaborate what exactly you expect the behaviour to be?
I want to remove all debug-related information from the binary when compiling in release mode.
Could someone label this A-reproducibility
?
Most helpful comment
I want to remove all debug-related information from the binary when compiling in release mode.