Skip to content

fix rustc_llvm spurious rebuilds #100152

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

Closed

Conversation

beepster4096
Copy link
Contributor

This PR fixes 2 sources of unnecessary rebuilds in rustc_llvm's build script:

  1. On Windows, the LLVM_CONFIG and CFG_LLVM_ROOT env variables tracked by the build script can have different casing between rust-analyzer and the terminal. This is solved by lowercasing the paths before setting the vars.
  2. rustc_llvm's build script checks for the RUST_CHECK env var to avoid doing any work while just checking. However, it always tracked the var when doing so, causing it to rerun when checking after building. Then, this would cause it to rerun on the next build unnecessarily. This is solved by only tracking RUST_CHECK when it is present, causing it to only rebuild when needed.

@rustbot rustbot added 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 Aug 4, 2022
@rust-highfive
Copy link
Contributor

r? @jyn514

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 4, 2022
// If we're just running `check`, there's no need for LLVM to be built.
// We only track the RUST_CHECK var if it exists to prevent spurious rebuilds.
println!("cargo:rerun-if-env-changed=RUST_CHECK");
Copy link
Member

Choose a reason for hiding this comment

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

This is pretty suspicious -- this env variable should get set by rustbuild only if LLVM hasn't been built and we don't expect to need it (check/clippy run).

causing it to rerun when checking after building

So if you build, then on a subsequent x.py check, RUST_CHECK shouldn't be set. I think the fault here lies with the logic around here (

if crate::native::prebuilt_llvm_config(self, target).is_err() {
), not this build script.

cargo.env("LLVM_CONFIG", llvm_config.as_os_str().to_ascii_lowercase());
} else {
cargo.env("LLVM_CONFIG", &llvm_config);
}
Copy link
Member

Choose a reason for hiding this comment

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

It feels like we'll be on a pretty long road to fixing this if we have to make this kind of conversion on every point where Cargo is going to be sensitive to this. Is there a chance this is something we can fix with rust-analyzer or otherwise? It feels a little weird that there's different cases floating around, even if the underlying filesystem is insensitive.

cargo.env("LLVM_CONFIG", &llvm_config);

// HACK: on windows, paths are case insensitive, so case differences cause spurious rebuilds
if target.contains("windows") {
Copy link
Member

Choose a reason for hiding this comment

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

Why is the target important here? Shouldn't it be the host instead? Because one might cross compile Windows from Linux, which usually happens on a case sensitive file system. Or vice versa. Also, it's an imprecise generalization that windows paths are case insensitive, because you can enable case sensitive directories on Windows. Wouldn't this break in this instance then?

@Milo123459
Copy link
Contributor

This would solve #92369 I presume?

@Mark-Simulacrum
Copy link
Member

The difference we picked up there seems to be a \ vs / path, not case sensitivity, so I'd guess no.

@jyn514
Copy link
Member

jyn514 commented Aug 9, 2022

Haven't looked at this in detail, but the existing review comments make sense to me - would like to see an answer to those.

@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 Aug 9, 2022
@JohnCSimon
Copy link
Member

ping from triage:

Haven't looked at this in detail, but the existing review comments make sense to me - would like to see an answer to those.

@drmeepster ☝️ can you address this?

FYI: when a PR is ready for review, send a message containing
@rustbot ready to switch to S-waiting-on-review so the PR is in the reviewer's backlog.

@beepster4096
Copy link
Contributor Author

Sorry for disappearing for a while!

Using a separate build directory for rust-analyzer sidesteps this issue, so I don't really have the motivation to fix the problems with this PR.

@Dylan-DPC Dylan-DPC removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Oct 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

9 participants