Expand description
RUSTC_WRAPPER shim that restores absolute paths in SBF DWARF output.
§Problem
The Solana toolchain’s cargo passes -Zremap-cwd-prefix= (empty
replacement) to rustc for every SBF crate. This strips DW_AT_comp_dir
from the DWARF, making all source paths relative. When multiple crates
share filenames like src/lib.rs, the debugger can’t tell them apart
and may show source from the wrong crate.
§Solution
anchor debugger sets RUSTC_WRAPPER to the anchor binary itself.
Cargo then invokes anchor <real-rustc> <args...> for every rustc
call. This module detects that invocation pattern (the env var
__ANCHOR_RUSTC_WRAPPER=1 disambiguates from normal CLI usage) and
replaces -Zremap-cwd-prefix= with -Zremap-cwd-prefix=$CWD,
preserving absolute paths in the debug info.
The sentinel env var is necessary because RUSTC_WRAPPER mode passes
a path as argv[1] (the real rustc binary), which clap would reject as
an unknown subcommand. The check in main.rs runs before clap
parsing so the process never hits the normal CLI dispatch.
§Performance
The wrapper adds ~1ms of fork+exec overhead per rustc invocation. This is negligible compared to actual compilation time.
Constants§
- WRAPPER_
SENTINEL - Env var set by
anchor debuggerbefore callingcargo build-sbf. When present, the process knows it was invoked as a RUSTC_WRAPPER and should rewrite args instead of running the normal CLI.
Functions§
- maybe_
exec_ as_ wrapper - If we’re running as a RUSTC_WRAPPER (sentinel env var is set), rewrite the rustc args and exec the real compiler. Never returns.