Skip to content

Commit 0daa3b2

Browse files
authored
Merge pull request rust-lang#99 from oli-obk/travis
various travis cleanups + run miri tests on travis against 4 major targets
2 parents 57b9838 + 3ee3438 commit 0daa3b2

File tree

5 files changed

+51
-23
lines changed

5 files changed

+51
-23
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ before_script:
55
- |
66
pip install 'travis-cargo<0.2' --user &&
77
export PATH=$HOME/.local/bin:$PATH
8+
- sh ~/rust-installer/rustup.sh --add-target=i686-unknown-linux-gnu --prefix=/home/travis/rust -y --disable-sudo
9+
- sh ~/rust-installer/rustup.sh --add-target=i686-pc-windows-gnu --prefix=/home/travis/rust -y --disable-sudo
10+
- sh ~/rust-installer/rustup.sh --add-target=i686-pc-windows-msvc --prefix=/home/travis/rust -y --disable-sudo
811
script:
912
- |
1013
env RUST_SYSROOT=$HOME/rust travis-cargo build &&

src/bin/miri.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ impl<'a> CompilerCalls<'a> for MiriCompilerCalls {
2121
let mut control = CompileController::basic();
2222
control.after_hir_lowering.callback = Box::new(after_hir_lowering);
2323
control.after_analysis.callback = Box::new(after_analysis);
24-
control.after_analysis.stop = Compilation::Stop;
24+
if std::env::var("MIRI_HOST_TARGET") != Ok("yes".to_owned()) {
25+
// only fully compile targets on the host
26+
control.after_analysis.stop = Compilation::Stop;
27+
}
2528
control
2629
}
2730
}
@@ -136,6 +139,12 @@ fn main() {
136139
args.push(sysroot_flag);
137140
args.push(find_sysroot());
138141
}
142+
// we run the optimization passes inside miri
143+
// if we ran them twice we'd get funny failures due to borrowck ElaborateDrops only working on
144+
// unoptimized MIR
145+
// FIXME: add an after-mir-passes hook to rustc driver
146+
args.push("-Zmir-opt-level=0".to_owned());
147+
// for auxilary builds in unit tests
139148
args.push("-Zalways-encode-mir".to_owned());
140149

141150
rustc_driver::run_compiler(&args, &mut MiriCompilerCalls, None, None);

tests/compile-fail/send-is-not-static-par-for.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
//error-pattern: no mir for `std::panicking::panicking`
11+
//error-pattern: no mir for `std::
1212

1313
use std::sync::Mutex;
1414

tests/compiletest.rs

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ extern crate compiletest_rs as compiletest;
33
use std::path::{PathBuf, Path};
44
use std::io::Write;
55

6-
fn compile_fail(sysroot: &str) {
7-
let flags = format!("--sysroot {} -Dwarnings", sysroot);
8-
for_all_targets(sysroot, |target| {
6+
fn compile_fail(sysroot: &Path) {
7+
let flags = format!("--sysroot {} -Dwarnings", sysroot.to_str().expect("non utf8 path"));
8+
for_all_targets(&sysroot, |target| {
99
let mut config = compiletest::default_config();
1010
config.host_rustcflags = Some(flags.clone());
1111
config.mode = "compile-fail".parse().expect("Invalid mode");
@@ -27,13 +27,21 @@ fn run_pass() {
2727
compiletest::run_tests(&config);
2828
}
2929

30-
fn miri_pass(path: &str, target: &str) {
30+
fn miri_pass(path: &str, target: &str, host: &str) {
3131
let mut config = compiletest::default_config();
3232
config.mode = "mir-opt".parse().expect("Invalid mode");
3333
config.src_base = PathBuf::from(path);
3434
config.target = target.to_owned();
35+
config.host = host.to_owned();
3536
config.rustc_path = PathBuf::from("target/debug/miri");
37+
// don't actually execute the final binary, it might be for other targets and we only care
38+
// about running miri, not the binary.
39+
config.runtool = Some("echo \"\" || ".to_owned());
40+
if target == host {
41+
std::env::set_var("MIRI_HOST_TARGET", "yes");
42+
}
3643
compiletest::run_tests(&config);
44+
std::env::set_var("MIRI_HOST_TARGET", "");
3745
}
3846

3947
fn is_target_dir<P: Into<PathBuf>>(path: P) -> bool {
@@ -42,8 +50,10 @@ fn is_target_dir<P: Into<PathBuf>>(path: P) -> bool {
4250
path.metadata().map(|m| m.is_dir()).unwrap_or(false)
4351
}
4452

45-
fn for_all_targets<F: FnMut(String)>(sysroot: &str, mut f: F) {
46-
for entry in std::fs::read_dir(format!("{}/lib/rustlib/", sysroot)).unwrap() {
53+
fn for_all_targets<F: FnMut(String)>(sysroot: &Path, mut f: F) {
54+
let target_dir = sysroot.join("lib").join("rustlib");
55+
println!("target dir: {}", target_dir.to_str().unwrap());
56+
for entry in std::fs::read_dir(target_dir).expect("invalid sysroot") {
4757
let entry = entry.unwrap();
4858
if !is_target_dir(entry.path()) { continue; }
4959
let target = entry.file_name().into_string().unwrap();
@@ -55,20 +65,27 @@ fn for_all_targets<F: FnMut(String)>(sysroot: &str, mut f: F) {
5565

5666
#[test]
5767
fn compile_test() {
58-
// Taken from https://github.com/Manishearth/rust-clippy/pull/911.
59-
let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME"));
60-
let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN"));
61-
let sysroot = match (home, toolchain) {
62-
(Some(home), Some(toolchain)) => format!("{}/toolchains/{}", home, toolchain),
63-
_ => option_env!("RUST_SYSROOT")
64-
.expect("need to specify RUST_SYSROOT env var or use rustup or multirust")
65-
.to_owned(),
66-
};
68+
let sysroot = std::process::Command::new("rustc")
69+
.arg("--print")
70+
.arg("sysroot")
71+
.output()
72+
.expect("rustc not found")
73+
.stdout;
74+
let sysroot = std::str::from_utf8(&sysroot).expect("sysroot is not utf8").trim();
75+
let sysroot = &Path::new(&sysroot);
76+
let host = std::process::Command::new("rustc")
77+
.arg("-vV")
78+
.output()
79+
.expect("rustc not found for -vV")
80+
.stdout;
81+
let host = std::str::from_utf8(&host).expect("sysroot is not utf8");
82+
let host = host.split("\nhost: ").skip(1).next().expect("no host: part in rustc -vV");
83+
let host = host.split("\n").next().expect("no \n after host");
6784
run_pass();
6885
for_all_targets(&sysroot, |target| {
69-
miri_pass("tests/run-pass", &target);
86+
miri_pass("tests/run-pass", &target, host);
7087
if let Ok(path) = std::env::var("MIRI_RUSTC_TEST") {
71-
miri_pass(&path, &target);
88+
miri_pass(&path, &target, host);
7289
}
7390
});
7491
compile_fail(&sysroot);

tests/run-pass/aux_test.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
// aux-build:dep.rs
2+
// ignore-cross-compile
23

3-
// FIXME: Auxiliary builds are currently broken.
4-
// extern crate dep;
4+
extern crate dep;
55

66
fn main() {
7-
// FIXME: Auxiliary builds are currently broken.
8-
// dep::foo();
7+
dep::foo();
98
}

0 commit comments

Comments
 (0)