Skip to content

Commit 149aa21

Browse files
authored
fix(build-std): parse as comma-separated list (#15065)
### What does this PR try to resolve? Restore to the behavior prior to 30d11ce Also extend `build-std-features` to support comma-separated list. Fixes #15064 ### How should we test and review this PR? A test has been added.
2 parents ac22fd3 + 93c764d commit 149aa21

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed

src/cargo/core/features.rs

+20
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,9 @@ unstable_cli_options!(
759759
avoid_dev_deps: bool = ("Avoid installing dev-dependencies if possible"),
760760
binary_dep_depinfo: bool = ("Track changes to dependency artifacts"),
761761
bindeps: bool = ("Allow Cargo packages to depend on bin, cdylib, and staticlib crates, and use the artifacts built by those crates"),
762+
#[serde(deserialize_with = "deserialize_comma_separated_list")]
762763
build_std: Option<Vec<String>> = ("Enable Cargo to compile the standard library itself as part of a crate graph compilation"),
764+
#[serde(deserialize_with = "deserialize_comma_separated_list")]
763765
build_std_features: Option<Vec<String>> = ("Configure features enabled for the standard library itself when building the standard library"),
764766
cargo_lints: bool = ("Enable the `[lints.cargo]` table"),
765767
checksum_freshness: bool = ("Use a checksum to determine if output is fresh rather than filesystem mtime"),
@@ -872,6 +874,24 @@ const STABILIZED_LINTS: &str = "The `[lints]` table is now always available.";
872874
const STABILIZED_CHECK_CFG: &str =
873875
"Compile-time checking of conditional (a.k.a. `-Zcheck-cfg`) is now always enabled.";
874876

877+
fn deserialize_comma_separated_list<'de, D>(
878+
deserializer: D,
879+
) -> Result<Option<Vec<String>>, D::Error>
880+
where
881+
D: serde::Deserializer<'de>,
882+
{
883+
let Some(list) = <Option<Vec<String>>>::deserialize(deserializer)? else {
884+
return Ok(None);
885+
};
886+
let v = list
887+
.iter()
888+
.flat_map(|s| s.split(','))
889+
.filter(|s| !s.is_empty())
890+
.map(String::from)
891+
.collect();
892+
Ok(Some(v))
893+
}
894+
875895
#[derive(Debug, Copy, Clone, Default, Deserialize, Ord, PartialOrd, Eq, PartialEq)]
876896
#[serde(default)]
877897
pub struct GitFeatures {

tests/testsuite/config.rs

+78
Original file line numberDiff line numberDiff line change
@@ -2163,3 +2163,81 @@ gitoxide = \"fetch\"
21632163
unstable_flags.gitoxide == expect
21642164
}
21652165
}
2166+
2167+
#[cargo_test]
2168+
fn build_std() {
2169+
let gctx = GlobalContextBuilder::new()
2170+
.env("CARGO_UNSTABLE_BUILD_STD", "core,std,panic_abort")
2171+
.build();
2172+
let value = gctx
2173+
.get::<Option<cargo::core::CliUnstable>>("unstable")
2174+
.unwrap()
2175+
.unwrap()
2176+
.build_std
2177+
.unwrap();
2178+
assert_eq!(
2179+
value,
2180+
vec![
2181+
"core".to_string(),
2182+
"std".to_string(),
2183+
"panic_abort".to_string(),
2184+
],
2185+
);
2186+
2187+
let gctx = GlobalContextBuilder::new()
2188+
.config_arg("unstable.build-std=['core', 'std,panic_abort']")
2189+
.build();
2190+
let value = gctx
2191+
.get::<Option<cargo::core::CliUnstable>>("unstable")
2192+
.unwrap()
2193+
.unwrap()
2194+
.build_std
2195+
.unwrap();
2196+
assert_eq!(
2197+
value,
2198+
vec![
2199+
"core".to_string(),
2200+
"std".to_string(),
2201+
"panic_abort".to_string(),
2202+
]
2203+
);
2204+
2205+
let gctx = GlobalContextBuilder::new()
2206+
.env(
2207+
"CARGO_UNSTABLE_BUILD_STD_FEATURES",
2208+
"backtrace,panic-unwind,windows_raw_dylib",
2209+
)
2210+
.build();
2211+
let value = gctx
2212+
.get::<Option<cargo::core::CliUnstable>>("unstable")
2213+
.unwrap()
2214+
.unwrap()
2215+
.build_std_features
2216+
.unwrap();
2217+
assert_eq!(
2218+
value,
2219+
vec![
2220+
"backtrace".to_string(),
2221+
"panic-unwind".to_string(),
2222+
"windows_raw_dylib".to_string(),
2223+
]
2224+
);
2225+
2226+
let gctx = GlobalContextBuilder::new()
2227+
.config_arg("unstable.build-std-features=['backtrace', 'panic-unwind,windows_raw_dylib']")
2228+
.build();
2229+
let value = gctx
2230+
.get::<Option<cargo::core::CliUnstable>>("unstable")
2231+
.unwrap()
2232+
.unwrap()
2233+
.build_std_features
2234+
.unwrap();
2235+
assert_eq!(
2236+
value,
2237+
vec![
2238+
"backtrace".to_string(),
2239+
"panic-unwind".to_string(),
2240+
"windows_raw_dylib".to_string(),
2241+
]
2242+
);
2243+
}

0 commit comments

Comments
 (0)