1+ use std:: collections:: BTreeMap ;
2+
13use itertools:: Either ;
24use pixi_spec:: TomlSpec ;
35use pixi_toml:: { TomlFromStr , TomlWith } ;
46use rattler_conda_types:: NamedChannelOrUrl ;
5- use toml_span:: { de_helpers:: TableHelper , DeserError , Spanned , Value } ;
7+ use toml_span:: { de_helpers:: TableHelper , value :: ValueInner , DeserError , Spanned , Value } ;
68
79use crate :: {
810 build_system:: BuildBackend ,
@@ -16,6 +18,7 @@ pub struct TomlPackageBuild {
1618 pub backend : PixiSpanned < TomlBuildBackend > ,
1719 pub channels : Option < PixiSpanned < Vec < NamedChannelOrUrl > > > ,
1820 pub additional_dependencies : UniquePackageMap ,
21+ pub configuration : Option < serde_value:: Value > ,
1922}
2023
2124#[ derive( Debug ) ]
@@ -74,10 +77,37 @@ impl TomlPackageBuild {
7477 } ,
7578 additional_dependencies,
7679 channels : self . channels . map ( |channels| channels. value ) ,
80+ configuration : self . configuration ,
7781 } )
7882 }
7983}
8084
85+ fn convert_toml_to_serde ( value : & mut Value ) -> Result < serde_value:: Value , DeserError > {
86+ Ok ( match value. take ( ) {
87+ ValueInner :: String ( s) => serde_value:: Value :: String ( s. to_string ( ) ) ,
88+ ValueInner :: Integer ( i) => serde_value:: Value :: I64 ( i) ,
89+ ValueInner :: Float ( f) => serde_value:: Value :: F64 ( f) ,
90+ ValueInner :: Boolean ( b) => serde_value:: Value :: Bool ( b) ,
91+ ValueInner :: Array ( mut arr) => {
92+ let mut json_arr = Vec :: new ( ) ;
93+ for item in & mut arr {
94+ json_arr. push ( convert_toml_to_serde ( item) ?) ;
95+ }
96+ serde_value:: Value :: Seq ( json_arr)
97+ }
98+ ValueInner :: Table ( table) => {
99+ let mut map = BTreeMap :: new ( ) ;
100+ for ( key, mut val) in table {
101+ map. insert (
102+ serde_value:: Value :: String ( key. to_string ( ) ) ,
103+ convert_toml_to_serde ( & mut val) ?,
104+ ) ;
105+ }
106+ serde_value:: Value :: Map ( map)
107+ }
108+ } )
109+ }
110+
81111impl < ' de > toml_span:: Deserialize < ' de > for TomlBuildBackend {
82112 fn deserialize ( value : & mut Value < ' de > ) -> Result < Self , DeserError > {
83113 let mut th = TableHelper :: new ( value) ?;
@@ -107,11 +137,18 @@ impl<'de> toml_span::Deserialize<'de> for TomlPackageBuild {
107137 span : Some ( s. span . start ..s. span . end ) ,
108138 } ) ;
109139 let additional_dependencies = th. optional ( "additional-dependencies" ) . unwrap_or_default ( ) ;
140+
141+ let configuration = th
142+ . take ( "configuration" )
143+ . map ( |( _, mut value) | convert_toml_to_serde ( & mut value) )
144+ . transpose ( ) ?;
145+
110146 th. finalize ( None ) ?;
111147 Ok ( Self {
112148 backend : build_backend,
113149 channels,
114150 additional_dependencies,
151+ configuration,
115152 } )
116153 }
117154}
@@ -131,6 +168,18 @@ mod test {
131168 format_parse_error ( pixi_toml, parse_error)
132169 }
133170
171+ #[ test]
172+ fn test_configuration_parsing ( ) {
173+ let toml = r#"
174+ backend = { name = "foobar", version = "*" }
175+ configuration = { key = "value", other = ["foo", "bar"], integer = 1234, nested = { abc = "def" } }
176+ "# ;
177+ let parsed = <TomlPackageBuild as crate :: toml:: FromTomlStr >:: from_toml_str ( toml)
178+ . expect ( "parsing should succeed" ) ;
179+
180+ insta:: assert_debug_snapshot!( parsed) ;
181+ }
182+
134183 #[ test]
135184 fn test_disallow_source ( ) {
136185 assert_snapshot ! ( expect_parse_failure(
0 commit comments