Skip to content
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

Always set the deployment target when building std #133092

Merged
merged 6 commits into from
Feb 10, 2025

Conversation

madsmtm
Copy link
Contributor

@madsmtm madsmtm commented Nov 16, 2024

cc has a bug/feature (I guess depending on how you look at it) where the default deployment target is taken from the SDK instead of from rustc. This causes compiler-builtins to build compiler-rt with the wrong deployment target on iOS.

I've been meaning to change how cc works in this regard, but that's a lengthy process, so let's fix it in bootstrap for now.

The behaviour can be seen locally with ./x build library --set build.optimized-compiler-builtins=true for various target triples, and then inspecting with otool -l build/host/stage1/lib/rustlib/*/lib/libcompiler_builtins-*.rlib | rg 'minos|version'. I have added a rmake test that ensures that we now have the same version everywhere.

Fixes #128419
Fixes rust-lang/compiler-builtins#650
Fixes #136523
See also rust-lang/cargo#13115, rust-lang/cc-rs#1171, #136113
See #133092 (comment) for a description of how the change works.

try-job: i686-gnu-1
try-job: i686-gnu-2
try-job: x86_64-apple-1
try-job: aarch64-apple
try-job: dist-apple-various
try-job: dist-aarch64-apple
try-job: dist-various-2
try-job: x86_64-fuchsia

@rustbot
Copy link
Collaborator

rustbot commented Nov 16, 2024

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) O-apple Operating system: Apple (macOS, iOS, tvOS, visionOS, watchOS) labels Nov 16, 2024
@madsmtm madsmtm force-pushed the bootstrap-deployment-target branch from fd382a0 to dd8ca01 Compare November 16, 2024 05:34
@madsmtm
Copy link
Contributor Author

madsmtm commented Nov 16, 2024

Okay... So this didn't actually work initially, since bootstrap is for some godforsaken reason calling cc to get default flags, and then later passing passing them to Cargo, which invokes the build script, which calls cc again to get default flags... So all the build flags end up getting duplicated (!), and the values in CFLAGS that were looked up previously end up being prioritized.

I've rebased and fixed that in the first and second commits, but it may break more than I think, so this should probably get a try build before merging.

@madsmtm madsmtm force-pushed the bootstrap-deployment-target branch 3 times, most recently from 50812ff to 2294b05 Compare November 16, 2024 06:55
@rustbot rustbot added the A-run-make Area: port run-make Makefiles to rmake.rs label Nov 16, 2024
@madsmtm madsmtm force-pushed the bootstrap-deployment-target branch from 2294b05 to f816d33 Compare November 16, 2024 07:05
@madsmtm madsmtm marked this pull request as ready for review November 16, 2024 07:19
@rustbot
Copy link
Collaborator

rustbot commented Nov 16, 2024

This PR changes how LLVM is built. Consider updating src/bootstrap/download-ci-llvm-stamp.

This PR modifies tests/run-make/. If this PR is trying to port a Makefile
run-make test to use rmake.rs, please update the
run-make port tracking issue
so we can track our progress. You can either modify the tracking issue
directly, or you can comment on the tracking issue and link this PR.

cc @jieyouxu

@madsmtm
Copy link
Contributor Author

madsmtm commented Nov 16, 2024

This PR changes how LLVM is built. Consider updating src/bootstrap/download-ci-llvm-stamp.

Not sure if I should? It changes in theory (we pass different flags), but in practice it shouldn't (because those flags were already set by cmake-rs, so they were just duplicated)?

@Mark-Simulacrum
Copy link
Member

r=me modulo comment

@Mark-Simulacrum
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Nov 28, 2024

📌 Commit ff3dab4 has been approved by Mark-Simulacrum

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 28, 2024
Zalathar added a commit to Zalathar/rust that referenced this pull request Nov 29, 2024
…t, r=Mark-Simulacrum

Always set the deployment target when building std

`cc` has [a bug/feature](rust-lang/cc-rs#1171) (I guess depending on how you look at it) where the default deployment target is taken from the SDK instead of from `rustc`. This causes `compiler-builtins` to build `compiler-rt` with the wrong deployment target on iOS.

I've been meaning to change how `cc` works in this regard, but that's a lengthy process, so let's fix it in bootstrap for now.

The behaviour be seen locally with `./x build library --set build.optimized-compiler-builtins=true` for various target triples, and then inspecting with `otool -l build/host/stage1/lib/rustlib/*/lib/libcompiler_builtins-*.rlib | rg 'minos|version'`. I have added a rmake test that ensures that we now have the same version everywhere.

Fixes rust-lang#128419
Fixes rust-lang/compiler-builtins#650
See also rust-lang/cargo#13115

`@rustbot` label O-apple
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 29, 2024
Rollup of 7 pull requests

Successful merges:

 - rust-lang#131323 (Support `clobber_abi` in AVR inline assembly)
 - rust-lang#133092 (Always set the deployment target when building std)
 - rust-lang#133134 (Don't use a SyntheticProvider for literally every type)
 - rust-lang#133538 (Better diagnostic for fn items in variadic functions)
 - rust-lang#133590 (Rename `-Zparse-only`)
 - rust-lang#133592 (Misc: better instructions for envrc, ignore `/build` instead of `build/`)
 - rust-lang#133608 (Revert rust-lang#133418 (Store coverage source regions as `Span`) due to regression rust-lang#133606)

r? `@ghost`
`@rustbot` modify labels: rollup
@Zalathar
Copy link
Contributor

Could this have caused the failure at #133609 (comment)?

@jieyouxu
Copy link
Member

This looks most likely I agree.
@bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 29, 2024
@workingjubilee
Copy link
Member

Yeaaah, I don't think that's spurious.

@jieyouxu
Copy link
Member

jieyouxu commented Feb 10, 2025

Oh fuchsia... If you'd like help w/ that target, we can ping the fuchsia team.

@madsmtm
Copy link
Contributor Author

madsmtm commented Feb 10, 2025

I'll try to take a look myself first

@madsmtm
Copy link
Contributor Author

madsmtm commented Feb 10, 2025

Pretty sure I've fixed this now, the issue was that CI scripts were (correctly) setting CFLAGS_*, and bootstrap was then (incorrectly) overriding these preferences. It worked implicitly before by invoking cc-rs in bootstrap to get the default flags (which meant that cc-rs parsed the CFLAGS_*), now we do it manually.

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 10, 2025
@rust-log-analyzer

This comment has been minimized.

@jieyouxu
Copy link
Member

(Tidy moment)

Copy link
Member

@jieyouxu jieyouxu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with tidy pleased

@madsmtm madsmtm force-pushed the bootstrap-deployment-target branch from 148ebac to ea68a47 Compare February 10, 2025 10:03
@jieyouxu
Copy link
Member

The bootstrap diff LGTM.
@bors r=Mark-Simulacrum,jieyouxu

@bors
Copy link
Contributor

bors commented Feb 10, 2025

📌 Commit ea68a47 has been approved by Mark-Simulacrum,jieyouxu

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 10, 2025
@bors
Copy link
Contributor

bors commented Feb 10, 2025

⌛ Testing commit ea68a47 with merge 6171d94...

@bors
Copy link
Contributor

bors commented Feb 10, 2025

☀️ Test successful - checks-actions
Approved by: Mark-Simulacrum,jieyouxu
Pushing 6171d94 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Feb 10, 2025
@bors bors merged commit 6171d94 into rust-lang:master Feb 10, 2025
7 checks passed
@rustbot rustbot added this to the 1.86.0 milestone Feb 10, 2025
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (6171d94): comparison URL.

Overall result: ❌ regressions - no action needed

@rustbot label: -perf-regression

Instruction count

This is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.5% [0.5%, 0.5%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary 3.4%, secondary 1.8%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
3.4% [3.4%, 3.4%] 1
Regressions ❌
(secondary)
5.7% [5.7%, 5.7%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.0% [-2.0%, -2.0%] 1
All ❌✅ (primary) 3.4% [3.4%, 3.4%] 1

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 785.578s -> 786.626s (0.13%)
Artifact size: 348.28 MiB -> 348.30 MiB (0.00%)

github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Feb 11, 2025
…imulacrum,jieyouxu

Always set the deployment target when building std

`cc` has [a bug/feature](rust-lang/cc-rs#1171) (I guess depending on how you look at it) where the default deployment target is taken from the SDK instead of from `rustc`. This causes `compiler-builtins` to build `compiler-rt` with the wrong deployment target on iOS.

I've been meaning to change how `cc` works in this regard, but that's a lengthy process, so let's fix it in bootstrap for now.

The behaviour can be seen locally with `./x build library --set build.optimized-compiler-builtins=true` for various target triples, and then inspecting with `otool -l build/host/stage1/lib/rustlib/*/lib/libcompiler_builtins-*.rlib | rg 'minos|version'`. I have added a rmake test that ensures that we now have the same version everywhere.

Fixes rust-lang/rust#128419
Fixes rust-lang/compiler-builtins#650
Fixes rust-lang/rust#136523
See also rust-lang/cargo#13115, rust-lang/cc-rs#1171, rust-lang/rust#136113
See rust-lang/rust#133092 (comment) for a description of how the change works.

try-job: i686-gnu-1
try-job: i686-gnu-2
try-job: x86_64-apple-1
try-job: aarch64-apple
try-job: dist-apple-various
try-job: dist-aarch64-apple
try-job: dist-various-2
try-job: x86_64-fuchsia
@madsmtm madsmtm deleted the bootstrap-deployment-target branch February 11, 2025 07:00
// Extend `CXXFLAGS_$TARGET` with our extra flags.
let env = format!("CXXFLAGS_{triple_underscored}");
let mut cxxflags =
builder.cc_unhandled_cflags(target, GitRepo::Rustc, CLang::Cxx).join(" ");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@madsmtm this change here broke our rust build (http://crbug.com/395891130) and extending this with cc_handled_cflags() fixes the issue. was it intentional to leave out the cc handled flags here (and above)?

(also nit: typo in cc_handled_clags)

Copy link
Contributor

@aeubanks aeubanks Feb 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah I see it was intentional based on the comments, but it's dropping flags we're passing via CFLAGS/CXXFLAGS/LDFLAGS/RUSTFLAGS_BOOTSTRAP/RUSTFLAGS_NOT_BOOTSTRAP (here) like --sysroot= in the stage1 build. am I holding it wrong? should I be using some other method to pass flags?

  = note: ld.lld: error: undefined reference: __libc_single_threaded
          >>> referenced by /usr/home/aeubanks/repos/chromium/src/third_party/rust-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-d74657ee7dc4cb63.so (disallowed by --no-allow-shlib-undefined)
          
          ld.lld: error: undefined reference: std::__throw_bad_array_new_length()
          >>> referenced by /usr/home/aeubanks/repos/chromium/src/third_party/rust-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-d74657ee7dc4cb63.so (disallowed by --no-allow-shlib-undefined)
          
          ld.lld: error: undefined reference: std::ios_base_library_init()
          >>> referenced by /usr/home/aeubanks/repos/chromium/src/third_party/rust-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-d74657ee7dc4cb63.so (disallowed by --no-allow-shlib-undefined)
          clang: error: linker command failed with exit code 1 (use -v to see invocation)
          

error: could not compile `rustc-main` (bin "rustc-main") due to 1 previous error

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@madsmtm having stared at this change a bit more, it seems like there's no longer a way to pass flags to stage1 links, which seems like a big regression?

github-actions bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Feb 13, 2025
…imulacrum,jieyouxu

Always set the deployment target when building std

`cc` has [a bug/feature](rust-lang/cc-rs#1171) (I guess depending on how you look at it) where the default deployment target is taken from the SDK instead of from `rustc`. This causes `compiler-builtins` to build `compiler-rt` with the wrong deployment target on iOS.

I've been meaning to change how `cc` works in this regard, but that's a lengthy process, so let's fix it in bootstrap for now.

The behaviour can be seen locally with `./x build library --set build.optimized-compiler-builtins=true` for various target triples, and then inspecting with `otool -l build/host/stage1/lib/rustlib/*/lib/libcompiler_builtins-*.rlib | rg 'minos|version'`. I have added a rmake test that ensures that we now have the same version everywhere.

Fixes rust-lang/rust#128419
Fixes rust-lang/compiler-builtins#650
Fixes rust-lang/rust#136523
See also rust-lang/cargo#13115, rust-lang/cc-rs#1171, rust-lang/rust#136113
See rust-lang/rust#133092 (comment) for a description of how the change works.

try-job: i686-gnu-1
try-job: i686-gnu-2
try-job: x86_64-apple-1
try-job: aarch64-apple
try-job: dist-apple-various
try-job: dist-aarch64-apple
try-job: dist-various-2
try-job: x86_64-fuchsia
aarongable pushed a commit to chromium/chromium that referenced this pull request Feb 14, 2025
…5-g7b473dfe-1 / d4bdd1ed551fed0c951eb47b4be2c79d7a02d181-1 : 9fcc9cf4a202aadfe1f44722b39c83536eba3dba-2

https://chromium.googlesource.com/external/github.com/llvm/llvm-project/+log/ba476d0b..7b473dfe

https://chromium.googlesource.com/external/github.com/rust-lang/rust/+log/d4bdd1ed551f..9fcc9cf4a202

Ran: ./tools/clang/scripts/upload_revision.py 7b473dfe84c17319930d4019ab3f6ca0cfc03416

Revert rust-lang/rust#133092 since it breaks our Linux Rust build.

Bug: 395520092, 395891130
Change-Id: I91789dec738622e88746cbdc1ec7f5ffb401cc93
Disable-Rts: True
Cq-Include-Trybots: chromium/try:chromeos-amd64-generic-cfi-thin-lto-rel
Cq-Include-Trybots: chromium/try:dawn-win10-x86-deps-rel
Cq-Include-Trybots: chromium/try:linux-chromeos-dbg
Cq-Include-Trybots: chromium/try:linux_chromium_cfi_rel_ng
Cq-Include-Trybots: chromium/try:linux_chromium_chromeos_msan_rel_ng
Cq-Include-Trybots: chromium/try:linux_chromium_msan_rel_ng
Cq-Include-Trybots: chromium/try:mac11-arm64-rel,mac_chromium_asan_rel_ng
Cq-Include-Trybots: chromium/try:ios-catalyst,win-asan,android-official
Cq-Include-Trybots: chromium/try:fuchsia-arm64-cast-receiver-rel
Cq-Include-Trybots: chromium/try:mac-official,linux-official
Cq-Include-Trybots: chromium/try:win-official,win32-official
Cq-Include-Trybots: chromium/try:win-arm64-rel
Cq-Include-Trybots: chromium/try:linux-swangle-try-x64,win-swangle-try-x86
Cq-Include-Trybots: chromium/try:android-cronet-mainline-clang-arm64-dbg
Cq-Include-Trybots: chromium/try:android-cronet-mainline-clang-arm64-rel
Cq-Include-Trybots: chromium/try:android-cronet-mainline-clang-riscv64-dbg
Cq-Include-Trybots: chromium/try:android-cronet-mainline-clang-riscv64-rel
Cq-Include-Trybots: chromium/try:android-cronet-mainline-clang-x86-dbg
Cq-Include-Trybots: chromium/try:android-cronet-mainline-clang-x86-rel
Cq-Include-Trybots: chromium/try:android-cronet-riscv64-dbg
Cq-Include-Trybots: chromium/try:android-cronet-riscv64-rel
Cq-Include-Trybots: chrome/try:iphone-device,ipad-device
Cq-Include-Trybots: chrome/try:linux-chromeos-chrome
Cq-Include-Trybots: chrome/try:win-chrome,win64-chrome,linux-chrome,mac-chrome
Cq-Include-Trybots: chrome/try:linux-pgo,mac-pgo,win32-pgo,win64-pgo
Cq-Include-Trybots: luci.chromium.try:linux-cast-x64-rel
Cq-Include-Trybots: chromium/try:android-rust-arm32-rel
Cq-Include-Trybots: chromium/try:android-rust-arm64-dbg
Cq-Include-Trybots: chromium/try:android-rust-arm64-rel
Cq-Include-Trybots: chromium/try:linux-rust-x64-dbg
Cq-Include-Trybots: chromium/try:linux-rust-x64-rel
Cq-Include-Trybots: chromium/try:mac-rust-x64-dbg
Cq-Include-Trybots: chromium/try:win-rust-x64-dbg
Cq-Include-Trybots: chromium/try:win-rust-x64-rel
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6261055
Reviewed-by: Nico Weber <thakis@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1420430}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-run-make Area: port run-make Makefiles to rmake.rs A-testsuite Area: The testsuite used to check the correctness of rustc merged-by-bors This PR was explicitly merged by bors. O-apple Operating system: Apple (macOS, iOS, tvOS, visionOS, watchOS) S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue.
Projects
None yet