-
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
Allow linker override specifically for build scripts and proc macros #14105
Comments
Could you provide reproduction steps to remove any chance of misunderstanding in what you are running into? if I understand correctly, instead of saying Also, if I'm understanding correctly, we have no mechanism to set the linker, so in the end, this is about setting |
Steps to reproduce:
Admittedly this is a bit of a cursed setup |
So you are using #4423 is about something similar (RUSTFLAGS for build scripts) but specifically mentions that RUSTFLAGS is only applied to the platform-target builds and not the host-target builds. So how are your host-target builds using GCC 12? I wonder if rustc is using a system linker and somehow GCC 12 is being treated as the system linker. If so, then likely the core of your problem is a system configuration problem, rather than #4423. if somehow that can't be addressed and can only be solved in Cargo, then this is another version of #4423. Closing in favor of that. If there is a reason for us to keep this open separately, let us know! |
Well my issue boils down to the fact that when target and host have the same triple, the target linker is used for build scripts, which only happens in this case. In a sense, this is the opposite of #4423? As, if I understand correctly, #4423 is about adding flags to build script compilation, and I want to remove some? Unless I did not read the issue far enough. Someone also made the point in that thread that "cross compiling for the host triple and compiling natively is basically the same thing", which I would argue against... |
I found an issue on the rust forums with the same problem that might be clearer as to what the issue actually is: https://users.rust-lang.org/t/same-arch-cross-compile-linker-mixup/82337 |
Problem
When cross compiling for a target that has the same architecture as the host, the build scripts and proc macros are compiled with the target linker. However, those builds are not meant to be run on the target!
In my use case, I was building on an x86_64-unknown-linux-gnu host with glibc 2.31, and the target environment was x86_64-unknown-linux-gnu with glibc 2.38, and a specific linker for this target.
The build scripts and proc macros were failing with dynamic linking errors, saying they couldn't find the correct libc version, because they had been linked with the target linker, not the host linker.
Proposed Solution
Allow the user to specify if they want to build the build scripts / proc macros with a different linker or not.
Notes
As a workaround, I used this rustc wrapper script, that will remove the
-C linker=...
arguments if the crate name isbuild_script_build
, or the crate type isproc-macro
The text was updated successfully, but these errors were encountered: