soroban-cli
soroban-cli copied to clipboard
Strip absolute local paths from binaries
What problem does your feature solve?
For builds to be reproducible, the binaries cannot contain absolute filesystem paths. Today there are cases where rustc embeds absolute paths even when debuginfo is stripped.
Namely, panic messages emit paths via the builtin file! macro. In some cases these paths are relative (the local project, the prebuilt standard library); but in some they are absolute (crates.io dependencies, the standard library built from source).
So e.g. today the eth_abi example crate includes absolute paths for the soroban-sdk crate and the alloy-sol-types crate because it calls functions in these crates that in turn may panic.
Soroban probably doesn't care about these paths at all - I don't know if they make it all the way to soroban's own panic logging; and they increase wasm size.
What would you like to see?
Soroban-cli should invoke the compiler in a way that eliminates these absolute paths.
The main mechanism for doing this is the --remap-path-prefix flag to rustc.
There are more sophisticated mechanisms for controlling these paths in cargo via `trim-paths but they are unstable.
The linked trim-paths docs describe which paths cargo tells rustc to sanitize, and soroban-cli can do the same. The path to the local registry cache is the most important; the path to the local standard library also may be useful to remap.
The following patch to contract/build.rs is a working proof of concept for remapping the registry path:
+ {
+ assert!(std::env::var("RUSTFLAGS") == Err(std::env::VarError::NotPresent));
+ let cargo_home = home::cargo_home().map_err(Error::CargoHome)?;
+ let cargo_home = format!("{}", cargo_home.display());
+ let registry_prefix = format!("{cargo_home}/registry/src/");
+ let rustflags = format!("--remap-path-prefix={registry_prefix}=");
+ cmd.env("RUSTFLAGS", rustflags);
+ }
Unfortunately it seems like this must be done through the RUSTFLAGS variable, which adds some complications if the caller is also using it.
What alternatives are there?
Discussed above.