-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
-C link-arg is being ignored... maybe just in this specific case? #9089
Comments
It seems to fail for me:
Can you post the full output, particularly the line staring with |
@ehuss That's a different crate... I appreciate that the build fails much later, when building the challenge_bypass_ristretto_ffi crate; but it should have already failed when building the build_script_main crate from typenum. I can provide a more complex scenario to show you why this matters, but it would involve you installing another copy of clang (specifically, the r22 build of the Android NDK). Essentially, you are just checking to see "does the command eventually fail?", but I'm carefully passing -j1 and clipping the output to show the specific case that is being handled incorrectly: compiling typenum. |
@ehuss OK, so it hadn't really occurred to me to figure out how to compile just typenum before, but I found that package and can provide you a demonstration of the issue that doesn't rely on reading the output (so you can just check error codes). Setup:
This should fail, but doesn't:
To demonstrate that it is, in fact, linking something (and should fail), here is a demonstration of it running the linker:
I don't really understand anything at all about what Cargo is trying to do here, but I will note that by like, pattern analysis, the -C link-arg= doesn't seem to be being passed to that build_script_main invocation of rustc (and if I run it manually and pass it through myself the build then, correctly, fails). |
FWIW, I would have been willing to believe that I should instead be using CARGO_BUILD_RUSTFLAGS--though, I'd argue that that is confusing, given that it is using CARGO_TARGET_..._LINKER, and so I'd expect the semantics to match--but that also doesn't work... even RUSTFLAGS (which I would have expected to be used unconditionally) doesn't work :(. |
RUSTFLAGS are not passed to build scripts if you use the |
@ehuss My CARGO_TARGET_..._LINKER is "/path/to/a/special/clang" and I need to (minimally) pass "-fuse-ld=/usr/bin/ld" to make that copy of clang build things that run on x86_64-apple-darwin (I also should want to configure its sysroot and some paths, but I think it will at least work--if sort of wrongly--without those). If I don't pass -fuse-ld=, it doesn't link. The entire point of my passing extra link arguments is because I am saying "to compile for x86_64-apple-darwin, you need to pass these extra arguments" and I guess Cargo is deciding "well, except for build scripts, right?" and I'm saying "no: it doesn't matter what you are compiling... I am saying that if you want to compile for x86_64-apple-darwin, I need you to add these link arguments". I would agree that it usually wouldn't be necessary, as most people just use default compilers, but "in general" it certainly would be necessary, as the entire point of me being able to override the linker is to do something special. |
FWIW, if you wanted to be more consistent about it (in an attempt to make building build scripts be unrelated to building for a target), then just don't use |
Ah, I see. I didn't realize that the LINKER applied to build scripts, that sounds like possibly a bug. I think an issue is that it is somewhat rare to use Regardless, support for passing RUSTFLAGS to build scripts is tracked in #4423. There unfortunately isn't great support for controlling exactly where RUSTFLAGS gets applied. |
Possible fix in #9322. |
I'm on macOS (64-bit 10.14.6, if you care) and I'm compiling to x86_64-apple-darwin. I'm trying (and very much failing) to use CARGO_TARGET_X86_64_APPLE_DARWIN_RUSTFLAGS to set -C link-arg= to something I need to be passed to the compiler for it to choose the correct linker (I'm using a version of clang that selects its own version of ld unless I override it to Apple's ld64 with -fuse-ld=/usr/bin/ld). While CARGO_TARGET_X86_64_APPLE_DARWIN_LINKER does seem to override the linker, and while I know my rustflags are at least being parsed (as if I try to -C something invalid it throws an immediate error), -C link-args is being ignored, which makes me sad :(. (FWIW, using bare RUSTFLAGS doesn't seem to help.)
Here is the repository I happen to be working with:
This should fail with an error on --invalid from clang:
I know the triple and CARGO_TARGET_* are "in play":
The text was updated successfully, but these errors were encountered: