Skip to content

support "vxworks" and "nto" OSes on get_base_archiver_variant #1456

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
20 changes: 19 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
"x86" | "i586" => "-Vgcc_ntox86_cxx",
"aarch64" => "-Vgcc_ntoaarch64le_cxx",
"x86_64" => "-Vgcc_ntox86_64_cxx",
_ => {
Expand Down Expand Up @@ -3334,6 +3334,24 @@ 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" {
// 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()
}
_ => {
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) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you really want this to continue working in the future, it'd be nice if you could add either a test, or ideally a CI step that sets up the required environment for NTO and vxWorks and runs the normal test suite.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just added a coverage on certain targets along with NTO and wxWorks.

Expand Down
65 changes: 65 additions & 0 deletions tests/archiver.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
use std::env;

#[test]
fn main() {
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 ar = get_ar_for_target("x86_64-unknown-linux-gnu");
assert_eq!(ar, "ar");

let ar = get_ar_for_target("x86_64-unknown-linux-musl");
assert_eq!(ar, "ar");

let ar = get_ar_for_target("riscv64gc-unknown-openbsd");
assert_eq!(ar, "ar");

let ar = get_ar_for_target("i686-wrs-vxworks");
assert_eq!(ar, "wr-ar");

let ar = get_ar_for_target("i586-pc-nto-qnx700");
assert_eq!(ar, "ntox86-ar");

let ar = get_ar_for_target("aarch64-unknown-nto-qnx700");
assert_eq!(ar, "ntoaarch64-ar");

let ar = get_ar_for_target("x86_64-pc-nto-qnx710");
assert_eq!(ar, "ntox86_64-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 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 get_ar_for_target(target: &'static str) -> String {
let mut cfg = cc::Build::new();
cfg.host("x86_64-unknown-linux-gnu").target(target);
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()
}
}
Loading