@@ -66,45 +66,31 @@ pub(super) fn load_target_cfgs(config: &Config) -> CargoResult<Vec<(String, Targ
66
66
67
67
/// Loads a single `[host]` table for the given triple.
68
68
pub ( super ) fn load_host_triple ( config : & Config , triple : & str ) -> CargoResult < TargetConfig > {
69
- // This needs to get each field individually because it cannot fetch the
70
- // struct all at once due to `links_overrides`. Can't use `serde(flatten)`
71
- // because it causes serde to use `deserialize_map` which means the config
72
- // deserializer does not know which keys to deserialize, which means
73
- // environment variables would not work.
74
69
let host_triple_key = ConfigKey :: from_str ( & format ! ( "host.{}" , triple) ) ;
75
70
let host_prefix = match config. get_cv ( & host_triple_key) ? {
76
71
Some ( _) => format ! ( "host.{}" , triple) ,
77
72
None => "host" . to_string ( ) ,
78
73
} ;
79
- let runner: OptValue < PathAndArgs > = config. get ( & format ! ( "{}.runner" , host_prefix) ) ?;
80
- let rustflags: OptValue < StringList > = config. get ( & format ! ( "{}.rustflags" , host_prefix) ) ?;
81
- let linker: OptValue < ConfigRelativePath > = config. get ( & format ! ( "{}.linker" , host_prefix) ) ?;
82
- // Links do not support environment variables.
83
- let target_key = ConfigKey :: from_str ( & host_prefix) ;
84
- let links_overrides = match config. get_table ( & target_key) ? {
85
- Some ( links) => parse_links_overrides ( & target_key, links. val , config) ?,
86
- None => BTreeMap :: new ( ) ,
87
- } ;
88
- Ok ( TargetConfig {
89
- runner,
90
- rustflags,
91
- linker,
92
- links_overrides,
93
- } )
74
+ load_config_table ( config, & host_prefix)
94
75
}
95
76
96
77
/// Loads a single `[target]` table for the given triple.
97
78
pub ( super ) fn load_target_triple ( config : & Config , triple : & str ) -> CargoResult < TargetConfig > {
79
+ load_config_table ( config, & format ! ( "target.{}" , triple) )
80
+ }
81
+
82
+ /// Loads a single table for the given prefix.
83
+ fn load_config_table ( config : & Config , prefix : & str ) -> CargoResult < TargetConfig > {
98
84
// This needs to get each field individually because it cannot fetch the
99
85
// struct all at once due to `links_overrides`. Can't use `serde(flatten)`
100
86
// because it causes serde to use `deserialize_map` which means the config
101
87
// deserializer does not know which keys to deserialize, which means
102
88
// environment variables would not work.
103
- let runner: OptValue < PathAndArgs > = config. get ( & format ! ( "target. {}.runner" , triple ) ) ?;
104
- let rustflags: OptValue < StringList > = config. get ( & format ! ( "target. {}.rustflags" , triple ) ) ?;
105
- let linker: OptValue < ConfigRelativePath > = config. get ( & format ! ( "target. {}.linker" , triple ) ) ?;
89
+ let runner: OptValue < PathAndArgs > = config. get ( & format ! ( "{}.runner" , prefix ) ) ?;
90
+ let rustflags: OptValue < StringList > = config. get ( & format ! ( "{}.rustflags" , prefix ) ) ?;
91
+ let linker: OptValue < ConfigRelativePath > = config. get ( & format ! ( "{}.linker" , prefix ) ) ?;
106
92
// Links do not support environment variables.
107
- let target_key = ConfigKey :: from_str ( & format ! ( "target.{}" , triple ) ) ;
93
+ let target_key = ConfigKey :: from_str ( prefix ) ;
108
94
let links_overrides = match config. get_table ( & target_key) ? {
109
95
Some ( links) => parse_links_overrides ( & target_key, links. val , config) ?,
110
96
None => BTreeMap :: new ( ) ,
0 commit comments