From ffe841c540aaf98353dd85da544f597e71a86aae Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Tue, 14 Jan 2025 15:39:59 -0500 Subject: [PATCH 1/2] test: verify how build-std flag be deserialized now It doesn't parse as comma-separated list. It did before #14899 --- tests/testsuite/config.rs | 62 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/tests/testsuite/config.rs b/tests/testsuite/config.rs index ddaa168eb97..a99e5c81307 100644 --- a/tests/testsuite/config.rs +++ b/tests/testsuite/config.rs @@ -2163,3 +2163,65 @@ gitoxide = \"fetch\" unstable_flags.gitoxide == expect } } + +#[cargo_test] +fn build_std() { + let gctx = GlobalContextBuilder::new() + .env("CARGO_UNSTABLE_BUILD_STD", "core,std,panic_abort") + .build(); + let value = gctx + .get::>("unstable") + .unwrap() + .unwrap() + .build_std + .unwrap(); + assert_eq!(value, vec!["core,std,panic_abort".to_string()]); + + let gctx = GlobalContextBuilder::new() + .config_arg("unstable.build-std=['core', 'std,panic_abort']") + .build(); + let value = gctx + .get::>("unstable") + .unwrap() + .unwrap() + .build_std + .unwrap(); + assert_eq!( + value, + vec!["core".to_string(), "std,panic_abort".to_string()] + ); + + let gctx = GlobalContextBuilder::new() + .env( + "CARGO_UNSTABLE_BUILD_STD_FEATURES", + "backtrace,panic-unwind,windows_raw_dylib", + ) + .build(); + let value = gctx + .get::>("unstable") + .unwrap() + .unwrap() + .build_std_features + .unwrap(); + assert_eq!( + value, + vec!["backtrace,panic-unwind,windows_raw_dylib".to_string()] + ); + + let gctx = GlobalContextBuilder::new() + .config_arg("unstable.build-std-features=['backtrace', 'panic-unwind,windows_raw_dylib']") + .build(); + let value = gctx + .get::>("unstable") + .unwrap() + .unwrap() + .build_std_features + .unwrap(); + assert_eq!( + value, + vec![ + "backtrace".to_string(), + "panic-unwind,windows_raw_dylib".to_string() + ] + ); +} From 93c764d805fe8c4a08bd8616f77646200ad7d8be Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Tue, 14 Jan 2025 15:49:06 -0500 Subject: [PATCH 2/2] fix(build-std): parse as comma-separated list Restore to the behavior prior to 30d11ce1d9f06907d1e707c4fe379ebf57305a5e Also extend `build-std-features` to support comma-separated list. --- src/cargo/core/features.rs | 20 ++++++++++++++++++++ tests/testsuite/config.rs | 24 ++++++++++++++++++++---- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/cargo/core/features.rs b/src/cargo/core/features.rs index 4e17898d6e0..774e725e07a 100644 --- a/src/cargo/core/features.rs +++ b/src/cargo/core/features.rs @@ -759,7 +759,9 @@ unstable_cli_options!( avoid_dev_deps: bool = ("Avoid installing dev-dependencies if possible"), binary_dep_depinfo: bool = ("Track changes to dependency artifacts"), bindeps: bool = ("Allow Cargo packages to depend on bin, cdylib, and staticlib crates, and use the artifacts built by those crates"), + #[serde(deserialize_with = "deserialize_comma_separated_list")] build_std: Option> = ("Enable Cargo to compile the standard library itself as part of a crate graph compilation"), + #[serde(deserialize_with = "deserialize_comma_separated_list")] build_std_features: Option> = ("Configure features enabled for the standard library itself when building the standard library"), cargo_lints: bool = ("Enable the `[lints.cargo]` table"), 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."; const STABILIZED_CHECK_CFG: &str = "Compile-time checking of conditional (a.k.a. `-Zcheck-cfg`) is now always enabled."; +fn deserialize_comma_separated_list<'de, D>( + deserializer: D, +) -> Result>, D::Error> +where + D: serde::Deserializer<'de>, +{ + let Some(list) = >>::deserialize(deserializer)? else { + return Ok(None); + }; + let v = list + .iter() + .flat_map(|s| s.split(',')) + .filter(|s| !s.is_empty()) + .map(String::from) + .collect(); + Ok(Some(v)) +} + #[derive(Debug, Copy, Clone, Default, Deserialize, Ord, PartialOrd, Eq, PartialEq)] #[serde(default)] pub struct GitFeatures { diff --git a/tests/testsuite/config.rs b/tests/testsuite/config.rs index a99e5c81307..6fe1172cd8e 100644 --- a/tests/testsuite/config.rs +++ b/tests/testsuite/config.rs @@ -2175,7 +2175,14 @@ fn build_std() { .unwrap() .build_std .unwrap(); - assert_eq!(value, vec!["core,std,panic_abort".to_string()]); + assert_eq!( + value, + vec![ + "core".to_string(), + "std".to_string(), + "panic_abort".to_string(), + ], + ); let gctx = GlobalContextBuilder::new() .config_arg("unstable.build-std=['core', 'std,panic_abort']") @@ -2188,7 +2195,11 @@ fn build_std() { .unwrap(); assert_eq!( value, - vec!["core".to_string(), "std,panic_abort".to_string()] + vec![ + "core".to_string(), + "std".to_string(), + "panic_abort".to_string(), + ] ); let gctx = GlobalContextBuilder::new() @@ -2205,7 +2216,11 @@ fn build_std() { .unwrap(); assert_eq!( value, - vec!["backtrace,panic-unwind,windows_raw_dylib".to_string()] + vec![ + "backtrace".to_string(), + "panic-unwind".to_string(), + "windows_raw_dylib".to_string(), + ] ); let gctx = GlobalContextBuilder::new() @@ -2221,7 +2236,8 @@ fn build_std() { value, vec![ "backtrace".to_string(), - "panic-unwind,windows_raw_dylib".to_string() + "panic-unwind".to_string(), + "windows_raw_dylib".to_string(), ] ); }