From 82eec2692403ba881fee0ac99dcbc6167f2be0a6 Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Tue, 8 Apr 2025 15:38:09 +0300 Subject: [PATCH 1/6] support "vxworks" and "nto" OSes on `get_base_archiver_variant` Signed-off-by: onur-ozkan --- src/lib.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 6139bb25c..b8e1e74bb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3334,6 +3334,21 @@ impl Build { // Use the GNU-variant to match other Unix systems. name = format!("g{}", tool).into(); self.cmd(&name) + } else if target.os == "vxworks" { + name = format!("wr-{}", tool).into(); + self.cmd(&name) + } else if target.os == "nto" { + name = match target.arch { + "i586" | "x86" => format!("ntox86-{}", tool).into(), + "aarch64" | "x86_64" => format!("nto{}-{}", target.arch, tool).into(), + _ => { + return Err(Error::new( + ErrorKind::InvalidTarget, + format!("Unknown architecture for Neutrino QNX: {}", target.arch), + )) + } + }; + self.cmd(&name) } else if self.get_is_cross_compile()? { match self.prefix_for_target(&self.get_raw_target()?) { Some(prefix) => { From 91646cebfa462e79c9f9aaac2f0df9af7c92402e Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Tue, 8 Apr 2025 16:39:49 +0300 Subject: [PATCH 2/6] improve target matching for Neutrino Signed-off-by: onur-ozkan --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index b8e1e74bb..bda173038 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2113,7 +2113,7 @@ impl Build { // This assumes qcc/q++ as compiler, which is currently the only supported compiler for QNX. // See for details: https://github.com/rust-lang/cc-rs/pull/1319 let arg = match target.arch { - "i586" => "-Vgcc_ntox86_cxx", + "i586" | "x86" => "-Vgcc_ntox86_cxx", "aarch64" => "-Vgcc_ntoaarch64le_cxx", "x86_64" => "-Vgcc_ntox86_64_cxx", _ => { From 8301ac2eb96d8d440cc0902a33eca612f7290497 Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Wed, 16 Apr 2025 08:27:52 +0300 Subject: [PATCH 3/6] apply nits Signed-off-by: onur-ozkan --- src/lib.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index bda173038..972ba2732 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2113,7 +2113,7 @@ impl Build { // This assumes qcc/q++ as compiler, which is currently the only supported compiler for QNX. // See for details: https://github.com/rust-lang/cc-rs/pull/1319 let arg = match target.arch { - "i586" | "x86" => "-Vgcc_ntox86_cxx", + "x86" | "i586" => "-Vgcc_ntox86_cxx", "aarch64" => "-Vgcc_ntoaarch64le_cxx", "x86_64" => "-Vgcc_ntox86_64_cxx", _ => { @@ -3338,9 +3338,10 @@ impl Build { name = format!("wr-{}", tool).into(); self.cmd(&name) } else if target.os == "nto" { + // Ref: https://www.qnx.com/developers/docs/8.0/com.qnx.doc.neutrino.utilities/topic/a/ar.html name = match target.arch { - "i586" | "x86" => format!("ntox86-{}", tool).into(), - "aarch64" | "x86_64" => format!("nto{}-{}", target.arch, tool).into(), + "i586" => format!("ntox86-{}", tool).into(), + "x86" | "aarch64" | "x86_64" => format!("nto{}-{}", target.arch, tool).into(), _ => { return Err(Error::new( ErrorKind::InvalidTarget, From a1af860826d5eaea99315c21404578c4ff573c6d Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Wed, 16 Apr 2025 09:00:55 +0300 Subject: [PATCH 4/6] add test coverage for archiver Signed-off-by: onur-ozkan --- tests/archiver.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 tests/archiver.rs diff --git a/tests/archiver.rs b/tests/archiver.rs new file mode 100644 index 000000000..df82310ee --- /dev/null +++ b/tests/archiver.rs @@ -0,0 +1,44 @@ +#[test] +fn main() { + let cfg = cc_with_target("i586-pc-nto-qnx700"); + assert_eq!(cfg.get_archiver().get_program(), "ntox86-ar"); + + let cfg = cc_with_target("x86_64-unknown-linux-gnu"); + assert_eq!(cfg.get_archiver().get_program(), "ar"); + + let cfg = cc_with_target("x86_64-unknown-linux-musl"); + assert_eq!(cfg.get_archiver().get_program(), "ar"); + + let cfg = cc_with_target("riscv64gc-unknown-openbsd"); + assert_eq!(cfg.get_archiver().get_program(), "ar"); + + let cfg = cc_with_target("i686-wrs-vxworks"); + assert_eq!(cfg.get_archiver().get_program(), "wr-ar"); + + let cfg = cc_with_target("i586-pc-nto-qnx700"); + assert_eq!(cfg.get_archiver().get_program(), "ntox86-ar"); + + let cfg = cc_with_target("aarch64-unknown-nto-qnx700"); + assert_eq!(cfg.get_archiver().get_program(), "ntoaarch64-ar"); + + let cfg = cc_with_target("x86_64-pc-nto-qnx710"); + assert_eq!(cfg.get_archiver().get_program(), "ntox86_64-ar"); + + let cfg = cc_with_target("wasm32-wasip1"); + // This usually returns an absolute path, so using `assert_eq` might make the test flaky. + assert!(cfg + .get_archiver() + .get_program() + .to_str() + .unwrap() + .ends_with("llvm-ar")); + + let cfg = cc_with_target("riscv64-linux-android"); + assert_eq!(cfg.get_archiver().get_program(), "llvm-ar"); +} + +fn cc_with_target(target: &'static str) -> cc::Build { + let mut cfg = cc::Build::new(); + cfg.host("x86_64-unknown-linux-gnu").target(target); + cfg +} From bb33e309344c4b0e7fcda2497d3a0a5cb7a51d81 Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Wed, 16 Apr 2025 09:04:08 +0300 Subject: [PATCH 5/6] bless fmt Signed-off-by: onur-ozkan --- src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 972ba2732..2d06f9d86 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3341,7 +3341,9 @@ impl Build { // Ref: https://www.qnx.com/developers/docs/8.0/com.qnx.doc.neutrino.utilities/topic/a/ar.html name = match target.arch { "i586" => format!("ntox86-{}", tool).into(), - "x86" | "aarch64" | "x86_64" => format!("nto{}-{}", target.arch, tool).into(), + "x86" | "aarch64" | "x86_64" => { + format!("nto{}-{}", target.arch, tool).into() + } _ => { return Err(Error::new( ErrorKind::InvalidTarget, From e3b04dc4e57b275dee75e46ba3a5c3cf31af205b Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Wed, 16 Apr 2025 09:07:11 +0300 Subject: [PATCH 6/6] extend archiver coverage Signed-off-by: onur-ozkan --- src/lib.rs | 4 +-- tests/archiver.rs | 77 ++++++++++++++++++++++++++++++----------------- 2 files changed, 51 insertions(+), 30 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2d06f9d86..a599dafd3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2112,7 +2112,7 @@ impl Build { // QNX 8.0: https://www.qnx.com/developers/docs/8.0/com.qnx.doc.neutrino.utilities/topic/q/qcc.html // This assumes qcc/q++ as compiler, which is currently the only supported compiler for QNX. // See for details: https://github.com/rust-lang/cc-rs/pull/1319 - let arg = match target.arch { + let arg = match target.full_arch { "x86" | "i586" => "-Vgcc_ntox86_cxx", "aarch64" => "-Vgcc_ntoaarch64le_cxx", "x86_64" => "-Vgcc_ntox86_64_cxx", @@ -3339,7 +3339,7 @@ impl Build { self.cmd(&name) } else if target.os == "nto" { // Ref: https://www.qnx.com/developers/docs/8.0/com.qnx.doc.neutrino.utilities/topic/a/ar.html - name = match target.arch { + name = match target.full_arch { "i586" => format!("ntox86-{}", tool).into(), "x86" | "aarch64" | "x86_64" => { format!("nto{}-{}", target.arch, tool).into() diff --git a/tests/archiver.rs b/tests/archiver.rs index df82310ee..f94f81adb 100644 --- a/tests/archiver.rs +++ b/tests/archiver.rs @@ -1,44 +1,65 @@ +use std::env; + #[test] fn main() { - let cfg = cc_with_target("i586-pc-nto-qnx700"); - assert_eq!(cfg.get_archiver().get_program(), "ntox86-ar"); + unsafe { env::set_var("AR_i586_pc_nto_qnx700", "custom-ar") }; + let ar = get_ar_for_target("i586-pc-nto-qnx700"); + assert_eq!(ar, "custom-ar"); + unsafe { env::remove_var("AR_i586_pc_nto_qnx700") }; + + unsafe { env::set_var("AR", "custom-ar2") }; + let ar = get_ar_for_target("x86_64-unknown-linux-gnu"); + assert_eq!(ar, "custom-ar2"); + unsafe { env::remove_var("AR") }; - let cfg = cc_with_target("x86_64-unknown-linux-gnu"); - assert_eq!(cfg.get_archiver().get_program(), "ar"); + let ar = get_ar_for_target("x86_64-unknown-linux-gnu"); + assert_eq!(ar, "ar"); - let cfg = cc_with_target("x86_64-unknown-linux-musl"); - assert_eq!(cfg.get_archiver().get_program(), "ar"); + let ar = get_ar_for_target("x86_64-unknown-linux-musl"); + assert_eq!(ar, "ar"); - let cfg = cc_with_target("riscv64gc-unknown-openbsd"); - assert_eq!(cfg.get_archiver().get_program(), "ar"); + let ar = get_ar_for_target("riscv64gc-unknown-openbsd"); + assert_eq!(ar, "ar"); - let cfg = cc_with_target("i686-wrs-vxworks"); - assert_eq!(cfg.get_archiver().get_program(), "wr-ar"); + let ar = get_ar_for_target("i686-wrs-vxworks"); + assert_eq!(ar, "wr-ar"); - let cfg = cc_with_target("i586-pc-nto-qnx700"); - assert_eq!(cfg.get_archiver().get_program(), "ntox86-ar"); + let ar = get_ar_for_target("i586-pc-nto-qnx700"); + assert_eq!(ar, "ntox86-ar"); - let cfg = cc_with_target("aarch64-unknown-nto-qnx700"); - assert_eq!(cfg.get_archiver().get_program(), "ntoaarch64-ar"); + let ar = get_ar_for_target("aarch64-unknown-nto-qnx700"); + assert_eq!(ar, "ntoaarch64-ar"); - let cfg = cc_with_target("x86_64-pc-nto-qnx710"); - assert_eq!(cfg.get_archiver().get_program(), "ntox86_64-ar"); + let ar = get_ar_for_target("x86_64-pc-nto-qnx710"); + assert_eq!(ar, "ntox86_64-ar"); - let cfg = cc_with_target("wasm32-wasip1"); - // This usually returns an absolute path, so using `assert_eq` might make the test flaky. - assert!(cfg - .get_archiver() - .get_program() - .to_str() - .unwrap() - .ends_with("llvm-ar")); + let ar = get_ar_for_target("wasm32-wasip1"); + assert!( + // `llvm-ar` is usually an absolute path for this target, so we check it with `ends_with`. + ar.ends_with(&maybe_exe("llvm-ar")) + // If `llvm-ar` doesn't exist, the logic falls back to `ar` for this target. + || ar == "ar" + ); - let cfg = cc_with_target("riscv64-linux-android"); - assert_eq!(cfg.get_archiver().get_program(), "llvm-ar"); + let ar = get_ar_for_target("riscv64-linux-android"); + // 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) + assert!(ar == "llvm-ar" || ar == "riscv64-linux-android-ar"); } -fn cc_with_target(target: &'static str) -> cc::Build { +fn get_ar_for_target(target: &'static str) -> String { let mut cfg = cc::Build::new(); cfg.host("x86_64-unknown-linux-gnu").target(target); - cfg + let ar = cfg.get_archiver(); + let ar = ar.get_program().to_str().unwrap().to_string(); + println!("cc::Build::get_archiver -> target: '{target}': resolved archiver: '{ar}'"); + ar +} + +/// Appends `.exe` to the file name on Windows systems. +fn maybe_exe(file: &'static str) -> String { + if cfg!(windows) { + format!("{file}.exe") + } else { + file.to_owned() + } }