diff --git a/.travis.yml b/.travis.yml index e76a2f86cf93..91e6255f33cc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,9 @@ before_script: - | pip install 'travis-cargo<0.2' --user && export PATH=$HOME/.local/bin:$PATH +- sh ~/rust-installer/rustup.sh --add-target=i686-unknown-linux-gnu --prefix=/home/travis/rust -y --disable-sudo +- sh ~/rust-installer/rustup.sh --add-target=i686-pc-windows-gnu --prefix=/home/travis/rust -y --disable-sudo +- sh ~/rust-installer/rustup.sh --add-target=i686-pc-windows-msvc --prefix=/home/travis/rust -y --disable-sudo script: - | env RUST_SYSROOT=$HOME/rust travis-cargo build && diff --git a/src/bin/miri.rs b/src/bin/miri.rs index 379f25ef7576..56c2e433d067 100644 --- a/src/bin/miri.rs +++ b/src/bin/miri.rs @@ -21,7 +21,10 @@ impl<'a> CompilerCalls<'a> for MiriCompilerCalls { let mut control = CompileController::basic(); control.after_hir_lowering.callback = Box::new(after_hir_lowering); control.after_analysis.callback = Box::new(after_analysis); - control.after_analysis.stop = Compilation::Stop; + if std::env::var("MIRI_HOST_TARGET") != Ok("yes".to_owned()) { + // only fully compile targets on the host + control.after_analysis.stop = Compilation::Stop; + } control } } @@ -136,6 +139,12 @@ fn main() { args.push(sysroot_flag); args.push(find_sysroot()); } + // we run the optimization passes inside miri + // if we ran them twice we'd get funny failures due to borrowck ElaborateDrops only working on + // unoptimized MIR + // FIXME: add an after-mir-passes hook to rustc driver + args.push("-Zmir-opt-level=0".to_owned()); + // for auxilary builds in unit tests args.push("-Zalways-encode-mir".to_owned()); rustc_driver::run_compiler(&args, &mut MiriCompilerCalls, None, None); diff --git a/tests/compile-fail/send-is-not-static-par-for.rs b/tests/compile-fail/send-is-not-static-par-for.rs index bee05ecd7fae..afb401a919e9 100644 --- a/tests/compile-fail/send-is-not-static-par-for.rs +++ b/tests/compile-fail/send-is-not-static-par-for.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -//error-pattern: no mir for `std::panicking::panicking` +//error-pattern: no mir for `std:: use std::sync::Mutex; diff --git a/tests/compiletest.rs b/tests/compiletest.rs index 50970086ee54..909538494e86 100644 --- a/tests/compiletest.rs +++ b/tests/compiletest.rs @@ -3,9 +3,9 @@ extern crate compiletest_rs as compiletest; use std::path::{PathBuf, Path}; use std::io::Write; -fn compile_fail(sysroot: &str) { - let flags = format!("--sysroot {} -Dwarnings", sysroot); - for_all_targets(sysroot, |target| { +fn compile_fail(sysroot: &Path) { + let flags = format!("--sysroot {} -Dwarnings", sysroot.to_str().expect("non utf8 path")); + for_all_targets(&sysroot, |target| { let mut config = compiletest::default_config(); config.host_rustcflags = Some(flags.clone()); config.mode = "compile-fail".parse().expect("Invalid mode"); @@ -27,13 +27,21 @@ fn run_pass() { compiletest::run_tests(&config); } -fn miri_pass(path: &str, target: &str) { +fn miri_pass(path: &str, target: &str, host: &str) { let mut config = compiletest::default_config(); config.mode = "mir-opt".parse().expect("Invalid mode"); config.src_base = PathBuf::from(path); config.target = target.to_owned(); + config.host = host.to_owned(); config.rustc_path = PathBuf::from("target/debug/miri"); + // don't actually execute the final binary, it might be for other targets and we only care + // about running miri, not the binary. + config.runtool = Some("echo \"\" || ".to_owned()); + if target == host { + std::env::set_var("MIRI_HOST_TARGET", "yes"); + } compiletest::run_tests(&config); + std::env::set_var("MIRI_HOST_TARGET", ""); } fn is_target_dir>(path: P) -> bool { @@ -42,8 +50,10 @@ fn is_target_dir>(path: P) -> bool { path.metadata().map(|m| m.is_dir()).unwrap_or(false) } -fn for_all_targets(sysroot: &str, mut f: F) { - for entry in std::fs::read_dir(format!("{}/lib/rustlib/", sysroot)).unwrap() { +fn for_all_targets(sysroot: &Path, mut f: F) { + let target_dir = sysroot.join("lib").join("rustlib"); + println!("target dir: {}", target_dir.to_str().unwrap()); + for entry in std::fs::read_dir(target_dir).expect("invalid sysroot") { let entry = entry.unwrap(); if !is_target_dir(entry.path()) { continue; } let target = entry.file_name().into_string().unwrap(); @@ -55,20 +65,27 @@ fn for_all_targets(sysroot: &str, mut f: F) { #[test] fn compile_test() { - // Taken from https://github.com/Manishearth/rust-clippy/pull/911. - let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME")); - let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN")); - let sysroot = match (home, toolchain) { - (Some(home), Some(toolchain)) => format!("{}/toolchains/{}", home, toolchain), - _ => option_env!("RUST_SYSROOT") - .expect("need to specify RUST_SYSROOT env var or use rustup or multirust") - .to_owned(), - }; + let sysroot = std::process::Command::new("rustc") + .arg("--print") + .arg("sysroot") + .output() + .expect("rustc not found") + .stdout; + let sysroot = std::str::from_utf8(&sysroot).expect("sysroot is not utf8").trim(); + let sysroot = &Path::new(&sysroot); + let host = std::process::Command::new("rustc") + .arg("-vV") + .output() + .expect("rustc not found for -vV") + .stdout; + let host = std::str::from_utf8(&host).expect("sysroot is not utf8"); + let host = host.split("\nhost: ").skip(1).next().expect("no host: part in rustc -vV"); + let host = host.split("\n").next().expect("no \n after host"); run_pass(); for_all_targets(&sysroot, |target| { - miri_pass("tests/run-pass", &target); + miri_pass("tests/run-pass", &target, host); if let Ok(path) = std::env::var("MIRI_RUSTC_TEST") { - miri_pass(&path, &target); + miri_pass(&path, &target, host); } }); compile_fail(&sysroot); diff --git a/tests/run-pass/aux_test.rs b/tests/run-pass/aux_test.rs index 5510582e87a3..1b1dbaa68387 100644 --- a/tests/run-pass/aux_test.rs +++ b/tests/run-pass/aux_test.rs @@ -1,9 +1,8 @@ // aux-build:dep.rs +// ignore-cross-compile -// FIXME: Auxiliary builds are currently broken. -// extern crate dep; +extern crate dep; fn main() { - // FIXME: Auxiliary builds are currently broken. - // dep::foo(); + dep::foo(); }