diff --git a/src/cargo/util/config/target.rs b/src/cargo/util/config/target.rs index 11f6085c7d5..59bf7c1866a 100644 --- a/src/cargo/util/config/target.rs +++ b/src/cargo/util/config/target.rs @@ -66,45 +66,31 @@ pub(super) fn load_target_cfgs(config: &Config) -> CargoResult CargoResult { - // This needs to get each field individually because it cannot fetch the - // struct all at once due to `links_overrides`. Can't use `serde(flatten)` - // because it causes serde to use `deserialize_map` which means the config - // deserializer does not know which keys to deserialize, which means - // environment variables would not work. let host_triple_key = ConfigKey::from_str(&format!("host.{}", triple)); let host_prefix = match config.get_cv(&host_triple_key)? { Some(_) => format!("host.{}", triple), None => "host".to_string(), }; - let runner: OptValue = config.get(&format!("{}.runner", host_prefix))?; - let rustflags: OptValue = config.get(&format!("{}.rustflags", host_prefix))?; - let linker: OptValue = config.get(&format!("{}.linker", host_prefix))?; - // Links do not support environment variables. - let target_key = ConfigKey::from_str(&host_prefix); - let links_overrides = match config.get_table(&target_key)? { - Some(links) => parse_links_overrides(&target_key, links.val, config)?, - None => BTreeMap::new(), - }; - Ok(TargetConfig { - runner, - rustflags, - linker, - links_overrides, - }) + load_config_table(config, &host_prefix) } /// Loads a single `[target]` table for the given triple. pub(super) fn load_target_triple(config: &Config, triple: &str) -> CargoResult { + load_config_table(config, &format!("target.{}", triple)) +} + +/// Loads a single table for the given prefix. +fn load_config_table(config: &Config, prefix: &str) -> CargoResult { // This needs to get each field individually because it cannot fetch the // struct all at once due to `links_overrides`. Can't use `serde(flatten)` // because it causes serde to use `deserialize_map` which means the config // deserializer does not know which keys to deserialize, which means // environment variables would not work. - let runner: OptValue = config.get(&format!("target.{}.runner", triple))?; - let rustflags: OptValue = config.get(&format!("target.{}.rustflags", triple))?; - let linker: OptValue = config.get(&format!("target.{}.linker", triple))?; + let runner: OptValue = config.get(&format!("{}.runner", prefix))?; + let rustflags: OptValue = config.get(&format!("{}.rustflags", prefix))?; + let linker: OptValue = config.get(&format!("{}.linker", prefix))?; // Links do not support environment variables. - let target_key = ConfigKey::from_str(&format!("target.{}", triple)); + let target_key = ConfigKey::from_str(prefix); let links_overrides = match config.get_table(&target_key)? { Some(links) => parse_links_overrides(&target_key, links.val, config)?, None => BTreeMap::new(),