Auto merge of #2806 - saethlin:better-install, r=RalfJung

Install binaries to the miri toolchain's sysroot

The default install produces this behavior:
```
$ cargo +miri miri --version
miri 0.1.0 (0ba1f4a0 2023-03-05)
$ cargo +nightly miri --version
miri 0.1.0 (0ba1f4a0 2023-03-05)
```
Which is not good. We've effectively erased the toolchain selection, and users may reasonably conclude that their rustup install is broken.

After this change, we now get this:
```
$ cargo +miri miri --version
miri 0.1.0 (0ba1f4a0 2023-03-05)
$ cargo +nightly miri --version
miri 0.1.0 (f63ccaf 2023-03-06)
```

Thanks `@jyn514` who all but wrote this for me.
This commit is contained in:
bors 2023-03-15 12:45:04 +00:00
commit 3ad2fece14
4 changed files with 15 additions and 17 deletions

View File

@ -54,8 +54,8 @@ jobs:
# contains package information of crates installed via `cargo install`. # contains package information of crates installed via `cargo install`.
~/.cargo/.crates.toml ~/.cargo/.crates.toml
~/.cargo/.crates2.json ~/.cargo/.crates2.json
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} key: ${{ runner.os }}-cargo-reset20230315-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo restore-keys: ${{ runner.os }}-cargo-reset20230315
- name: Install rustup-toolchain-install-master - name: Install rustup-toolchain-install-master
if: ${{ steps.cache.outputs.cache-hit != 'true' }} if: ${{ steps.cache.outputs.cache-hit != 'true' }}
@ -106,8 +106,8 @@ jobs:
# contains package information of crates installed via `cargo install`. # contains package information of crates installed via `cargo install`.
~/.cargo/.crates.toml ~/.cargo/.crates.toml
~/.cargo/.crates2.json ~/.cargo/.crates2.json
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} key: ${{ runner.os }}-cargo-reset20230315-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo restore-keys: ${{ runner.os }}-cargo-reset20230315
- name: Install rustup-toolchain-install-master - name: Install rustup-toolchain-install-master
if: ${{ steps.cache.outputs.cache-hit != 'true' }} if: ${{ steps.cache.outputs.cache-hit != 'true' }}

View File

@ -129,18 +129,15 @@ development version of Miri using
./miri install ./miri install
``` ```
and then you can use it as if it was installed by `rustup`. Make sure you use and then you can use it as if it was installed by `rustup` as a component of the
the same toolchain when calling `cargo miri` that you used when installing Miri! `miri` toolchain. Note that the `miri` and `cargo-miri` executables are placed
Usually this means you have to write `cargo +miri miri ...` to select the `miri` in the `miri` toolchain's sysroot to prevent conflicts with other toolchains.
toolchain that was installed by `./miri toolchain`. The Miri binaries in the `cargo` bin directory (usually `~/.cargo/bin`) are managed by rustup.
There's a test for the cargo wrapper in the `test-cargo-miri` directory; run There's a test for the cargo wrapper in the `test-cargo-miri` directory; run
`./run-test.py` in there to execute it. Like `./miri test`, this respects the `./run-test.py` in there to execute it. Like `./miri test`, this respects the
`MIRI_TEST_TARGET` environment variable to execute the test for another target. `MIRI_TEST_TARGET` environment variable to execute the test for another target.
Note that installing Miri like this will "take away" Miri management from `rustup`.
If you want to later go back to a rustup-installed Miri, run `rustup update`.
### Using a modified standard library ### Using a modified standard library
Miri re-builds the standard library into a custom sysroot, so it is fairly easy Miri re-builds the standard library into a custom sysroot, so it is fairly easy

View File

@ -62,8 +62,8 @@ function run_tests {
if [ "$HOST_TARGET" = x86_64-unknown-linux-gnu ]; then if [ "$HOST_TARGET" = x86_64-unknown-linux-gnu ]; then
# These act up on Windows (`which miri` produces a filename that does not exist?!?), # These act up on Windows (`which miri` produces a filename that does not exist?!?),
# so let's do this only on Linux. Also makes sure things work without these set. # so let's do this only on Linux. Also makes sure things work without these set.
export RUSTC=$(which rustc) export RUSTC=$(which rustc) # Produces a warning unless we also set MIRI
export MIRI=$(which miri) export MIRI=$(rustc +miri --print sysroot)/bin/miri
fi fi
mkdir -p .cargo mkdir -p .cargo
echo 'build.rustc-wrapper = "thisdoesnotexist"' > .cargo/config.toml echo 'build.rustc-wrapper = "thisdoesnotexist"' > .cargo/config.toml

View File

@ -6,8 +6,8 @@ USAGE=$(cat <<"EOF"
./miri install <flags>: ./miri install <flags>:
Installs the miri driver and cargo-miri. <flags> are passed to `cargo Installs the miri driver and cargo-miri. <flags> are passed to `cargo
install`. Sets up the rpath such that the installed binary should work in any install`. Sets up the rpath such that the installed binary should work in any
working directory. However, the rustup toolchain when invoking `cargo miri` working directory. Note that the binaries are placed in the `miri` toolchain
needs to be the same one used for `./miri install`. sysroot, to prevent conflicts with other toolchains.
./miri build <flags>: ./miri build <flags>:
Just build miri. <flags> are passed to `cargo build`. Just build miri. <flags> are passed to `cargo build`.
@ -281,8 +281,9 @@ find_sysroot() {
case "$COMMAND" in case "$COMMAND" in
install) install)
# "--locked" to respect the Cargo.lock file if it exists. # "--locked" to respect the Cargo.lock file if it exists.
$CARGO install $CARGO_EXTRA_FLAGS --path "$MIRIDIR" --force --locked "$@" # Install binaries to the miri toolchain's sysroot so they do not interact with other toolchains.
$CARGO install $CARGO_EXTRA_FLAGS --path "$MIRIDIR"/cargo-miri --force --locked "$@" $CARGO install $CARGO_EXTRA_FLAGS --path "$MIRIDIR" --force --locked --root "$SYSROOT" "$@"
$CARGO install $CARGO_EXTRA_FLAGS --path "$MIRIDIR"/cargo-miri --force --locked --root "$SYSROOT" "$@"
;; ;;
check) check)
# Check, and let caller control flags. # Check, and let caller control flags.