Skip to content

rustc proxy may not invoke the correct rustc override when used with external cargo. #2762

@cr1901

Description

@cr1901

Problem
This too may be a cargo problem, but since it involves the rustc proxy, I'll open here first.

Consider a crate with the following src/lib.rs and Cargo.toml:

#![no_std]

use bit_reverse;

#[cfg(test)]
mod tests {
    #[test]
    fn it_works() {
        assert_eq!(2 + 2, 4);
    }
}
[package]
name = "rust-check"
version = "0.1.0"
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bit_reverse = "*"

My default rustup toolchain is nightly, and I have an override to use stable in this directory. rustup is on the path first, so the proxies will be picked up first. In addition, I have an external cargo that I built for testing that I'm using instead of the proxy that rustup provides. When invoking this particular cargo binary, which is not a proxy, I get the following error:

william@xubuntu-dtrain:~/Projects/toolchains/rust-check$ ../cargo/target/debug/cargo build
    Updating crates.io index
   Compiling bit_reverse v0.1.8
   Compiling rust-check v0.1.0 (/home/william/Projects/toolchains/rust-check)
error[E0514]: found crate `bit_reverse` compiled by an incompatible version of rustc
 --> src/lib.rs:3:5
  |
3 | use bit_reverse;
  |     ^^^^^^^^^^^
  |
  = help: please recompile that crate using this compiler (rustc 1.51.0 (2fd73fabe 2021-03-23))
  = note: the following crate versions were found:
          crate `bit_reverse` compiled by rustc 1.53.0-nightly (9d9c2c92b 2021-04-19): /home/william/Projects/toolchains/rust-check/target/debug/deps/libbit_reverse-4ef4b144e0bd8cec.rmeta

error: aborting due to previous error

error: could not compile `rust-check`

To learn more, run the command again with --verbose.

Steps

  1. Compile your own cargo from source, e.g. git clone https://github.com/rust-lang/cargo; cd cargo; cargo build.
  2. Create a crate such as above with any external dependency that's used.
  3. In that crate directory, set up a rustup override to anything besides your default toolchain.
  4. Attempt to compile the crate using your shiny new cargo, and not the cargo proxy provided by rustup.

Possible Solution(s)
Since cargo invokes rustc, and the rustc proxy is first on my path, the external cargo is invoking the rustc proxy. However, the override is not taking effect except for the final crate. I can confirm that all artifacts are built with the default rustc in my case (nightly), until the final crate is compiled. At this point, rustc invoked from external cargo starts honoring the override, and crate compilation fails due to version mismatch.

Is this not supported? It's fine if using an external cargo unsupported, but I do wonder if:

  1. A better error message/warning could notify the user that this is not supported.
  2. How does one debug cargo in the presence of rustup on the path?
  3. Additionally, I thought cargo could auto-detect whether there's a version-mismatch that warrants recompiling dependencies? Does this setup break auto-detect?

Notes

System Information:

william@xubuntu-dtrain:~/Projects/toolchains/rust-check$ uname -a
Linux xubuntu-dtrain 5.4.0-72-generic #80-Ubuntu SMP Mon Apr 12 17:35:00 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

william@xubuntu-dtrain:~/Projects/toolchains/rust-check$ rustup -V
rustup 1.24.1 (a01bd6b0d 2021-04-27)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.51.0 (2fd73fabe 2021-03-23)`

william@xubuntu-dtrain:~/Projects/toolchains/rust-check$ rustup show
Default host: x86_64-unknown-linux-gnu
rustup home:  /home/william/.rustup

installed toolchains
--------------------

stable-x86_64-unknown-linux-gnu
nightly-x86_64-unknown-linux-gnu
msp430-fix
shared-rust

active toolchain
----------------

stable-x86_64-unknown-linux-gnu (directory override for '/home/william/Projects/toolchains/rust-check')
rustc 1.51.0 (2fd73fabe 2021-03-23)

william@xubuntu-dtrain:~/Projects/toolchains/rust-check$ rustc +nightly -V
rustc 1.53.0-nightly (9d9c2c92b 2021-04-19)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions