Skip to content

Commit 8ee6782

Browse files
authored
support "vxworks" and "nto" OSes on get_base_archiver_variant (#1456)
1 parent d61b3b3 commit 8ee6782

File tree

2 files changed

+85
-2
lines changed

2 files changed

+85
-2
lines changed

src/lib.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,8 +2139,8 @@ impl Build {
21392139
// QNX 8.0: https://www.qnx.com/developers/docs/8.0/com.qnx.doc.neutrino.utilities/topic/q/qcc.html
21402140
// This assumes qcc/q++ as compiler, which is currently the only supported compiler for QNX.
21412141
// See for details: https://github.com/rust-lang/cc-rs/pull/1319
2142-
let arg = match target.arch {
2143-
"i586" => "-Vgcc_ntox86_cxx",
2142+
let arg = match target.full_arch {
2143+
"x86" | "i586" => "-Vgcc_ntox86_cxx",
21442144
"aarch64" => "-Vgcc_ntoaarch64le_cxx",
21452145
"x86_64" => "-Vgcc_ntox86_64_cxx",
21462146
_ => {
@@ -3361,6 +3361,24 @@ impl Build {
33613361
// Use the GNU-variant to match other Unix systems.
33623362
name = format!("g{}", tool).into();
33633363
self.cmd(&name)
3364+
} else if target.os == "vxworks" {
3365+
name = format!("wr-{}", tool).into();
3366+
self.cmd(&name)
3367+
} else if target.os == "nto" {
3368+
// Ref: https://www.qnx.com/developers/docs/8.0/com.qnx.doc.neutrino.utilities/topic/a/ar.html
3369+
name = match target.full_arch {
3370+
"i586" => format!("ntox86-{}", tool).into(),
3371+
"x86" | "aarch64" | "x86_64" => {
3372+
format!("nto{}-{}", target.arch, tool).into()
3373+
}
3374+
_ => {
3375+
return Err(Error::new(
3376+
ErrorKind::InvalidTarget,
3377+
format!("Unknown architecture for Neutrino QNX: {}", target.arch),
3378+
))
3379+
}
3380+
};
3381+
self.cmd(&name)
33643382
} else if self.get_is_cross_compile()? {
33653383
match self.prefix_for_target(&self.get_raw_target()?) {
33663384
Some(prefix) => {

tests/archiver.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
use std::env;
2+
3+
#[test]
4+
fn main() {
5+
unsafe { env::set_var("AR_i586_pc_nto_qnx700", "custom-ar") };
6+
let ar = get_ar_for_target("i586-pc-nto-qnx700");
7+
assert_eq!(ar, "custom-ar");
8+
unsafe { env::remove_var("AR_i586_pc_nto_qnx700") };
9+
10+
unsafe { env::set_var("AR", "custom-ar2") };
11+
let ar = get_ar_for_target("x86_64-unknown-linux-gnu");
12+
assert_eq!(ar, "custom-ar2");
13+
unsafe { env::remove_var("AR") };
14+
15+
let ar = get_ar_for_target("x86_64-unknown-linux-gnu");
16+
assert_eq!(ar, "ar");
17+
18+
let ar = get_ar_for_target("x86_64-unknown-linux-musl");
19+
assert_eq!(ar, "ar");
20+
21+
let ar = get_ar_for_target("riscv64gc-unknown-openbsd");
22+
assert_eq!(ar, "ar");
23+
24+
let ar = get_ar_for_target("i686-wrs-vxworks");
25+
assert_eq!(ar, "wr-ar");
26+
27+
let ar = get_ar_for_target("i586-pc-nto-qnx700");
28+
assert_eq!(ar, "ntox86-ar");
29+
30+
let ar = get_ar_for_target("aarch64-unknown-nto-qnx700");
31+
assert_eq!(ar, "ntoaarch64-ar");
32+
33+
let ar = get_ar_for_target("x86_64-pc-nto-qnx710");
34+
assert_eq!(ar, "ntox86_64-ar");
35+
36+
let ar = get_ar_for_target("wasm32-wasip1");
37+
assert!(
38+
// `llvm-ar` is usually an absolute path for this target, so we check it with `ends_with`.
39+
ar.ends_with(&maybe_exe("llvm-ar"))
40+
// If `llvm-ar` doesn't exist, the logic falls back to `ar` for this target.
41+
|| ar == "ar"
42+
);
43+
44+
let ar = get_ar_for_target("riscv64-linux-android");
45+
// If `llvm-ar` is not available on the system, this will fall back to `$target-ar` (e.g., `riscv64-linux-android-ar` in this case)
46+
assert!(ar == "llvm-ar" || ar == "riscv64-linux-android-ar");
47+
}
48+
49+
fn get_ar_for_target(target: &'static str) -> String {
50+
let mut cfg = cc::Build::new();
51+
cfg.host("x86_64-unknown-linux-gnu").target(target);
52+
let ar = cfg.get_archiver();
53+
let ar = ar.get_program().to_str().unwrap().to_string();
54+
println!("cc::Build::get_archiver -> target: '{target}': resolved archiver: '{ar}'");
55+
ar
56+
}
57+
58+
/// Appends `.exe` to the file name on Windows systems.
59+
fn maybe_exe(file: &'static str) -> String {
60+
if cfg!(windows) {
61+
format!("{file}.exe")
62+
} else {
63+
file.to_owned()
64+
}
65+
}

0 commit comments

Comments
 (0)