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

using ~/.cargo/config.toml to enable cranelift results in a confusing error when bootstrapping rustc #135300

Open
lolbinarycat opened this issue Jan 9, 2025 · 5 comments
Labels
C-discussion Category: Discussion or questions that doesn't represent real issues. D-confusing Diagnostics: Confusing error or lint that should be reworked. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Comments

@lolbinarycat
Copy link
Contributor

the offending config:

# .cargo/config.toml
unstable.codegen-backend = true
# commenting out the following line will allow rustc to bootstrap successfully
profile.dev.codegen-backend = "cranelift"

the errror:

error: failed to find a `codegen-backends` folder in the sysroot candidates:
       * /home/binarycat/src/rs/rust/build/x86_64-unknown-linux-gnu/stage0
       * /home/binarycat/src/rs/rust/build/x86_64-unknown-linux-gnu/stage0

reproduction steps:

  1. enable download-rustc
  2. remove all of build/
  3. ./x doc library/core (probably any build command works)

there's a lot of workarounds for this, but i was only able to diagnose it on a hunch, so at the very least the error message should be more clear.

@lolbinarycat lolbinarycat added C-bug Category: This is a bug. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Jan 9, 2025
@onur-ozkan onur-ozkan added the D-confusing Diagnostics: Confusing error or lint that should be reworked. label Jan 10, 2025
@onur-ozkan
Copy link
Member

reproduction steps:

enable download-rustc
remove all of build/
./x doc library/core (probably any build command works)

x check without 1 and 2 should be enough for reproduction.

The failure happens during bootstrap compilation itself, which is the first thing we compile on bootstrapping. In order to give a friendly message, what we have to do is:

  1. Parse .cargo/config.toml in the bootstrap python script (which will be migrated to rust eventually)
  2. Check whether sysroot contains the related artifacts for the backend used in .cargo/config.toml
  3. Give a nice error message.

I strongly believe this is too much to give a error message just for a slightly better error message than the current one (I even think the current one is quite clear already).

Even with a nice error message, there is no way to use different backends in .cargo/config.toml if you are using the default stage0 compiler. So, the path for setting different codegen on cargo is requires custom configurations and custom compiler toolchain. If we want to switch codegen backend, that should be done in the bootstrap way rather than doing it with cargo directly.

I am going to close the issue as this isn't something we can consider doing it.

@onur-ozkan onur-ozkan closed this as not planned Won't fix, can't repro, duplicate, stale Jan 13, 2025
@lolbinarycat
Copy link
Contributor Author

reopening this because i found a potential workaround: setting the environment variable CARGO_PROFILE_DEV_CODEGEN_BACKEND=llvm in bootstrap.py.

this will override the global config and eliminate the error entirely.

@lolbinarycat lolbinarycat reopened this Feb 24, 2025
@onur-ozkan
Copy link
Member

Why should we override the backend? The purpose was making the error message more clear, not ignoring the cargo/config.toml backend.

@lolbinarycat
Copy link
Contributor Author

The problem is that there is a confusing error message. This can be fixed either by making the error message less confusing, or by removing it entirely.

rustc effectively has its own build system, and in many places already overrides the global cargo config.

@onur-ozkan
Copy link
Member

That would have side effects like overriding the project-specific cargo/config.toml if present. Also, I assume this would be problematic when different backend is configured from config.toml. IMO it doesn't seem like a good solution and it doesn't seem to worth it just to hide an error message because it seemed confusing and arises in a very specific and rare case.

@onur-ozkan onur-ozkan added C-discussion Category: Discussion or questions that doesn't represent real issues. and removed C-bug Category: This is a bug. labels Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-discussion Category: Discussion or questions that doesn't represent real issues. D-confusing Diagnostics: Confusing error or lint that should be reworked. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
Projects
None yet
Development

No branches or pull requests

2 participants