-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No way to specify linker arguments via rustflags for dependency build scripts with --target
#13981
Comments
Should this be considered a duplicate of #4423? |
I found the section in Cargo book
Very likely |
@epage #4423 is a broad issue that is much more difficult to solve without introducing some major changes; would you consider entertaining a PR that forwarded rustflags to build scripts specifically and only for the case where host triple == explicit target triple? That would make |
Sounds like what you are describing is target-applies-to-host |
If I've understood that link correctly, what I want is actually the opposite of that, as It does seem that For context, I am on a no-longer-supported OS X version for $reasons, and since std now assumes that methods like For normal builds, merely setting For further context, the issue is with "packaged" rust projects that cannot be installed normally via But the problem is obviously more general than that; the root problem is a general conflation of host and target systems for RUSTFLAGS and the "workaround" here was to completely ignore RUSTFLAGS for build scripts when So again, my suggestion would be that today a PR to patch |
This might break existing builds, for example, when using address sanitizer. |
Interesting case, I confess I didn't consider it... but I'm not sure it's so cut and dry. I set up the ASAN CI profile for fish, and so speaking from experience, I can imagine scenarios where passing RUSTFLAGS to build scripts could both break or actually be required for the correct application of ASAN. It's easy to see why you wouldn't want your build script to be run under ASAN (it'll mess with its output and you might have memory leaks that trigger an ASAN abort causing your builds to fail, among others) but there are also inverse cases (though I think they would tend to be non-idiomatic). CFLAGS is passed to build.rs and that's how you can usually get |
Is RUSTFLAGS currently not forwarded both when building |
It depends on how you configure it. Cargo does respect When running a build script, Cargo sets
|
@weihanglo sorry, I meant specifically in the explicit |
While compiling the build script itself wouldn't. |
Problem
Background, but note that I already know how to work around this for me but am posting for want of a more general solution: I'm using rust on an unsupported macOS target (toolchain installed with
macports
) for $reasons. Due to missing system symbols like_getentropy()
and_clock_gettime
, the rust toolchain is built additionally linked against/opt/local/lib/libMacportsLegacySystem.B.dylib
which provides these symbols that the standard library now uses since support for older macOS releases was removed.Compiling a project with transitive dependencies that use std functionality that pulls in a reference to these symbols requires that the cargo be executed as
env RUSTFLAGS='-Clink-args=-Wl,/opt/local/lib/libMacportsLegacySystem.B.dylib' cargo build
and works great. No problems.However, due to the logic that cargo uses internally to determine when and where rustflags are forwarded to
rustc
, this does not work if cargo is executed with an explicit--target
, even when the target matches the host (e.g.x86_64-apple-darwin
in this case).I have tried the following methods:
env RUSTFLAGS='...' cargo build --target x86_64-apple-darwin
env CARGO_BUILD_RUSTFLAGS='...' cargo build --target x86_64-apple-darwin
env CARGO_TARGET_X86_64_APPLE_DARWIN_RUSTFLAGS='...' cargo build --target x86_64-apple-darwin
target.x86_64-apple-darwin.rustflags
in a newly created.config/cargo.toml
(to emphasize that there was no previous such file masking the above)In all these cases, the provided rust flags are not passed when the linker is invoked in dependency builds (e.g.
pcre2-sys
fails to compile with errors about a missing_getentropy()
symbol).Debugging with
env CARGO_LOG=trace
reveals that the flags are picked up, and they're even used for some of therustc
invocations, but critically, they're ignored when it comes to build scripts (which is predominantly where external linker invocations will come in).I can understand why "normal" RUSTFLAGS are not forwarded to all rustc invocations when
--target
is used, but I would proffer that the specific combination ofCARGO_TARGET_<TRIPLE>_RUSTFLAGS
with a matching--target <triple>
should be forwarded the same way that RUSTFLAGS is when no--target
is passed. (Note here that the project builds successfully when usingRUSTFLAGS
and no--target
, with the correct-Clink-args
being forwarded throughout.)Note also that I am requesting that a solution be possible via the usage of environment variables only, without needing to specify any values in
.cargo/config.toml
so that this can be used in external build systems. (Indeed, the problem here is that I am callingcargo
from a build system that determines the target and always passes--target <triple>
tocargo
.)(For the record, I am not reporting this as a "I can't build on this unsupported platform" bug but rather as a "there doesn't seem to be any way to influence the linker behavior of all transitive dependencies in one go with an environment variable" issue only when building for a specific
--target
triple.)cc #9743, which identified the issue but ended up being treated as a symptom of the OP's problem rather than the problem itself, and was closed accordingly.
Steps
No response
Possible Solution(s)
CARGO_TARGET_<TRIPLE>_RUSTFLAGS
to build scripts when an explicitly provided, matchingcargo build --target triple
is used-Clink-args
and other-Clink...
flags and pass those to build scripts where currently no rustflags are forwardedNotes
No response
Version
The text was updated successfully, but these errors were encountered: