Skip to content

Commit 9979db5

Browse files
committed
Fix passing of RUSTFLAGS with spaces
1 parent 9e1971e commit 9979db5

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

Diff for: src/cargo/mod.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
use anyhow::Context;
2-
use cargo_remark::RustcSourceRoot;
31
use std::path::{Path, PathBuf};
42
use std::process::{Command, Stdio};
53

6-
use cargo_remark::utils::io::ensure_directory;
4+
use anyhow::Context;
75

86
use cargo_remark::utils::cli::cli_format_path;
7+
use cargo_remark::utils::io::ensure_directory;
8+
use cargo_remark::RustcSourceRoot;
99

1010
pub mod version;
1111

@@ -53,8 +53,9 @@ pub fn run_cargo(subcmd: CargoSubcommand, cargo_args: Vec<String>) -> anyhow::Re
5353
}
5454
};
5555

56+
// Use CARGO_ENCODED_RUSTFLAGS to make sure that paths with spaces work.
5657
let flags = format!(
57-
"-Cremark=all -Zremark-dir={} -Cdebuginfo=1",
58+
"-Cremark=all\u{001f}-Zremark-dir={}\u{001f}-Cdebuginfo=1",
5859
yaml_dir.display()
5960
);
6061
set_cargo_env(&mut cmd, &flags);
@@ -92,12 +93,13 @@ pub fn get_rustc_source_root() -> anyhow::Result<RustcSourceRoot> {
9293
}
9394

9495
fn set_cargo_env(command: &mut Command, flags: &str) {
95-
use std::fmt::Write;
96-
97-
let mut rustflags = std::env::var("RUSTFLAGS").unwrap_or_default();
98-
write!(&mut rustflags, " {}", flags).unwrap();
96+
let mut rustflags = std::env::var("CARGO_ENCODED_RUSTFLAGS").unwrap_or_default();
97+
if !rustflags.is_empty() {
98+
rustflags.push('\u{001f}');
99+
}
100+
rustflags.push_str(flags);
99101

100-
command.env("RUSTFLAGS", rustflags);
102+
command.env("CARGO_ENCODED_RUSTFLAGS", rustflags);
101103
}
102104

103105
#[derive(Debug, Default)]

0 commit comments

Comments
 (0)