@@ -287,21 +287,48 @@ impl CargoTransform {
287287 doc[ "workspace" ] = table ( ) ;
288288 }
289289
290- // Ensure [workspace.dependencies] section exists
291- let workspace = doc[ "workspace" ]
292- . as_table_mut ( )
293- . ok_or_else ( || RailError :: message ( "[workspace] is not a table" ) ) ?;
290+ // Write each unified dependency
291+ // Group by target (None for regular deps, Some(target) for platform-specific)
292+ for unified in unified_deps {
293+ // Determine which table to write to based on target
294+ let deps_table = if let Some ( ref target) = unified. target {
295+ // Platform-specific dependency: write to [target.'<target>'.dependencies]
296+ let target_key = format ! ( "target.'{}'" , target) ;
297+
298+ // Ensure target section exists in workspace
299+ let workspace = doc[ "workspace" ]
300+ . as_table_mut ( )
301+ . ok_or_else ( || RailError :: message ( "[workspace] is not a table" ) ) ?;
302+
303+ if !workspace. contains_key ( & target_key) {
304+ workspace[ & target_key] = table ( ) ;
305+ }
294306
295- if !workspace . contains_key ( "dependencies" ) {
296- workspace [ "dependencies" ] = table ( ) ;
297- }
307+ let target_section = workspace [ & target_key ]
308+ . as_table_mut ( )
309+ . ok_or_else ( || RailError :: message ( format ! ( "[workspace.{}] is not a table" , target_key ) ) ) ? ;
298310
299- let workspace_deps = workspace [ "dependencies" ]
300- . as_table_mut ( )
301- . ok_or_else ( || RailError :: message ( "[workspace.dependencies] is not a table" ) ) ? ;
311+ if !target_section . contains_key ( "dependencies" ) {
312+ target_section [ "dependencies" ] = table ( ) ;
313+ }
302314
303- // Write each unified dependency
304- for unified in unified_deps {
315+ target_section[ "dependencies" ]
316+ . as_table_mut ( )
317+ . ok_or_else ( || RailError :: message ( format ! ( "[workspace.{}.dependencies] is not a table" , target_key) ) ) ?
318+ } else {
319+ // Regular dependency: write to [workspace.dependencies]
320+ let workspace = doc[ "workspace" ]
321+ . as_table_mut ( )
322+ . ok_or_else ( || RailError :: message ( "[workspace] is not a table" ) ) ?;
323+
324+ if !workspace. contains_key ( "dependencies" ) {
325+ workspace[ "dependencies" ] = table ( ) ;
326+ }
327+
328+ workspace[ "dependencies" ]
329+ . as_table_mut ( )
330+ . ok_or_else ( || RailError :: message ( "[workspace.dependencies] is not a table" ) ) ?
331+ } ;
305332 // Use inline table for simple deps and deps with few features
306333 // Use regular table format only for deps with many features (>10) to avoid long lines
307334 let use_inline_table = unified. features . len ( ) <= 10 ;
@@ -335,12 +362,12 @@ impl CargoTransform {
335362 }
336363
337364 // Insert the dependency
338- workspace_deps . insert ( & unified. name , toml_edit:: Item :: Value ( dep_table. into ( ) ) ) ;
365+ deps_table . insert ( & unified. name , toml_edit:: Item :: Value ( dep_table. into ( ) ) ) ;
339366
340367 // Add comments if enabled and any exist
341368 if add_comments
342369 && !unified. comments . is_empty ( )
343- && let Some ( item) = workspace_deps . get_mut ( & unified. name )
370+ && let Some ( item) = deps_table . get_mut ( & unified. name )
344371 {
345372 let comment_str = unified. comments . join ( ", " ) ;
346373 item
@@ -373,7 +400,7 @@ impl CargoTransform {
373400 dep_table[ "features" ] = toml_edit:: value ( Value :: Array ( features_array) ) ;
374401
375402 // Insert the dependency
376- workspace_deps . insert ( & unified. name , dep_table) ;
403+ deps_table . insert ( & unified. name , dep_table) ;
377404
378405 // Add comments if enabled and any exist
379406 // Note: Comments for regular tables are more complex - for now we skip them
@@ -671,12 +698,15 @@ members = ["crate-a", "crate-b"]
671698 name: "serde" . to_string( ) ,
672699 version_req: VersionReq :: parse( "1.0" ) . unwrap( ) ,
673700 features: vec![ "derive" . to_string( ) ] ,
701+ feature_provenance: HashMap :: new( ) ,
674702 default_features: true ,
675703 used_by: vec![ "crate-a" . to_string( ) , "crate-b" . to_string( ) ] ,
676704 dep_kinds: HashSet :: new( ) ,
677705 fragmentation_count: 2 ,
678706 path: None ,
707+ target: None ,
679708 comments: Vec :: new( ) ,
709+ is_proc_macro: false ,
680710 } ] ;
681711
682712 // Write workspace dependencies
@@ -728,12 +758,15 @@ members = ["crate-a"]
728758 name: "anyhow" . to_string( ) ,
729759 version_req: VersionReq :: parse( "1.0" ) . unwrap( ) ,
730760 features: vec![ ] , // No features
761+ feature_provenance: HashMap :: new( ) ,
731762 default_features: true ,
732763 used_by: vec![ "crate-a" . to_string( ) ] ,
733764 dep_kinds: HashSet :: new( ) ,
734765 fragmentation_count: 1 ,
735766 path: None ,
767+ target: None ,
736768 comments: Vec :: new( ) ,
769+ is_proc_macro: false ,
737770 } ] ;
738771
739772 transformer
@@ -766,12 +799,15 @@ members = ["crate-a"]
766799 name: "tokio" . to_string( ) ,
767800 version_req: VersionReq :: parse( "1.0" ) . unwrap( ) ,
768801 features: vec![ "fs" . to_string( ) , "net" . to_string( ) ] ,
802+ feature_provenance: HashMap :: new( ) ,
769803 default_features: false , // Explicitly disabled
770804 used_by: vec![ "crate-a" . to_string( ) ] ,
771805 dep_kinds: HashSet :: new( ) ,
772806 fragmentation_count: 1 ,
773807 path: None ,
808+ target: None ,
774809 comments: Vec :: new( ) ,
810+ is_proc_macro: false ,
775811 } ] ;
776812
777813 transformer
0 commit comments