-
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
Configure hosts separately from targets when --target is specified. #9322
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @ehuss (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
4875137
to
60f721b
Compare
83b5f50
to
1597f84
Compare
One quick bit of feedback: I don't think this should just be If there's something that really does apply to all hosts, it could use |
I don't see a realistic use case for having host target triples since each build host should only need one host configuration for all targets as the build scripts must run on the build host and shouldn't change depending on targets, using target triples here seems to complicate things unnecessarily. |
@jameshilliard I have several use cases for that. Projects often check in |
Thanks for the PR @jameshilliard! We talked about this in the Cargo meeting today for quite awhile and I'm going to try to summarize our thoughts all down in writing. As you've discovered this is a particularly large thorn in Cargo's side, and it's been there for quite some time! Overall we generally favored this design, but one thing we're worried about is backwards compatibility. This will break any usage of The changes we were thinking for this PR are:
How does that sound? This is definitely a more long-term plan to get this fixed but the hope is that we can do this with minimal breakage and if something breaks there's recourse for users to fix it. Additionally I think this should fix all if not almost all of the issue about The points about "fixing" |
I think this is unnecessarily complex, these host config flag settings aren't exactly portable in most cases so having multiple sections for different host build script targets doesn't appear to be useful.
This should behave as before as long as one doesn't manually set the target(which one generally only does when cross compiling AFAIK). The only thing I could see this breaking are some obscure edge-cases(obscure enough they aren't even tested for) where one is manually setting a target that also needs custom flags for the build script(most of the time build scripts don't need custom flags so this generally shouldn't cause any issues).
Well it doesn't exactly unconditionally default to
I really don't think this is a good idea, currently the behavior of cargo arbitrarily applying target configurations to host scripts is objectively wrong but only breaks in a fatal way for specific configurations, and by providing a host table we ensure that in the rare case build scripts need custom flags that there is a way for them to be provided still. Since this change should not break any common use cases I think we should just default to doing the sane thing and not apply target flags to build scripts except in cases where the host is the target(target not set).
While this does change a default it doesn't appear likely to cause significant breakage, and with a
I'm not really seeing a scenario that's not covered by my approach, is there some use case I've missed here? |
Do you have an example of what one of those checked in cargo configs would look like? I'd like to see one that this change would break ideally. Custom build script flags tied to the host architecture just seems like a bad idea for multiple reasons, it means the build output gets affected by both the build host as well as the target which I don't see as desirable in general. Normally the build output should only be affected by the target settings, the main use case for the |
I have done a lot of "complicated" criss-crossed compilation--mostly in the world of C/C++--and am one of the people who has been long affected by this Cargo issue, whilst slowly drowning in failing workarounds ;P, and I am also not sure I see the use case for host-triple specific build rules? The only thing I ever feel I need to pass that is special on the host is super high-level language confirmation flags (the only one I can think of being -std=, but I could see a use case for -funsigned-char). I generally just need my host compiler to "work at all", not be configured in some extra special way (and I thereby try to get away if at all possible with just running "cc" and passing -I/c/o, though in practice I often "care" a bit and run "gcc" or even "clang"). It could be that people are doing something very different in Rust-land with their host build steps, or there is an entire level of complexity far past where I have ever gone? |
@jameshilliard
Also, to clarify, I don't object to having |
@joshtriplett The first and third bullets don't actually seem like they should be checked in as files to your project as part of your cargo configuration, as that is probably going to make them attempt to get applied to a build of your project even if you are just some embedded dependency; at a "high-level", I'd argue that the person doing the build should get to make these determinations if at all possible, as these are both like, toolchain issues and not target issues. Like, to the extent to which there are faster ways of doing these builds, shouldn't that just be defaults built into cargo, or decisions made by the system toolchain distributor? (I'd even argue that is mostly true of the second one as well, though I can appreciate some stored guidance on math flags or something, but even there I find it a bit sketchy and I'm highly concerned that projects using it will become hard for me to compile.) |
Update cargo 10 commits in e931e4796b61de593aa1097649445e535c9c7ee0..0cecbd67323ca14a7eb6505900d0d7307b00355b 2021-05-24 16:17:27 +0000 to 2021-06-01 20:09:13 +0000 - Configure hosts separately from targets when --target is specified. (rust-lang/cargo#9322) - Add some validation to rustc-link-arg (rust-lang/cargo#9523) - Implement suggestions for unknown features in workspace (rust-lang/cargo#9420) - Extract common `make_dep_path` to cargo_util (rust-lang/cargo#9529) - Add a note about rustflags compatibility. (rust-lang/cargo#9524) - Consolidate doc collision detection. (rust-lang/cargo#9526) - Add `--depth` option for `cargo-tree` (rust-lang/cargo#9499) - `cargo tree -e no-proc-macro` to hide procedural macro dependencies (rust-lang/cargo#9488) - Update to semver 1.0.0 (rust-lang/cargo#9508) - Update tar dependency to 0.4.35 (rust-lang/cargo#9517)
To fix this bug we have to use an undocumented test variable to enable the nightly target-applies-to-host feature so that the target linker doesn't get used for host binaries like the build-script. Fixes: error: failed to run custom build command for `ripgrep v0.8.1 (/home/buildroot/buildroot/output/build/ripgrep-0.8.1)` Caused by: process didn't exit successfully: `/home/buildroot/buildroot/output/build/ripgrep-0.8.1/target/release/build/ripgrep-59eeb7069534e1ef/build-script-build` (exit status: 1) --- stderr /home/buildroot/buildroot/output/build/ripgrep-0.8.1/target/release/build/ripgrep-59eeb7069534e1ef/build-script-build: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found (required by /home/buildroot/buildroot/output/build/ripgrep-0.8.1/target/release/build/ripgrep-59eeb7069534e1ef/build-script-build) Details: rust-lang/cargo#3349 rust-lang/cargo#9322 Signed-off-by: James Hilliard <[email protected]> Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <[email protected]>
Hello, I am currently facing this issue with target==host==x86_64. Cargo version is 1.75. Is this version has the fix? I tried with following settings in the config.toml, but I don't see it taking effect: [host] |
@vithalsm, it is behind some Z flags. See https://doc.rust-lang.org/cargo/reference/unstable.html#host-config |
Yes but it's a bit annoying to enable since for unclear reasons #9753 has yet to be merged, for buildroot we use these env variables. |
Thanks for the pointers. However -Z expects cargo from 'nightly' channel or use the env variables as being used by buildroot. Using nightly is not feasible for us, so will try with env variables. But, would it be possible to merge and make the options available regular stable release please? That will be very helpful for many |
This prevents target configs from accidentally being picked up when cross compiling from hosts that have the same architecture as their targets.
closes #3349