use std::{env, process::Command};
fn command_help_output(command: &str) -> std::io::Result<std::process::Output> {
Command::new(command).args(["--help"]).output()
}
pub struct QtPlatformLinker;
impl QtPlatformLinker {
pub fn init() {
if env::var("CARGO_CFG_UNIX").is_err() {
return;
}
if let Ok(vendor) = env::var("CARGO_CFG_TARGET_VENDOR") {
if vendor == "apple" {
println!("cargo::rustc-link-arg=-fapple-link-rtlib");
}
}
let flags = env::var("CARGO_ENCODED_RUSTFLAGS").unwrap();
if !flags.contains("-fuse-ld") {
let ld_help = String::from_utf8(
command_help_output("ld")
.expect("Could not run ld command")
.stdout,
)
.unwrap();
let ld_is_bfd = ld_help.contains("symbolsrec")
|| ld_help.contains("verilog")
|| ld_help.contains("tekhex");
if !ld_is_bfd {
return;
}
if command_help_output("lld").is_ok() {
println!("cargo::rustc-link-arg=-fuse-ld=lld");
} else if command_help_output("ld.gold").is_ok() {
println!("cargo::rustc-link-arg=-fuse-ld=gold");
} else if command_help_output("mold").is_ok() {
println!("cargo::rustc-link-arg=-fuse-ld=mold");
} else {
println!("cargo::warning=Neither mold, lld, nor gold linkers were found. Linking with GNU ld.bfd will likely fail.");
}
}
}
}