From 32cd8efb977b0edec1ddbd1efa2db49dad6faf89 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Mon, 19 Dec 2016 15:46:03 +0100 Subject: [PATCH 01/10] re-enable auxiliary tests for the host only --- src/bin/miri.rs | 11 ++++++++++- tests/compiletest.rs | 14 +++++++++++--- tests/run-pass/aux_test.rs | 7 +++---- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/bin/miri.rs b/src/bin/miri.rs index 379f25ef757..56c2e433d06 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/compiletest.rs b/tests/compiletest.rs index 50970086ee5..90a40d8e39b 100644 --- a/tests/compiletest.rs +++ b/tests/compiletest.rs @@ -27,13 +27,20 @@ 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.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 { @@ -65,10 +72,11 @@ fn compile_test() { .to_owned(), }; run_pass(); + let host = toolchain.unwrap().splitn(2, '-').skip(1).next().unwrap(); 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 5510582e87a..1b1dbaa6838 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(); } From 5d7b92a6e3880326118b2c903529dac96e033573 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Mon, 19 Dec 2016 15:59:32 +0100 Subject: [PATCH 02/10] fix travis --- tests/compiletest.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/compiletest.rs b/tests/compiletest.rs index 90a40d8e39b..2d0e65c4c00 100644 --- a/tests/compiletest.rs +++ b/tests/compiletest.rs @@ -72,7 +72,14 @@ fn compile_test() { .to_owned(), }; run_pass(); - let host = toolchain.unwrap().splitn(2, '-').skip(1).next().unwrap(); + let host = Path::new(&sysroot).file_name() + .unwrap() + .to_str() + .unwrap() + .splitn(2, '-') + .skip(1) + .next() + .unwrap(); for_all_targets(&sysroot, |target| { miri_pass("tests/run-pass", &target, host); if let Ok(path) = std::env::var("MIRI_RUSTC_TEST") { From 1f40819315fa8df4d609a619e428f1ef75eb46c2 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Tue, 20 Dec 2016 09:05:46 +0100 Subject: [PATCH 03/10] try to pin down the travis failure --- tests/compiletest.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/compiletest.rs b/tests/compiletest.rs index 2d0e65c4c00..09b31b71bbc 100644 --- a/tests/compiletest.rs +++ b/tests/compiletest.rs @@ -73,13 +73,13 @@ fn compile_test() { }; run_pass(); let host = Path::new(&sysroot).file_name() - .unwrap() + .expect("sysroot has no last par") .to_str() - .unwrap() + .expect("sysroot contains non utf8") .splitn(2, '-') .skip(1) .next() - .unwrap(); + .expect("target dir not prefixed"); for_all_targets(&sysroot, |target| { miri_pass("tests/run-pass", &target, host); if let Ok(path) = std::env::var("MIRI_RUSTC_TEST") { From 2f51310a80900364de3efe875d04cada346b85f5 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Tue, 20 Dec 2016 09:58:41 +0100 Subject: [PATCH 04/10] clamp down on hacks in compiletest --- tests/compiletest.rs | 45 ++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/tests/compiletest.rs b/tests/compiletest.rs index 09b31b71bbc..ae55c1adb5c 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"); @@ -49,8 +49,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(); @@ -62,24 +64,23 @@ 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(); - let host = Path::new(&sysroot).file_name() - .expect("sysroot has no last par") - .to_str() - .expect("sysroot contains non utf8") - .splitn(2, '-') - .skip(1) - .next() - .expect("target dir not prefixed"); for_all_targets(&sysroot, |target| { miri_pass("tests/run-pass", &target, host); if let Ok(path) = std::env::var("MIRI_RUSTC_TEST") { From 3084aa8052f469024848957809beee20890cb581 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Tue, 10 Jan 2017 10:04:53 +0100 Subject: [PATCH 05/10] test more targets on travis --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index e76a2f86cf9..3aa1b51497b 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 +- rustup target add i686-unknown-linux-gnu +- rustup target add i686-pc-windows-gnu +- rustup target add i686-pc-windows-msvc script: - | env RUST_SYSROOT=$HOME/rust travis-cargo build && From f47aa03f6fce571e43d5a1606c41a1cea37dee50 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Tue, 10 Jan 2017 10:45:33 +0100 Subject: [PATCH 06/10] analyze travis --- .travis.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3aa1b51497b..ed0363dcc9e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,9 +5,10 @@ before_script: - | pip install 'travis-cargo<0.2' --user && export PATH=$HOME/.local/bin:$PATH -- rustup target add i686-unknown-linux-gnu -- rustup target add i686-pc-windows-gnu -- rustup target add i686-pc-windows-msvc +- ls -lh ~/rust +- ~/rust/rustup target add i686-unknown-linux-gnu +- ~/rust/rustup target add i686-pc-windows-gnu +- ~/rust/rustup target add i686-pc-windows-msvc script: - | env RUST_SYSROOT=$HOME/rust travis-cargo build && From 421b537f80d3557d42e7be5f370b65484f08961d Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Tue, 10 Jan 2017 12:50:27 +0100 Subject: [PATCH 07/10] travis fix --- .travis.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index ed0363dcc9e..fefa37b7fec 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,10 +5,9 @@ before_script: - | pip install 'travis-cargo<0.2' --user && export PATH=$HOME/.local/bin:$PATH -- ls -lh ~/rust -- ~/rust/rustup target add i686-unknown-linux-gnu -- ~/rust/rustup target add i686-pc-windows-gnu -- ~/rust/rustup target add i686-pc-windows-msvc +- 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 p-y --disable-sudo script: - | env RUST_SYSROOT=$HOME/rust travis-cargo build && From ae7d69a5bd5767620c0d48fd81e3fbab18d200de Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Mon, 19 Dec 2016 15:47:52 +0100 Subject: [PATCH 08/10] msvc has different internals for mutexes and thus fails on a different function --- tests/compile-fail/send-is-not-static-par-for.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 bee05ecd7fa..afb401a919e 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; From ccfcc12a580aa27fc8b99c6ec262e82d74629457 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Thu, 12 Jan 2017 08:45:09 +0100 Subject: [PATCH 09/10] aux tests only run if the host is set --- tests/compiletest.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/compiletest.rs b/tests/compiletest.rs index ae55c1adb5c..909538494e8 100644 --- a/tests/compiletest.rs +++ b/tests/compiletest.rs @@ -32,6 +32,7 @@ fn miri_pass(path: &str, target: &str, host: &str) { 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. From 3ee34381b63a55837cb6c3834b969a281da6877c Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Thu, 12 Jan 2017 08:53:03 +0100 Subject: [PATCH 10/10] remove typo --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index fefa37b7fec..91e6255f33c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,7 @@ before_script: 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 p-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 &&