Skip to content

Commit

Permalink
Auto merge of #14370 - weihanglo:build-std, r=Muscraft
Browse files Browse the repository at this point in the history
fix: std Cargo.lock moved to `library` dir

#14358 didn't check the correct Cargo.lock existence
Perhaps it was there so the test passed,
but after a new nightly is out it is gone.

```
    Blocking waiting for file lock on package cache
error: "/home/user/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/Cargo.lock" does not exist, unable to build with the standard library, try:
        rustup component add rust-src --toolchain nightly-aarch64-apple-darwin

note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```

Fixes rust-lang/rust#128808

### How to test the change:

The current nightly `cargo 1.82.0-nightly (94977cb 2024-08-06)` would fail when running

```
cargo +nightly build -Zbuild-std --target <host-triple>
```

After this fix, it should just work

```
RUSTC=~/.rustup/toolchains/nightly-<host-triple>/bin/rustc ./target/debug/cargo build -Zbuild-std --target <host-triple>
```
  • Loading branch information
bors committed Aug 8, 2024
2 parents f50c592 + 50237f4 commit 0d8d22f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/cargo/core/compiler/standard_lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub fn resolve_std<'gctx>(
}

let src_path = detect_sysroot_src_path(target_data)?;
let std_ws_manifest_path = src_path.join("library").join("Cargo.toml");
let std_ws_manifest_path = src_path.join("Cargo.toml");
let gctx = ws.gctx();
// TODO: Consider doing something to enforce --locked? Or to prevent the
// lock file from being written, such as setting ephemeral.
Expand Down Expand Up @@ -192,7 +192,8 @@ fn detect_sysroot_src_path(target_data: &RustcTargetData<'_>) -> CargoResult<Pat
.join("lib")
.join("rustlib")
.join("src")
.join("rust");
.join("rust")
.join("library");
let lock = src_path.join("Cargo.lock");
if !lock.exists() {
let msg = format!(
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/standard_lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ fn setup() -> Setup {
fn enable_build_std(e: &mut Execs, setup: &Setup) {
// First up, force Cargo to use our "mock sysroot" which mimics what
// libstd looks like upstream.
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/testsuite/mock-std");
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/testsuite/mock-std/library");
e.env("__CARGO_TESTS_ONLY_SRC_ROOT", &root);

e.masquerade_as_nightly_cargo(&["build-std"]);
Expand Down

0 comments on commit 0d8d22f

Please sign in to comment.