Skip to content

Commit 32a2cf0

Browse files
authored
Merge branch 'master' into foreign_math_functions
2 parents 4db0eea + 7fc182c commit 32a2cf0

File tree

5 files changed

+34
-25
lines changed

5 files changed

+34
-25
lines changed

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
d8f50ab0ea6c529c24e575279acc72093caeb679
1+
374c63e0fc356eb61b1966cb6026a2a49fe9226d

src/bin/cargo-miri.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,12 @@ fn test_sysroot_consistency() {
133133
fn get_sysroot(mut cmd: Command) -> PathBuf {
134134
let out = cmd.arg("--print").arg("sysroot")
135135
.output().expect("Failed to run rustc to get sysroot info");
136-
assert!(out.status.success(), "Bad status code when getting sysroot info");
137-
let sysroot = out.stdout.lines().nth(0)
138-
.expect("didn't get at least one line for the sysroot").unwrap();
139-
PathBuf::from(sysroot).canonicalize()
140-
.expect("Failed to canonicalize sysroot")
136+
let stdout = String::from_utf8(out.stdout).expect("stdout is not valid UTF-8");
137+
let stderr = String::from_utf8(out.stderr).expect("stderr is not valid UTF-8");
138+
let stdout = stdout.trim();
139+
assert!(out.status.success(), "Bad status code when getting sysroot info.\nstdout:\n{}\nstderr:\n{}", stdout, stderr);
140+
PathBuf::from(stdout).canonicalize()
141+
.unwrap_or_else(|_| panic!("Failed to canonicalize sysroot: {}", stdout))
141142
}
142143

143144
let rustc_sysroot = get_sysroot(Command::new("rustc"));

src/bin/miri-rustc-tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl rustc_driver::Callbacks for MiriCompilerCalls {
4343
compiler.session().abort_if_errors();
4444
compiler.global_ctxt().unwrap().peek_mut().enter(|tcx| {
4545
if std::env::args().any(|arg| arg == "--test") {
46-
struct Visitor<'tcx>(TyCtxt<'tcx, 'tcx>);
46+
struct Visitor<'tcx>(TyCtxt<'tcx>);
4747
impl<'tcx, 'hir> itemlikevisit::ItemLikeVisitor<'hir> for Visitor<'tcx> {
4848
fn visit_item(&mut self, i: &'hir hir::Item) {
4949
if let hir::ItemKind::Fn(.., body_id) = i.node {

src/bin/miri.rs

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -102,21 +102,26 @@ fn init_late_loggers() {
102102

103103
/// Returns the "default sysroot" that Miri will use if no `--sysroot` flag is set.
104104
/// Should be a compile-time constant.
105-
fn compile_time_sysroot() -> String {
105+
fn compile_time_sysroot() -> Option<String> {
106+
if option_env!("RUSTC_STAGE").is_some() {
107+
// This is being built as part of rustc, and gets shipped with rustup.
108+
// We can rely on the sysroot computation in librustc.
109+
return None;
110+
}
111+
// For builds outside rustc, we need to ensure that we got a sysroot
112+
// that gets used as a default. The sysroot computation in librustc would
113+
// end up somewhere in the build dir.
106114
// Taken from PR <https://github.com/Manishearth/rust-clippy/pull/911>.
107115
let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME"));
108116
let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN"));
109-
match (home, toolchain) {
117+
Some(match (home, toolchain) {
110118
(Some(home), Some(toolchain)) => format!("{}/toolchains/{}", home, toolchain),
111119
_ => {
112120
option_env!("RUST_SYSROOT")
113-
.expect(
114-
"could not find sysroot. Either set `MIRI_SYSROOT` at run-time, or at \
115-
build-time specify `RUST_SYSROOT` env var or use rustup or multirust",
116-
)
121+
.expect("To build Miri without rustup, set the `RUST_SYSROOT` env var at build time")
117122
.to_owned()
118123
}
119-
}
124+
})
120125
}
121126

122127
fn main() {
@@ -165,14 +170,17 @@ fn main() {
165170
}
166171
}
167172

168-
// Determine sysroot.
169-
let sysroot_flag = "--sysroot".to_string();
170-
if !rustc_args.contains(&sysroot_flag) {
171-
// We need to *always* set a --sysroot, as the "default" rustc uses is
172-
// somewhere in the directory miri was built in.
173-
// If no --sysroot is given, fall back to env vars that are read at *compile-time*.
174-
rustc_args.push(sysroot_flag);
175-
rustc_args.push(compile_time_sysroot());
173+
// Determine sysroot if needed. Make sure we always call `compile_time_sysroot`
174+
// as that also does some sanity-checks of the environment we were built in.
175+
// FIXME: Ideally we'd turn a bad build env into a compile-time error, but
176+
// CTFE does not seem powerful enough for that yet.
177+
if let Some(sysroot) = compile_time_sysroot() {
178+
let sysroot_flag = "--sysroot".to_string();
179+
if !rustc_args.contains(&sysroot_flag) {
180+
// We need to overwrite the default that librustc would compute.
181+
rustc_args.push(sysroot_flag);
182+
rustc_args.push(sysroot);
183+
}
176184
}
177185

178186
// Finally, add the default flags all the way in the beginning, but after the binary name.

src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub struct MiriConfig {
7272

7373
// Used by priroda.
7474
pub fn create_ecx<'mir, 'tcx: 'mir>(
75-
tcx: TyCtxt<'tcx, 'tcx>,
75+
tcx: TyCtxt<'tcx>,
7676
main_id: DefId,
7777
config: MiriConfig,
7878
) -> InterpResult<'tcx, InterpretCx<'mir, 'tcx, Evaluator<'tcx>>> {
@@ -212,7 +212,7 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
212212
}
213213

214214
pub fn eval_main<'tcx>(
215-
tcx: TyCtxt<'tcx, 'tcx>,
215+
tcx: TyCtxt<'tcx>,
216216
main_id: DefId,
217217
config: MiriConfig,
218218
) {
@@ -475,7 +475,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
475475

476476
fn find_foreign_static(
477477
def_id: DefId,
478-
tcx: TyCtxtAt<'tcx, 'tcx>,
478+
tcx: TyCtxtAt<'tcx>,
479479
) -> InterpResult<'tcx, Cow<'tcx, Allocation>> {
480480
let attrs = tcx.get_attrs(def_id);
481481
let link_name = match attr::first_attr_value_str_by_name(&attrs, sym::link_name) {

0 commit comments

Comments
 (0)