Skip to content

Commit

Permalink
Switches RUSTFLAGS to CARGO_ENCODED_RUSTFLAGS
Browse files Browse the repository at this point in the history
  • Loading branch information
kupiakos committed Apr 10, 2022
1 parent 917c516 commit 7b20d96
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
18 changes: 15 additions & 3 deletions src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use util;
use sysroot::XargoMode;
use xargo::Home;

#[derive(Clone)]
pub struct Rustflags {
flags: Vec<String>,
}
Expand Down Expand Up @@ -41,18 +42,29 @@ impl Rustflags {
}
}

pub fn push(&mut self, flag: impl Into<String>) {
self.flags.push(flag.into())
}

/// Stringifies these flags for Xargo consumption
pub fn for_xargo(&self, home: &Home) -> String {
pub fn build_for_xargo(&self, home: &Home) -> String {
let mut flags = self.flags.clone();
flags.push("--sysroot".to_owned());
flags.push(home.display().to_string());
flags.join(" ")
flags.join("\x1f")
}
}

impl fmt::Display for Rustflags {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(&self.flags.join(" "), f)
let len = self.flags.len();
for (i, flag) in self.flags.iter().enumerate() {
write!(f, "'{flag}'")?;
if i < len - 1 {
f.write_str(" ")?;
}
}
Ok(())
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/sysroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,14 @@ version = "0.0.0"

let cargo = || {
let mut cmd = cargo::command();
let mut flags = rustflags.for_xargo(home);
flags.push_str(" -Z force-unstable-if-unmarked");
let mut rustflags = rustflags.clone();
rustflags.push("-Z");
rustflags.push("force-unstable-if-unmarked");
let flags = rustflags.build_for_xargo(home);
if verbose {
writeln!(io::stderr(), "+ RUSTFLAGS={:?}", flags).ok();
writeln!(io::stderr(), "+ CARGO_ENCODED_RUSTFLAGS={:?}", flags).ok();
}
cmd.env("RUSTFLAGS", flags);
cmd.env("CARGO_ENCODED_RUSTFLAGS", flags);

// Since we currently don't want to respect `.cargo/config` or `CARGO_TARGET_DIR`,
// we need to force the target directory to match the `cp_r` below.
Expand Down
8 changes: 4 additions & 4 deletions src/xargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ pub fn run(

if args.subcommand() == Some(Subcommand::Doc) {
cmd.env(
"RUSTDOCFLAGS",
"CARGO_ENCODED_RUSTDOCFLAGS",
cargo::rustdocflags(config, cmode.triple())?.for_xargo(home),
);
}

let flags = rustflags.for_xargo(home);
let flags = rustflags.build_for_xargo(home);
if verbose {
writeln!(io::stderr(), "+ RUSTFLAGS={:?}", flags).ok();
writeln!(io::stderr(), "+ CARGO_ENCODED_RUSTFLAGS={:?}", flags).ok();
}
cmd.env("RUSTFLAGS", flags);
cmd.env("CARGO_ENCODED_RUSTFLAGS", flags);

let locks = (home.lock_ro(&meta.host), home.lock_ro(cmode.triple()));

Expand Down

3 comments on commit 7b20d96

@kupiakos
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, the goal is for this to fix japaric#206 / rust-lang/cargo#6139. Looks like there could be something else tripping up on a space? cargo test works just fine:

PS C:\Users\Alyssa Haroldsen\Documents\git\munge> cargo +nightly-2022-04-03 miri test
    Finished test [unoptimized + debuginfo] target(s) in 0.05s
     Running unittests src\lib.rs (target\miri\x86_64-pc-windows-msvc\debug\deps\munge-d8087f9e75a37dbf.exe)
error: test failed, to rerun pass '--lib'

Caused by:
  could not execute process `C:\Users\Alyssa Haroldsen\.rustup\toolchains\nightly-2022-04-03-x86_64-pc-windows-msvc\bin\cargo-miri.exe "C:\Users\Alyssa Haroldsen\Documents\git\munge\target\miri\x86_64-pc-windows-msvc\debug\deps\munge-d8087f9e75a37dbf.exe"` (never executed)

@kupiakos
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opening up cmd and using the (DOS) short path didn't work, until I set USERPROFILE and then the test was successful:

C:\Users\ALYSSA~2\Documents\git\munge>cargo +nightly-2022-04-03 miri test
    Finished test [unoptimized + debuginfo] target(s) in 0.05s
     Running unittests src\lib.rs (target\miri\x86_64-pc-windows-msvc\debug\deps\munge-d8087f9e75a37dbf.exe)
error: test failed, to rerun pass '--lib'

Caused by:
  could not execute process `C:\Users\Alyssa Haroldsen\.rustup\toolchains\nightly-2022-04-03-x86_64-pc-windows-msvc\bin\cargo-miri.exe
C:\Users\ALYSSA~2\Documents\git\munge\target\miri\x86_64-pc-windows-msvc\debug\deps\munge-d8087f9e75a37dbf.exe` (never executed)
C:\Users\ALYSSA~2\Documents\git\munge>set USERPROFILE=C:\Users\ALYSSA~2
C:\Users\ALYSSA~2\Documents\git\munge>set HOMEPATH=\Users\ALYSSA~2
C:\Users\ALYSSA~2\Documents\git\munge>cargo build
    Finished dev [unoptimized + debuginfo] target(s) in 0.50s
C:\Users\ALYSSA~2\Documents\git\munge>cargo +nightly-2022-04-03 miri test
...
test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.31s

@RalfJung
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I just saw this, after basically reimplementing it in japaric#336. Would have been nice to make a PR and avoid duplicate work. :)

Please sign in to comment.