mirror of
https://github.com/dexoron/dcr.git
synced 2026-10-21 17:19:37 +00:00
fix: use host macOS target for default builds
This commit is contained in:
@@ -72,6 +72,46 @@ pub fn normalize_target_os(target: &str) -> &str {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn default_target_triple() -> String {
|
||||
if cfg!(target_os = "linux") {
|
||||
format!("{}-unknown-linux-gnu", std::env::consts::ARCH)
|
||||
} else if cfg!(target_os = "macos") {
|
||||
format!("{}-apple-darwin", std::env::consts::ARCH)
|
||||
} else if cfg!(target_os = "windows") {
|
||||
format!("{}-pc-windows-msvc", std::env::consts::ARCH)
|
||||
} else if cfg!(any(
|
||||
target_os = "freebsd",
|
||||
target_os = "openbsd",
|
||||
target_os = "netbsd",
|
||||
target_os = "dragonfly"
|
||||
)) {
|
||||
format!(
|
||||
"{}-unknown-{}",
|
||||
std::env::consts::ARCH,
|
||||
std::env::consts::OS
|
||||
)
|
||||
} else {
|
||||
"unknown".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn prepend_clang_target_flag(flags: &mut Vec<String>, target: Option<&str>, tool: &str) {
|
||||
let Some(target) = target.map(str::trim).filter(|t| !t.is_empty()) else {
|
||||
return;
|
||||
};
|
||||
if !tool.to_lowercase().contains("clang") {
|
||||
return;
|
||||
}
|
||||
|
||||
let target_flag = format!("--target={target}");
|
||||
if !flags
|
||||
.iter()
|
||||
.any(|f| f == &target_flag || f.starts_with("--target="))
|
||||
{
|
||||
flags.insert(0, target_flag);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_config_str(config: &Config, key: &str) -> String {
|
||||
config
|
||||
.get(key)
|
||||
@@ -380,6 +420,61 @@ mod tests {
|
||||
assert_eq!(normalize_target_os("unknown"), "unknown");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn default_target_triple_uses_host_arch() {
|
||||
let target = default_target_triple();
|
||||
if cfg!(target_os = "linux") {
|
||||
assert_eq!(
|
||||
target,
|
||||
format!("{}-unknown-linux-gnu", std::env::consts::ARCH)
|
||||
);
|
||||
} else if cfg!(target_os = "macos") {
|
||||
assert_eq!(target, format!("{}-apple-darwin", std::env::consts::ARCH));
|
||||
} else if cfg!(target_os = "windows") {
|
||||
assert_eq!(
|
||||
target,
|
||||
format!("{}-pc-windows-msvc", std::env::consts::ARCH)
|
||||
);
|
||||
} else if cfg!(any(
|
||||
target_os = "freebsd",
|
||||
target_os = "openbsd",
|
||||
target_os = "netbsd",
|
||||
target_os = "dragonfly"
|
||||
)) {
|
||||
assert_eq!(
|
||||
target,
|
||||
format!(
|
||||
"{}-unknown-{}",
|
||||
std::env::consts::ARCH,
|
||||
std::env::consts::OS
|
||||
)
|
||||
);
|
||||
} else {
|
||||
assert_eq!(target, "unknown");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn prepend_clang_target_flag_adds_once_for_clang() {
|
||||
let mut flags = vec!["-O2".to_string()];
|
||||
prepend_clang_target_flag(&mut flags, Some("aarch64-apple-darwin"), "clang");
|
||||
prepend_clang_target_flag(&mut flags, Some("aarch64-apple-darwin"), "clang");
|
||||
assert_eq!(
|
||||
flags,
|
||||
vec![
|
||||
"--target=aarch64-apple-darwin".to_string(),
|
||||
"-O2".to_string()
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn prepend_clang_target_flag_ignores_non_clang_tools() {
|
||||
let mut flags = vec!["-O2".to_string()];
|
||||
prepend_clang_target_flag(&mut flags, Some("aarch64-apple-darwin"), "gcc");
|
||||
assert_eq!(flags, vec!["-O2".to_string()]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_version_parts() {
|
||||
let info = parse_version_info("1.2.3-beta");
|
||||
|
||||
Reference in New Issue
Block a user