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

Fix no_std tests that load libc from the sysroot when download-rustc is enabled #110229

Merged
merged 1 commit into from
Apr 19, 2023

Commits on Apr 18, 2023

  1. Fix no_std tests that load libc when download-rustc is enabled

    There were a series of unfortunate interactions here. Here's an MCVE of the test this fixes (committed as `tests/ui/meta/no_std-extern-libc.rs`):
    ```rust
     #![crate_type = "lib"]
     #![no_std]
     #![feature(rustc_private)]
    extern crate libc;
    ```
    
    Before, this would give an error about duplicate versions of libc:
    ```
    error[E0464]: multiple candidates for `rlib` dependency `libc` found
      --> fake-test-src-base/allocator/no_std-alloc-error-handler-default.rs:15:1
       |
    LL | extern crate libc;
       | ^^^^^^^^^^^^^^^^^^
       |
       = note: candidate #1: /home/gh-jyn514/rust/build/aarch64-unknown-linux-gnu/stage2/lib/rustlib/aarch64-unknown-linux-gnu/lib/liblibc-358db1024b7d9957.rlib
       = note: candidate #2: /home/gh-jyn514/rust/build/aarch64-unknown-linux-gnu/stage2/lib/rustlib/aarch64-unknown-linux-gnu/lib/liblibc-ebc478710122a279.rmeta
    ```
    Both these versions were downloaded from CI, but one came from the `rust-std` component and one came from `rustc-dev`:
    ```
    ; tar -tf build/cache/f2d9a3d0771504f1ae776226a5799dcb4408a91a/rust-std-nightly-x86_64-unknown-linux-gnu.tar.xz | grep liblibc
    rust-std-nightly-x86_64-unknown-linux-gnu/rust-std-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-68a2d9e195dd6ed2.rlib
    ; tar -tf build/cache/f2d9a3d0771504f1ae776226a5799dcb4408a91a/rustc-dev-nightly-x86_64-unknown-linux-gnu.tar.xz | grep liblibc
    rustc-dev-nightly-x86_64-unknown-linux-gnu/rustc-dev/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-f226c9fbdd92a0fd.rmeta
    ```
    The fix was to only copy files from `rust-std` unless a Step explicitly requests for the `rustc-dev` components to be available by calling `builder.ensure(compile::Rustc)`.
    
    To avoid having to re-parse the `rustc-dev.tar.xz` tarball every time, which is quite slow, this adds a new `build/host/ci-rustc/.rustc-dev-contents` cache file which stores only the names of files we need to copy into the sysroot.
    
    This also allows reverting the hack in
    rust-lang#110121; now that we only copy
    rustc-dev on-demand, we can correctly add the `Rustc` check artifacts
    into the sysroot, so that this works correctly even when
    `download-rustc` is forced to `true`.
    
    ---
    
    See rust-lang#108767 (comment) for why `no_std` is required for the MCVE test to fail; it's complicated and not particularly important.
    
    Fixes rust-lang#108767.
    jyn514 committed Apr 18, 2023
    Configuration menu
    Copy the full SHA
    71f04bd View commit details
    Browse the repository at this point in the history