-
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
Remove requirement for --target when invoking Cargo with -Zbuild-std #14317
Remove requirement for --target when invoking Cargo with -Zbuild-std #14317
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) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
@@ -97,11 +97,6 @@ impl BuildConfig { | |||
}, | |||
}; | |||
|
|||
if gctx.cli_unstable().build_std.is_some() && requested_kinds[0].is_host() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add some build-std
tests for relying on host target?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might not be easy to set up though. Maybe we can only do this on certain platforms like x86_64 linux.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ehuss I meant this but now it seems to be a separate issue so you're right.
Lines 235 to 240 in a7c4206
// Fixing rust-lang/rust#117839. | |
// on macOS it never gets remapped. | |
// Might be a separate issue, so only run on Linux. | |
#[cargo_test(build_std_real)] | |
#[cfg(target_os = "linux")] | |
fn remap_path_scope() { |
Yea, I'd like to see some tests added. There is a dedicated build-std suite that would be appropriate for this. Testing proc-macros is the most important part, and including shared dependencies I think will also be important. Also, the documentation will need updating, too. I'm not sure what @weihanglo means by only working on certain platforms. This should work on all host platforms that we test with. One key difference of how cargo works today versus when this was written is that cargo now defaults to "cross compile mode", and then has a separate pass which unifies things when building in "host only" mode. Because the host dependencies will not be wired up to the std dependencies, that means they essentially get forked and built twice. Overall that seems like it should work, though I'm still uncertain about RUSTFLAGS compatibility. This may complicate rust-lang/wg-cargo-std-aware#31, since cargo would need to be careful about how it disables the sysroot. But overall I think it should be workable. |
Thanks @ehuss. Could you clarify what you mean relating to the disable sysroot issue? |
rust-lang/wg-cargo-std-aware#31 is recommending to add a flag to rustc to disable sysroot lookups. Cargo would pass that flag when using build-std to ensure that rustc does not ever attempt to load crates from the sysroot (to avoid various weird errors). With the change in this PR, proc-macros and build scripts will start using the standard library from the sysroot. We will need some way to tell cargo to not pass that flag for host crates. That may be complicated due to the way That seems like something we can deal with in the future, though. |
I think this is already the case. It looks like cargo assumes, for the purpose of build dependencies, that artifact deps can execute on the host when a Even though they technically can, I don't think build scripts using --extern std in host mode is even any better since right now building and running build scripts doesn't depend on building std. I think this would just slow down builds. |
There is no longer a need for the --target to be specified in every case when using -Zbuild-std. Cargo will default to the Host CompileKind when no --target is specified.
c3edeff
to
388bceb
Compare
Add a new test case for building a crate with -Zbuild-std, without the requirement for the --target flag, and that uses a proc_macro.
Add a test case which ensures that -Zbuild-std without --target correctly handles building a crate that has a shared dependency between it's own build script, and std.
388bceb
to
5a66672
Compare
@ehuss & @weihanglo , have you had a chance to look at the updated changes? Thanks! |
Thanks, sorry for the delay! I'm not fully confident this won't unearth some issues since there are a lot of subtle interactions (like the RUSTFLAGS thing I mentioned above). However, I can't think of anything specific that will be a problem. Really appreciate you helping with this! @bors r+ |
☀️ Test successful - checks-actions |
Update cargo 18 commits in e75214ea4936d2f2c909a71a1237042cc0e14b07..0310497822a7a673a330a5dd068b7aaa579a265e 2024-10-25 16:34:32 +0000 to 2024-11-01 19:27:56 +0000 - Add more metadata to `rustc_fingerprint` (rust-lang/cargo#14761) - test(rustfix): switch to a simpler case for dedup-suggestions (rust-lang/cargo#14765) - chore(deps): update rust crate security-framework to v3 (rust-lang/cargo#14766) - chore(deps): update rust crate gix to 0.67.0 (rust-lang/cargo#14762) - fix(util): Respect all `..`s in `normalize_path` (rust-lang/cargo#14750) - test(doc): Resolve flaky test (rust-lang/cargo#14760) - refactor(test): Remove dead 'expect_stdout_contains_n' check (rust-lang/cargo#14759) - add unstable -Zroot-dir flag to configure the path from which rustc should be invoked (rust-lang/cargo#14752) - docs(resolver): Further v3 prep (rust-lang/cargo#14753) - fix: track version in fingerprint dep-info files (rust-lang/cargo#14751) - test: Remove unused msrv-policy (rust-lang/cargo#14748) - download targeted transitive deps of with artifact deps' target platform (rust-lang/cargo#14723) - Remove requirement for --target when invoking Cargo with -Zbuild-std (rust-lang/cargo#14317) - docs(fingerprint): document the encoding of Cargo's depinfo (rust-lang/cargo#14745) - Allow build scripts to report error messages through `cargo::error` (rust-lang/cargo#14743) - fix(publish): Downgrade version-exists error to warning on dry-run (rust-lang/cargo#14742) - fix: clean up for deprecated and removed commands (rust-lang/cargo#14739) - Deprecate `cargo verify-project` (rust-lang/cargo#14736)
This PR addresses this issue re: build-std stabilization. We believe the requirement for --target to be specified when invoking cargo with -Zbuild-std, from our testing, is no longer needed. Now, with this change, by default Cargo will use the Host CompileKind, rather than a manually specified CompileTarget. We propose removing this restriction in order to test this more widely. Our own testing is detailed below.
This change has been tested in the following manner:
-Zsanitizer=cfi
,-Cembed-bitcode=yes
,-Cforce-frame-pointers
,-Cforce-unwind-tables=yes
,-Csoft-float=yes
,-Zbranch-protection=pac-ret
.