Open konstin opened 3 months ago
I had a hunch that this might be related to #13257, which landed in Rust 1.77.0.
Trying with Rust 1.76.0
it doesn't reproduce:
$ ./compile.sh
Release: 400608
strip=symbols: 313936
strip=debuginfo: 368304
strip = true: 313936
But with 1.77.0
it does:
$ ./compile.sh
Release: 367968
strip=symbols: 367968
strip=debuginfo: 367968
strip = true: 313968
So it does seem like #13257 could be the cause?
I'm presuming the command passed to rustc ends up being -C strip=symbols -C strip=debuginfo
(or similar) and thus the strip mode gets overridden?
I'm presuming the command passed to rustc ends up being
-C strip=symbols -C strip=debuginfo
(or similar) and thus the strip mode gets overridden?
Yeah your observation is correct. It's about precedence.
cargo rustc
are appended here-C strip
from profile.strip
is set later here.I have no idea why rustflags from cargo rustc
got such a lower precendence. Every change in rustc invocation from Cargo may break the usage of it. Also, the precedence is not well-documented.
I am not sure how to document the behavior. Adding rustflags is usually a lower level thing, and the same regression might happen again for other kind of rustflags. Generally using [profile]
is recommended if a rustflag is already control over profiles.
Another approach is we move cargo rustc -- <rustflags>
to one line below:
It has less impact to the precedence of other user-overridable rustflags (build.rustflags
and RUSTFLAGS
). I am not 100% sure about the implication and impact though.
Hmm, I didn't think of that. Yeah, this is tricky, but it also happens with other rustc flags set by Cargo, it just didn't happen for split
specifically before 1.77.
If you use the CARGO_<PROFILE>_STRIP
env. var. or just use RUSTFLAGS
, it should work, however as @weihanglo said, cargo rustc
flags have low priority. It seems to me like that is a very unexpected behavior, as cargo rustc
is specifically designed to have control over how exactly is rustc
invoked, and it is thus quite unintuitive that flags passed after cargo rustc
have lower priority than flags passed by Cargo - that essentially makes these flags useless, and does not allow overriding the behavior of Cargo.
@weihanglo I think that it would make sense to raise the priority of the cargo rustc
passed flags. What process should be used to achieve that? :) (RFC/PR/Zulip issue?)
I have already put this on the Cargo triage agenda, but I was out for family issues for the past two weeks. A zulip thread sounds good to me as a start
Awesome, thanks!
This is kinda accepted with some requirements:
Re-opened to track the stabilization of #14587.
In case of the new precedence start blocking your builds, please let us know and use __CARGO_RUSTC_ORIG_ARGS_PRIO=1
to restore to the original precedence.
Original issue title:
-C strip=symbols
doesn't work likestrip = true
Problem
Reproducer: https://github.com/konstin/strip-reproducer/blob/main/compile.sh
With the default linker on linux, passing
-C link-arg=-s
,-C strip=symbols
and-C strip=debuginfo
tocargo rustc
all don't strip the binary properly as settingstrip = true
does, even though the docs say "The strip option controls the -C strip flag".In maturin we expose a
--strip
option, since small size is important for publishing. We pass this on tocargo rustc
, historically with-C link-arg=-s
, but i also tried with-C strip=symbols
. This does strip some debuginfo, 40MB -> 37MB in the case of uv, but not down to 30MB for the fully stripped binary (https://github.com/astral-sh/uv/issues/5683). In the minimal reproducer, onlystrip = true
shows any effect.Note that this only happens with the default linker, mold strips properly in both cases.
Steps
https://github.com/konstin/strip-reproducer/blob/main/compile.sh
Create a new project with
cargo new strip-reproducer
, then run:Possible Solution(s)
There should ideally be a cli option to strip like
strip = true
does, or the docs should be adjusted on the differences betweenstrip = true
and the-C
options.Notes
No response
Version