Unverified Commit e85060f5 authored by Bernardo Meurer Costa's avatar Bernardo Meurer Costa
Browse files

buildRustCrate: remap rustc store path to break rust-src closure leak

When the rust-src component is installed (common with rust-overlay
toolchains via rust-toolchain.toml), rustc unvirtualises libstd source
paths. Panic locations from monomorphised generic std code
(BTreeMap, VecDeque, sync primitives, etc.) then embed the toolchain
store path in .rodata, pulling the entire multi-GB toolchain into the
runtime closure.

This is not an RPATH issue — stdenv's patchelf --shrink-rpath already
cleans that. The reference is a core::panic::Location string.

Remap the rustc store path to /rustc so panic messages stay readable
but no longer create a store-path dependency. This is a no-op for
toolchains without rust-src (the prefix simply never matches).
parent 9a666592
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -31,6 +31,12 @@ let
    (if release then "-C opt-level=3" else "-C debuginfo=2")
    "-C codegen-units=${toString codegenUnits}"
    "--remap-path-prefix=$NIX_BUILD_TOP=/"
    # When the rust-src component is present (common with rust-overlay
    # toolchains), rustc unvirtualises libstd source paths. Panic
    # locations from monomorphised generic std code then embed the
    # toolchain store path in .rodata, pulling the entire toolchain into
    # the closure. Remap to a stable placeholder to break the reference.
    "--remap-path-prefix=${rustc}=/rustc"
    (mkRustcDepArgs dependencies crateRenames)
    (mkRustcFeatureArgs crateFeatures)
  ]