From ac2f6cbcde00eebcb696143e76177c1600f63410 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 14 Jun 2019 11:15:09 +0200 Subject: [PATCH 1/4] change sysroot check to print the output in case of an error --- src/bin/cargo-miri.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/bin/cargo-miri.rs b/src/bin/cargo-miri.rs index 121930bccce6..3b7af9324194 100644 --- a/src/bin/cargo-miri.rs +++ b/src/bin/cargo-miri.rs @@ -133,11 +133,12 @@ fn test_sysroot_consistency() { fn get_sysroot(mut cmd: Command) -> PathBuf { let out = cmd.arg("--print").arg("sysroot") .output().expect("Failed to run rustc to get sysroot info"); - assert!(out.status.success(), "Bad status code when getting sysroot info"); - let sysroot = out.stdout.lines().nth(0) - .expect("didn't get at least one line for the sysroot").unwrap(); - PathBuf::from(sysroot).canonicalize() - .expect("Failed to canonicalize sysroot") + let stdout = String::from_utf8(out.stdout).expect("stdout is not valid UTF-8"); + let stderr = String::from_utf8(out.stderr).expect("stderr is not valid UTF-8"); + let stdout = stdout.trim(); + assert!(out.status.success(), "Bad status code when getting sysroot info.\nstdout:\n{}\nstderr:\n{}", stdout, stderr); + PathBuf::from(stdout).canonicalize() + .unwrap_or_else(|_| panic!("Failed to canonicalize sysroot: {}", stdout)) } let rustc_sysroot = get_sysroot(Command::new("rustc")); From 34b0922cec2eac41c7c204ca234fcd4a85b08615 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 14 Jun 2019 12:09:43 +0200 Subject: [PATCH 2/4] fix running a Miri that was built in bootstrap --- src/bin/miri.rs | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/src/bin/miri.rs b/src/bin/miri.rs index 6346b2340b08..5a425baf0f61 100644 --- a/src/bin/miri.rs +++ b/src/bin/miri.rs @@ -102,21 +102,26 @@ fn init_late_loggers() { /// Returns the "default sysroot" that Miri will use if no `--sysroot` flag is set. /// Should be a compile-time constant. -fn compile_time_sysroot() -> String { +fn compile_time_sysroot() -> Option { + if option_env!("RUSTC_STAGE").is_some() { + // This is being built as part of rustc, and gets shipped with rustup. + // We can rely on the sysroot computation in librustc. + return None; + } + // For builds outside rustc, we need to ensure that we got a sysroot + // that gets used as a default. The sysroot computation in librustc would + // end up somewhere in the build dir. // Taken from PR . let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME")); let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN")); - match (home, toolchain) { + Some(match (home, toolchain) { (Some(home), Some(toolchain)) => format!("{}/toolchains/{}", home, toolchain), _ => { option_env!("RUST_SYSROOT") - .expect( - "could not find sysroot. Either set `MIRI_SYSROOT` at run-time, or at \ - build-time specify `RUST_SYSROOT` env var or use rustup or multirust", - ) + .expect("To build Miri without rustup, set the `RUST_SYSROOT` env var at build time") .to_owned() } - } + }) } fn main() { @@ -165,14 +170,17 @@ fn main() { } } - // Determine sysroot. - let sysroot_flag = "--sysroot".to_string(); - if !rustc_args.contains(&sysroot_flag) { - // We need to *always* set a --sysroot, as the "default" rustc uses is - // somewhere in the directory miri was built in. - // If no --sysroot is given, fall back to env vars that are read at *compile-time*. - rustc_args.push(sysroot_flag); - rustc_args.push(compile_time_sysroot()); + // Determine sysroot if needed. Make sure we always call `compile_time_sysroot` + // as that also does some sanity-checks of the environment we were built in. + // FIXME: Ideally we'd turn a bad build env into a compile-time error, but + // CTFE does not seem powerful enough for that yet. + if let Some(sysroot) = compile_time_sysroot() { + let sysroot_flag = "--sysroot".to_string(); + if !rustc_args.contains(&sysroot_flag) { + // We need to overwrite the default that librustc would compute. + rustc_args.push(sysroot_flag); + rustc_args.push(sysroot); + } } // Finally, add the default flags all the way in the beginning, but after the binary name. From fd0dccd4b12169e0aac42aff8addbb26b6d72197 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Sat, 15 Jun 2019 02:34:11 +0700 Subject: [PATCH 3/4] Fix wrong lifetime of TyCtxt Rustup rust-lang/rust#61817 --- rust-version | 2 +- src/bin/miri-rustc-tests.rs | 2 +- src/lib.rs | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/rust-version b/rust-version index b945d0b3a265..e60eb6c94954 100644 --- a/rust-version +++ b/rust-version @@ -1 +1 @@ -d8f50ab0ea6c529c24e575279acc72093caeb679 +9606f6fa64926a84d82e3c62dbdc57f5c10f756d diff --git a/src/bin/miri-rustc-tests.rs b/src/bin/miri-rustc-tests.rs index e8714123ceb0..9b0d02f4b7e2 100644 --- a/src/bin/miri-rustc-tests.rs +++ b/src/bin/miri-rustc-tests.rs @@ -43,7 +43,7 @@ impl rustc_driver::Callbacks for MiriCompilerCalls { compiler.session().abort_if_errors(); compiler.global_ctxt().unwrap().peek_mut().enter(|tcx| { if std::env::args().any(|arg| arg == "--test") { - struct Visitor<'tcx>(TyCtxt<'tcx, 'tcx>); + struct Visitor<'tcx>(TyCtxt<'tcx>); impl<'tcx, 'hir> itemlikevisit::ItemLikeVisitor<'hir> for Visitor<'tcx> { fn visit_item(&mut self, i: &'hir hir::Item) { if let hir::ItemKind::Fn(.., body_id) = i.node { diff --git a/src/lib.rs b/src/lib.rs index 822b173e34a0..061b07478a28 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -72,7 +72,7 @@ pub struct MiriConfig { // Used by priroda. pub fn create_ecx<'mir, 'tcx: 'mir>( - tcx: TyCtxt<'tcx, 'tcx>, + tcx: TyCtxt<'tcx>, main_id: DefId, config: MiriConfig, ) -> InterpResult<'tcx, InterpretCx<'mir, 'tcx, Evaluator<'tcx>>> { @@ -212,7 +212,7 @@ pub fn create_ecx<'mir, 'tcx: 'mir>( } pub fn eval_main<'tcx>( - tcx: TyCtxt<'tcx, 'tcx>, + tcx: TyCtxt<'tcx>, main_id: DefId, config: MiriConfig, ) { @@ -475,7 +475,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> { fn find_foreign_static( def_id: DefId, - tcx: TyCtxtAt<'tcx, 'tcx>, + tcx: TyCtxtAt<'tcx>, ) -> InterpResult<'tcx, Cow<'tcx, Allocation>> { let attrs = tcx.get_attrs(def_id); let link_name = match attr::first_attr_value_str_by_name(&attrs, sym::link_name) { From d210ed7e122632b0904f8c077b94459fda92012f Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 16 Jun 2019 09:49:27 +0200 Subject: [PATCH 4/4] bump rustc yet again --- rust-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-version b/rust-version index e60eb6c94954..9d2a8772234b 100644 --- a/rust-version +++ b/rust-version @@ -1 +1 @@ -9606f6fa64926a84d82e3c62dbdc57f5c10f756d +374c63e0fc356eb61b1966cb6026a2a49fe9226d