Skip to content

Commit 93c764d

Browse files
weihangloehuss
authored andcommitted
fix(build-std): parse as comma-separated list
Restore to the behavior prior to 30d11ce Also extend `build-std-features` to support comma-separated list.
1 parent ffe841c commit 93c764d

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
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

+20-4
Original file line numberDiff line numberDiff line change
@@ -2175,7 +2175,14 @@ fn build_std() {
21752175
.unwrap()
21762176
.build_std
21772177
.unwrap();
2178-
assert_eq!(value, vec!["core,std,panic_abort".to_string()]);
2178+
assert_eq!(
2179+
value,
2180+
vec![
2181+
"core".to_string(),
2182+
"std".to_string(),
2183+
"panic_abort".to_string(),
2184+
],
2185+
);
21792186

21802187
let gctx = GlobalContextBuilder::new()
21812188
.config_arg("unstable.build-std=['core', 'std,panic_abort']")
@@ -2188,7 +2195,11 @@ fn build_std() {
21882195
.unwrap();
21892196
assert_eq!(
21902197
value,
2191-
vec!["core".to_string(), "std,panic_abort".to_string()]
2198+
vec![
2199+
"core".to_string(),
2200+
"std".to_string(),
2201+
"panic_abort".to_string(),
2202+
]
21922203
);
21932204

21942205
let gctx = GlobalContextBuilder::new()
@@ -2205,7 +2216,11 @@ fn build_std() {
22052216
.unwrap();
22062217
assert_eq!(
22072218
value,
2208-
vec!["backtrace,panic-unwind,windows_raw_dylib".to_string()]
2219+
vec![
2220+
"backtrace".to_string(),
2221+
"panic-unwind".to_string(),
2222+
"windows_raw_dylib".to_string(),
2223+
]
22092224
);
22102225

22112226
let gctx = GlobalContextBuilder::new()
@@ -2221,7 +2236,8 @@ fn build_std() {
22212236
value,
22222237
vec![
22232238
"backtrace".to_string(),
2224-
"panic-unwind,windows_raw_dylib".to_string()
2239+
"panic-unwind".to_string(),
2240+
"windows_raw_dylib".to_string(),
22252241
]
22262242
);
22272243
}

0 commit comments

Comments
 (0)