Skip to content

Commit 0610a81

Browse files
authored
Merge pull request #573 from RalfJung/rustc-wrapper
use RUSTC_WRAPPER for the cargo hook
2 parents ff140da + ee2b5bb commit 0610a81

File tree

4 files changed

+41
-38
lines changed

4 files changed

+41
-38
lines changed

.travis.yml

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,51 +12,22 @@ os:
1212
dist: xenial
1313

1414
before_script:
15-
# install extra stuff for cross-compilation
15+
# Linux: install extra stuff for cross-compilation
1616
- if [[ "$TRAVIS_OS_NAME" == linux ]]; then sudo apt update && sudo apt install gcc-multilib; fi
17-
# macOS weirdness (https://github.com/travis-ci/travis-ci/issues/6307, https://github.com/travis-ci/travis-ci/issues/10165)
18-
- if [[ "$TRAVIS_OS_NAME" == osx ]]; then rvm get stable; fi
1917
# Compute the rust version we use. We do not use "language: rust" to have more control here.
2018
- |
2119
if [[ "$TRAVIS_EVENT_TYPE" == cron ]]; then
2220
RUST_TOOLCHAIN=nightly
2321
else
2422
RUST_TOOLCHAIN=$(cat rust-version)
2523
fi
26-
- |
27-
if [ "$TRAVIS_OS_NAME" == osx ]; then
28-
export MIRI_SYSROOT_BASE=~/Library/Caches/miri.miri.miri/
29-
else
30-
export MIRI_SYSROOT_BASE=~/.cache/miri/
31-
fi
32-
- |
33-
if [[ "$TRAVIS_OS_NAME" == osx ]]; then
34-
FOREIGN_TARGET=i686-apple-darwin
35-
else
36-
FOREIGN_TARGET=i686-unknown-linux-gnu
37-
fi
3824
# install Rust
3925
- curl https://build.travis-ci.org/files/rustup-init.sh -sSf | sh -s -- -y --default-toolchain "$RUST_TOOLCHAIN"
4026
- export PATH=$HOME/.cargo/bin:$PATH
4127
- rustc --version
4228

4329
script:
44-
- set -e
45-
- |
46-
# Build and install miri
47-
cargo build --release --all-features --all-targets &&
48-
cargo install --all-features --force --path .
49-
- |
50-
# Get ourselves a MIR-full libstd for the host and a foreign architecture
51-
cargo miri setup &&
52-
cargo miri setup --target "$FOREIGN_TARGET"
53-
- |
54-
# Test miri with full MIR, on the host and other architectures
55-
MIRI_SYSROOT=$MIRI_SYSROOT_BASE/HOST cargo test --release --all-features &&
56-
MIRI_SYSROOT=$MIRI_SYSROOT_BASE MIRI_TARGET=$FOREIGN_TARGET cargo test --release --all-features
57-
- |
58-
# Test cargo integration
59-
(cd test-cargo-miri && MIRI_SYSROOT=$MIRI_SYSROOT_BASE/HOST ./run-test.py)
30+
- ./travis.sh
6031

6132
notifications:
6233
email:

src/bin/cargo-miri.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,8 @@ fn main() {
305305
_ => {}
306306
}
307307
}
308-
} else {
309-
// This arm is executed when cargo-miri runs `cargo rustc` with the `RUSTC` env var set to itself:
308+
} else if let Some("rustc") = std::env::args().nth(1).as_ref().map(AsRef::as_ref) {
309+
// This arm is executed when cargo-miri runs `cargo rustc` with the `RUSTC_WRAPPER` env var set to itself:
310310
// Dependencies get dispatched to rustc, the final test/binary to miri.
311311

312312
let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME"));
@@ -332,11 +332,11 @@ fn main() {
332332

333333
// this conditional check for the --sysroot flag is there so users can call `cargo-miri` directly
334334
// without having to pass --sysroot or anything
335+
let rustc_args = std::env::args().skip(2);
335336
let mut args: Vec<String> = if std::env::args().any(|s| s == "--sysroot") {
336-
std::env::args().skip(1).collect()
337+
rustc_args.collect()
337338
} else {
338-
std::env::args()
339-
.skip(1)
339+
rustc_args
340340
.chain(Some("--sysroot".to_owned()))
341341
.chain(Some(sys_root))
342342
.collect()
@@ -365,6 +365,8 @@ fn main() {
365365
Err(ref e) if miri_enabled => panic!("error during miri run: {:?}", e),
366366
Err(ref e) => panic!("error during rustc call: {:?}", e),
367367
}
368+
} else {
369+
show_error(format!("Must be called with either `miri` or `rustc` as first argument."))
368370
}
369371
}
370372

@@ -389,7 +391,7 @@ where
389391
let path = std::env::current_exe().expect("current executable path invalid");
390392
let exit_status = Command::new("cargo")
391393
.args(&args)
392-
.env("RUSTC", path)
394+
.env("RUSTC_WRAPPER", path)
393395
.spawn()
394396
.expect("could not run cargo")
395397
.wait()

tests/compiletest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#![test_runner(test_runner)]
44

55
use std::slice::SliceConcatExt;
6-
use std::path::{PathBuf, Path};
6+
use std::path::PathBuf;
77
use std::env;
88

99
use compiletest_rs as compiletest;

travis.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Determine configuration
5+
if [ "$TRAVIS_OS_NAME" == osx ]; then
6+
export MIRI_SYSROOT_BASE=~/Library/Caches/miri.miri.miri/
7+
FOREIGN_TARGET=i686-apple-darwin
8+
else
9+
export MIRI_SYSROOT_BASE=~/.cache/miri/
10+
FOREIGN_TARGET=i686-unknown-linux-gnu
11+
fi
12+
13+
echo "Build and install miri"
14+
cargo build --release --all-features --all-targets &&
15+
cargo install --all-features --force --path .
16+
echo
17+
18+
echo "Get ourselves a MIR-full libstd for the host and a foreign architecture"
19+
cargo miri setup &&
20+
cargo miri setup --target "$FOREIGN_TARGET"
21+
echo
22+
23+
echo "Test miri with full MIR, on the host and other architectures"
24+
MIRI_SYSROOT=$MIRI_SYSROOT_BASE/HOST cargo test --release --all-features &&
25+
MIRI_SYSROOT=$MIRI_SYSROOT_BASE MIRI_TARGET=$FOREIGN_TARGET cargo test --release --all-features
26+
echo
27+
28+
echo "Test cargo integration"
29+
(cd test-cargo-miri && MIRI_SYSROOT=$MIRI_SYSROOT_BASE/HOST ./run-test.py)
30+
echo

0 commit comments

Comments
 (0)