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
This commit is contained in:
bors 2020-07-16 17:12:38 +00:00
commit 136348497d
2 changed files with 52 additions and 9 deletions

View File

@ -348,6 +348,7 @@ pub struct CliUnstable {
pub mtime_on_use: bool,
pub named_profiles: bool,
pub binary_dep_depinfo: bool,
#[serde(deserialize_with = "deserialize_build_std")]
pub build_std: Option<Vec<String>>,
pub timings: Option<Vec<String>>,
pub doctest_xcompile: bool,
@ -361,6 +362,20 @@ pub struct CliUnstable {
pub terminal_width: Option<Option<usize>>,
}
fn deserialize_build_std<'de, D>(deserializer: D) -> Result<Option<Vec<String>>, D::Error>
where
D: serde::Deserializer<'de>,
{
let crates = match <Option<Vec<String>>>::deserialize(deserializer)? {
Some(list) => list,
None => return Ok(None),
};
let v = crates.join(",");
Ok(Some(
crate::core::compiler::standard_lib::parse_unstable_flag(Some(&v)),
))
}
impl CliUnstable {
pub fn parse(&mut self, flags: &[String]) -> CargoResult<()> {
if !flags.is_empty() && !nightly_features_allowed() {

View File

@ -128,7 +128,7 @@ fn setup() -> Option<Setup> {
})
}
fn enable_build_std(e: &mut Execs, setup: &Setup, arg: Option<&str>) {
fn enable_build_std(e: &mut Execs, setup: &Setup) {
// First up, force Cargo to use our "mock sysroot" which mimics what
// libstd looks like upstream.
let root = paths::root();
@ -142,12 +142,6 @@ fn enable_build_std(e: &mut Execs, setup: &Setup, arg: Option<&str>) {
.join("tests/testsuite/mock-std");
e.env("__CARGO_TESTS_ONLY_SRC_ROOT", &root);
// Actually enable `-Zbuild-std` for now
let arg = match arg {
Some(s) => format!("-Zbuild-std={}", s),
None => "-Zbuild-std".to_string(),
};
e.arg(arg);
e.masquerade_as_nightly_cargo();
// We do various shenanigans to ensure our "mock sysroot" actually links
@ -181,12 +175,14 @@ trait BuildStd: Sized {
impl BuildStd for Execs {
fn build_std(&mut self, setup: &Setup) -> &mut Self {
enable_build_std(self, setup, None);
enable_build_std(self, setup);
self.arg("-Zbuild-std");
self
}
fn build_std_arg(&mut self, setup: &Setup, arg: &str) -> &mut Self {
enable_build_std(self, setup, Some(arg));
enable_build_std(self, setup);
self.arg(format!("-Zbuild-std={}", arg));
self
}
@ -604,3 +600,35 @@ fn ignores_incremental() {
.unwrap()
.starts_with("foo-"));
}
#[cargo_test]
fn cargo_config_injects_compiler_builtins() {
let setup = match setup() {
Some(s) => s,
None => return,
};
let p = project()
.file(
"src/lib.rs",
r#"
#![no_std]
pub fn foo() {
assert_eq!(u8::MIN, 0);
}
"#,
)
.file(
".cargo/config.toml",
r#"
[unstable]
build-std = ['core']
"#,
)
.build();
let mut build = p.cargo("build -v --lib");
enable_build_std(&mut build, &setup);
build
.target_host()
.with_stderr_does_not_contain("[..]libstd[..]")
.run();
}