Skip to content

Commit 1363484

Browse files
committed
Auto merge of #8491 - alexcrichton:fix-unstable-build-std-config, r=Eh2406
Ensure `unstable.build-std` works like `-Zbuild-std` This fixes an issue where the deserializer for `-Zbuild-std` was a bit fancier than the `unstable.build-std` directive. cc #8393
2 parents e37b35c + 78314ca commit 1363484

File tree

2 files changed

+52
-9
lines changed

2 files changed

+52
-9
lines changed

src/cargo/core/features.rs

+15
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ pub struct CliUnstable {
348348
pub mtime_on_use: bool,
349349
pub named_profiles: bool,
350350
pub binary_dep_depinfo: bool,
351+
#[serde(deserialize_with = "deserialize_build_std")]
351352
pub build_std: Option<Vec<String>>,
352353
pub timings: Option<Vec<String>>,
353354
pub doctest_xcompile: bool,
@@ -361,6 +362,20 @@ pub struct CliUnstable {
361362
pub terminal_width: Option<Option<usize>>,
362363
}
363364

365+
fn deserialize_build_std<'de, D>(deserializer: D) -> Result<Option<Vec<String>>, D::Error>
366+
where
367+
D: serde::Deserializer<'de>,
368+
{
369+
let crates = match <Option<Vec<String>>>::deserialize(deserializer)? {
370+
Some(list) => list,
371+
None => return Ok(None),
372+
};
373+
let v = crates.join(",");
374+
Ok(Some(
375+
crate::core::compiler::standard_lib::parse_unstable_flag(Some(&v)),
376+
))
377+
}
378+
364379
impl CliUnstable {
365380
pub fn parse(&mut self, flags: &[String]) -> CargoResult<()> {
366381
if !flags.is_empty() && !nightly_features_allowed() {

tests/testsuite/standard_lib.rs

+37-9
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ fn setup() -> Option<Setup> {
128128
})
129129
}
130130

131-
fn enable_build_std(e: &mut Execs, setup: &Setup, arg: Option<&str>) {
131+
fn enable_build_std(e: &mut Execs, setup: &Setup) {
132132
// First up, force Cargo to use our "mock sysroot" which mimics what
133133
// libstd looks like upstream.
134134
let root = paths::root();
@@ -142,12 +142,6 @@ fn enable_build_std(e: &mut Execs, setup: &Setup, arg: Option<&str>) {
142142
.join("tests/testsuite/mock-std");
143143
e.env("__CARGO_TESTS_ONLY_SRC_ROOT", &root);
144144

145-
// Actually enable `-Zbuild-std` for now
146-
let arg = match arg {
147-
Some(s) => format!("-Zbuild-std={}", s),
148-
None => "-Zbuild-std".to_string(),
149-
};
150-
e.arg(arg);
151145
e.masquerade_as_nightly_cargo();
152146

153147
// We do various shenanigans to ensure our "mock sysroot" actually links
@@ -181,12 +175,14 @@ trait BuildStd: Sized {
181175

182176
impl BuildStd for Execs {
183177
fn build_std(&mut self, setup: &Setup) -> &mut Self {
184-
enable_build_std(self, setup, None);
178+
enable_build_std(self, setup);
179+
self.arg("-Zbuild-std");
185180
self
186181
}
187182

188183
fn build_std_arg(&mut self, setup: &Setup, arg: &str) -> &mut Self {
189-
enable_build_std(self, setup, Some(arg));
184+
enable_build_std(self, setup);
185+
self.arg(format!("-Zbuild-std={}", arg));
190186
self
191187
}
192188

@@ -604,3 +600,35 @@ fn ignores_incremental() {
604600
.unwrap()
605601
.starts_with("foo-"));
606602
}
603+
604+
#[cargo_test]
605+
fn cargo_config_injects_compiler_builtins() {
606+
let setup = match setup() {
607+
Some(s) => s,
608+
None => return,
609+
};
610+
let p = project()
611+
.file(
612+
"src/lib.rs",
613+
r#"
614+
#![no_std]
615+
pub fn foo() {
616+
assert_eq!(u8::MIN, 0);
617+
}
618+
"#,
619+
)
620+
.file(
621+
".cargo/config.toml",
622+
r#"
623+
[unstable]
624+
build-std = ['core']
625+
"#,
626+
)
627+
.build();
628+
let mut build = p.cargo("build -v --lib");
629+
enable_build_std(&mut build, &setup);
630+
build
631+
.target_host()
632+
.with_stderr_does_not_contain("[..]libstd[..]")
633+
.run();
634+
}

0 commit comments

Comments
 (0)