Skip to content

Do not get proc_macro from the sysroot in rustc #141595

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

Merged
merged 1 commit into from
May 29, 2025

Conversation

bjorn3
Copy link
Member

@bjorn3 bjorn3 commented May 26, 2025

With the stage0 refactor the proc_macro version found in the sysroot will no longer always match the proc_macro version that proc-macros get compiled with by the rustc executable that uses this proc_macro. This will cause problems as soon as the ABI of the bridge gets changed to implement new features or change the way existing features work.

To fix this, this commit changes rustc crates to depend directly on the local version of proc_macro which will also be used in the sysroot that rustc will build.

@rustbot
Copy link
Collaborator

rustbot commented May 26, 2025

r? @compiler-errors

rustbot has assigned @compiler-errors.
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) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 26, 2025
@rustbot
Copy link
Collaborator

rustbot commented May 26, 2025

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

@bjorn3
Copy link
Member Author

bjorn3 commented May 26, 2025

cc #119899 (comment)

@@ -776,7 +776,8 @@ impl Step for RustcDev {
copy_src_dirs(
builder,
&builder.src,
&["compiler"],
// The compiler has a path dependency on proc_macro, so make sure to include it.
&["compiler", "library/proc_macro"],
Copy link
Member Author

Choose a reason for hiding this comment

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

I've tested that cargo metadata and cargo check still work in the built rustc-dev tarball. It may be possible to do the same trick for rustc-literal-escaper to pull it back into this repo.

Copy link
Member

Choose a reason for hiding this comment

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

The rustup component was not the only problem; the other problem are out-of-tree consumers -- RA has to be able to import some of the rustc crates, and IIRC the literal-escaper occurred in the dependency tree.

It'd be good to involve them here as well in case rustc_builtin_macros is in their dependency tree -- Cc @Veykril

Copy link
Member

Choose a reason for hiding this comment

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

It is not so that should be fine

Copy link
Member

Choose a reason for hiding this comment

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

I am also iffy about the fact that the compiler tree relies on this somewhat magical hack, but it looks fairly simple/maintainable and works perfectly fine. It seems like no one in the project is bothered by it (yet), so I would say let's move forward and revisit it if someone raises an issue.

@bjorn3 bjorn3 mentioned this pull request May 26, 2025
@@ -8,6 +8,9 @@ doctest = false

[dependencies]
# tidy-alphabetical-start
# We must use the proc_macro version that we will compile proc-macros against,
# not the one from our own sysroot.
proc_macro = { path = "../../library/proc_macro", default-features = false }
Copy link
Member

Choose a reason for hiding this comment

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

Will this work in the sources as they are distributed by rustup? IIRC last time we tried to share a file between library and compiler, a bunch of stuff broke.

Copy link
Member

Choose a reason for hiding this comment

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

Issue from last time this happened: #138647.

That was the exact same thing, a path dependency from compiler to library -- so it'll almost certainly fail in the exact same way this time again.

Copy link
Member

@jieyouxu jieyouxu May 26, 2025

Choose a reason for hiding this comment

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

EDIT: I didn't look closely, the rustc-dev dist component was addressed by #141595 (comment)

@rust-log-analyzer

This comment has been minimized.

@jieyouxu
Copy link
Member

r? @onur-ozkan

@onur-ozkan
Copy link
Member

@rustbot author

@rustbot rustbot 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-review Status: Awaiting review from the assignee but also interested parties. labels May 27, 2025
@rust-log-analyzer

This comment has been minimized.

@bjorn3 bjorn3 force-pushed the rustc_no_sysroot_proc_macro branch from 883ce51 to df1477d Compare May 27, 2025 10:31
@bjorn3
Copy link
Member Author

bjorn3 commented May 27, 2025

I had to switch from using a path dependency for proc_macro to creating a separate package which includes the same source as the proc_macro package.

@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 May 27, 2025
@rust-log-analyzer

This comment has been minimized.

@bjorn3 bjorn3 force-pushed the rustc_no_sysroot_proc_macro branch from df1477d to 72951e3 Compare May 27, 2025 11:18
@rust-log-analyzer

This comment has been minimized.

@bjorn3 bjorn3 force-pushed the rustc_no_sysroot_proc_macro branch from 72951e3 to 6c78091 Compare May 27, 2025 11:29
edition = "2024"

[lib]
path = "../../library/proc_macro/src/lib.rs"
Copy link
Member

Choose a reason for hiding this comment

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

This will break for the same reason, no? That path just doesn't exist when rustc-dev is distributed via rustup.

Copy link
Member Author

Choose a reason for hiding this comment

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

I explicitly added it to the rustc-dev component. See #141595 (comment).

Copy link
Member

Choose a reason for hiding this comment

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

Hm... if you do that then you can go back to making it a regular path dependency, you don't need this separate crate, do you?

Copy link
Member Author

Choose a reason for hiding this comment

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

That didn't work. Building two crates both named proc_macro (once as part of stdlib and once as part of rustc) causes ambiguity for extern crate proc_macro; when the rustc libraries are part of the sysroot. Because of this I'm forced to build the rustc copy with a different crate name, which requires a separate Cargo.toml.

@rust-log-analyzer

This comment has been minimized.

With the stage0 refactor the proc_macro version found in the sysroot
will no longer always match the proc_macro version that proc-macros get
compiled with by the rustc executable that uses this proc_macro. This
will cause problems as soon as the ABI of the bridge gets changed to
implement new features or change the way existing features work.

To fix this, this commit changes rustc crates to depend directly on the
local version of proc_macro which will also be used in the sysroot that
rustc will build.
@bjorn3 bjorn3 force-pushed the rustc_no_sysroot_proc_macro branch from 6c78091 to 026baa1 Compare May 27, 2025 15:49
@onur-ozkan
Copy link
Member

@bors r+ rollup=never (to make it easier to revert if any issues come up)

@bors
Copy link
Collaborator

bors commented May 28, 2025

📌 Commit 026baa1 has been approved by onur-ozkan

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 May 28, 2025
@onur-ozkan
Copy link
Member

This is blocking #119899, so @bors p=1

@bors
Copy link
Collaborator

bors commented May 29, 2025

⌛ Testing commit 026baa1 with merge 13718eb...

@bors
Copy link
Collaborator

bors commented May 29, 2025

☀️ Test successful - checks-actions
Approved by: onur-ozkan
Pushing 13718eb to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 29, 2025
@bors bors merged commit 13718eb into rust-lang:master May 29, 2025
8 checks passed
@rustbot rustbot added this to the 1.89.0 milestone May 29, 2025
@bjorn3 bjorn3 deleted the rustc_no_sysroot_proc_macro branch May 29, 2025 15:19
Copy link
Contributor

What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing 8afd710 (parent) -> 13718eb (this PR)

Test differences

No test diffs found

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard 13718eb788622ef8c998650451174570230d2971 --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. dist-apple-various: 7291.2s -> 6303.7s (-13.5%)
  2. aarch64-apple: 4784.4s -> 5398.9s (12.8%)
  3. x86_64-apple-1: 7755.6s -> 8418.6s (8.5%)
  4. x86_64-msvc-2: 6681.9s -> 7171.1s (7.3%)
  5. x86_64-msvc-1: 8787.5s -> 8144.4s (-7.3%)
  6. x86_64-gnu-llvm-20-1: 3870.4s -> 4147.2s (7.2%)
  7. dist-x86_64-apple: 8830.8s -> 8277.5s (-6.3%)
  8. dist-powerpc64le-linux-musl: 5370.3s -> 5657.9s (5.4%)
  9. x86_64-gnu-llvm-19-1: 3953.8s -> 4119.1s (4.2%)
  10. dist-i586-gnu-i586-i686-musl: 5099.9s -> 5307.4s (4.1%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (13718eb): comparison URL.

Overall result: ✅ improvements - 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
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.4% [-0.4%, -0.4%] 1
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (secondary 0.3%)

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)
- - 0
Regressions ❌
(secondary)
1.2% [0.6%, 2.7%] 7
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.1% [-2.6%, -0.6%] 4
All ❌✅ (primary) - - 0

Cycles

Results (secondary 0.2%)

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)
- - 0
Regressions ❌
(secondary)
0.7% [0.5%, 1.3%] 7
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.1% [-1.6%, -0.6%] 3
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 777.423s -> 780.508s (0.40%)
Artifact size: 368.47 MiB -> 368.46 MiB (-0.00%)

github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this pull request May 30, 2025
…r=onur-ozkan

Do not get proc_macro from the sysroot in rustc

With the stage0 refactor the proc_macro version found in the sysroot will no longer always match the proc_macro version that proc-macros get compiled with by the rustc executable that uses this proc_macro. This will cause problems as soon as the ABI of the bridge gets changed to implement new features or change the way existing features work.

To fix this, this commit changes rustc crates to depend directly on the local version of proc_macro which will also be used in the sysroot that rustc will build.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. 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-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants