Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 2 additions & 13 deletions src/bootstrap/src/core/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::core::config::{DryRun, SplitDebuginfo, TargetSelection};
use crate::prepare_behaviour_dump_dir;
use crate::utils::cache::{Cache, Interned, INTERNER};
use crate::utils::helpers::{self, add_dylib_path, add_link_lib_path, exe, linker_args};
use crate::utils::helpers::{libdir, linker_flags, output, t, LldThreads};
use crate::utils::helpers::{check_cfg_arg, libdir, linker_flags, output, t, LldThreads};
use crate::EXTRA_CHECK_CFGS;
use crate::{Build, CLang, Crate, DocTests, GitRepo, Mode};

Expand Down Expand Up @@ -1467,18 +1467,7 @@ impl<'a> Builder<'a> {
rustflags.arg("-Zunstable-options");
for (restricted_mode, name, values) in EXTRA_CHECK_CFGS {
if *restricted_mode == None || *restricted_mode == Some(mode) {
// Creating a string of the values by concatenating each value:
// ',"tvos","watchos"' or '' (nothing) when there are no values
let values = match values {
Some(values) => values
.iter()
.map(|val| [",", "\"", val, "\""])
.flatten()
.collect::<String>(),
None => String::new(),
};
let values = values.strip_prefix(",").unwrap_or(&values); // remove the first `,`
rustflags.arg(&format!("--check-cfg=cfg({name},values({values}))"));
rustflags.arg(&check_cfg_arg(name, *values));
}
}

Expand Down
15 changes: 14 additions & 1 deletion src/bootstrap/src/tests/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::utils::helpers::{extract_beta_rev, hex_encode, make};
use crate::utils::helpers::{extract_beta_rev, hex_encode, make, check_cfg_arg};
use std::path::PathBuf;

#[test]
Expand Down Expand Up @@ -57,3 +57,16 @@ fn test_string_to_hex_encode() {
let hex_string = hex_encode(input_string);
assert_eq!(hex_string, "48656c6c6f2c20576f726c6421");
}

#[test]
fn test_check_cfg_arg() {
assert_eq!(check_cfg_arg("bootstrap", None), "--check-cfg=cfg(bootstrap)");
assert_eq!(
check_cfg_arg("target_arch", Some(&["s360"])),
"--check-cfg=cfg(target_arch,values(\"s360\"))"
);
assert_eq!(
check_cfg_arg("target_os", Some(&["nixos", "nix2"])),
"--check-cfg=cfg(target_os,values(\"nixos\",\"nix2\"))"
);
}
19 changes: 19 additions & 0 deletions src/bootstrap/src/utils/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,3 +552,22 @@ where
{
input.as_ref().iter().map(|x| format!("{:02x}", x)).collect()
}

/// Create a `--check-cfg` argument invocation for a given name
/// and it's values.
pub fn check_cfg_arg(name: &str, values: Option<&[&str]>) -> String {
// Creating a string of the values by concatenating each value:
// ',values("tvos","watchos")' or '' (nothing) when there are no values.
let next = match values {
Some(values) => {
let mut tmp =
values.iter().map(|val| [",", "\"", val, "\""]).flatten().collect::<String>();

tmp.insert_str(1, "values(");
tmp.push_str(")");
tmp
}
None => "".to_string(),
};
format!("--check-cfg=cfg({name}{next})")
}