Skip to content

Commit e3b04dc

Browse files
committed
extend archiver coverage
Signed-off-by: onur-ozkan <work@onurozkan.dev>
1 parent bb33e30 commit e3b04dc

File tree

2 files changed

+51
-30
lines changed

2 files changed

+51
-30
lines changed

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2112,7 +2112,7 @@ impl Build {
21122112
// QNX 8.0: https://www.qnx.com/developers/docs/8.0/com.qnx.doc.neutrino.utilities/topic/q/qcc.html
21132113
// This assumes qcc/q++ as compiler, which is currently the only supported compiler for QNX.
21142114
// See for details: https://github.com/rust-lang/cc-rs/pull/1319
2115-
let arg = match target.arch {
2115+
let arg = match target.full_arch {
21162116
"x86" | "i586" => "-Vgcc_ntox86_cxx",
21172117
"aarch64" => "-Vgcc_ntoaarch64le_cxx",
21182118
"x86_64" => "-Vgcc_ntox86_64_cxx",
@@ -3339,7 +3339,7 @@ impl Build {
33393339
self.cmd(&name)
33403340
} else if target.os == "nto" {
33413341
// Ref: https://www.qnx.com/developers/docs/8.0/com.qnx.doc.neutrino.utilities/topic/a/ar.html
3342-
name = match target.arch {
3342+
name = match target.full_arch {
33433343
"i586" => format!("ntox86-{}", tool).into(),
33443344
"x86" | "aarch64" | "x86_64" => {
33453345
format!("nto{}-{}", target.arch, tool).into()

tests/archiver.rs

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,65 @@
1+
use std::env;
2+
13
#[test]
24
fn main() {
3-
let cfg = cc_with_target("i586-pc-nto-qnx700");
4-
assert_eq!(cfg.get_archiver().get_program(), "ntox86-ar");
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") };
514

6-
let cfg = cc_with_target("x86_64-unknown-linux-gnu");
7-
assert_eq!(cfg.get_archiver().get_program(), "ar");
15+
let ar = get_ar_for_target("x86_64-unknown-linux-gnu");
16+
assert_eq!(ar, "ar");
817

9-
let cfg = cc_with_target("x86_64-unknown-linux-musl");
10-
assert_eq!(cfg.get_archiver().get_program(), "ar");
18+
let ar = get_ar_for_target("x86_64-unknown-linux-musl");
19+
assert_eq!(ar, "ar");
1120

12-
let cfg = cc_with_target("riscv64gc-unknown-openbsd");
13-
assert_eq!(cfg.get_archiver().get_program(), "ar");
21+
let ar = get_ar_for_target("riscv64gc-unknown-openbsd");
22+
assert_eq!(ar, "ar");
1423

15-
let cfg = cc_with_target("i686-wrs-vxworks");
16-
assert_eq!(cfg.get_archiver().get_program(), "wr-ar");
24+
let ar = get_ar_for_target("i686-wrs-vxworks");
25+
assert_eq!(ar, "wr-ar");
1726

18-
let cfg = cc_with_target("i586-pc-nto-qnx700");
19-
assert_eq!(cfg.get_archiver().get_program(), "ntox86-ar");
27+
let ar = get_ar_for_target("i586-pc-nto-qnx700");
28+
assert_eq!(ar, "ntox86-ar");
2029

21-
let cfg = cc_with_target("aarch64-unknown-nto-qnx700");
22-
assert_eq!(cfg.get_archiver().get_program(), "ntoaarch64-ar");
30+
let ar = get_ar_for_target("aarch64-unknown-nto-qnx700");
31+
assert_eq!(ar, "ntoaarch64-ar");
2332

24-
let cfg = cc_with_target("x86_64-pc-nto-qnx710");
25-
assert_eq!(cfg.get_archiver().get_program(), "ntox86_64-ar");
33+
let ar = get_ar_for_target("x86_64-pc-nto-qnx710");
34+
assert_eq!(ar, "ntox86_64-ar");
2635

27-
let cfg = cc_with_target("wasm32-wasip1");
28-
// This usually returns an absolute path, so using `assert_eq` might make the test flaky.
29-
assert!(cfg
30-
.get_archiver()
31-
.get_program()
32-
.to_str()
33-
.unwrap()
34-
.ends_with("llvm-ar"));
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+
);
3543

36-
let cfg = cc_with_target("riscv64-linux-android");
37-
assert_eq!(cfg.get_archiver().get_program(), "llvm-ar");
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");
3847
}
3948

40-
fn cc_with_target(target: &'static str) -> cc::Build {
49+
fn get_ar_for_target(target: &'static str) -> String {
4150
let mut cfg = cc::Build::new();
4251
cfg.host("x86_64-unknown-linux-gnu").target(target);
43-
cfg
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+
}
4465
}

0 commit comments

Comments
 (0)