use std::path::PathBuf;
use std::process::Command;
fn main() {
println!("cargo:rerun-if-changed=swift/passbox-se.swift");
if std::env::var_os("CARGO_FEATURE_HOST").is_none()
|| std::env::var("CARGO_CFG_TARGET_OS").as_deref() != Ok("macos")
{
return;
}
let arch = match std::env::var("CARGO_CFG_TARGET_ARCH").as_deref() {
Ok("x86_64") => "x86_64",
_ => "arm64",
};
let out = PathBuf::from(std::env::var("OUT_DIR").expect("OUT_DIR")).join("passbox-se");
let status = Command::new("swiftc")
.args(["-O", "-target", &format!("{arch}-apple-macosx13.0"), "-o"])
.arg(&out)
.arg("swift/passbox-se.swift")
.status()
.expect("swiftc is missing, install the Command Line Tools");
assert!(
status.success(),
"could not build the Secure Enclave helper"
);
let signed = Command::new("codesign")
.args(["-s", "-", "--force", "--options", "runtime"])
.arg(&out)
.status()
.expect("codesign is missing, install the Command Line Tools");
assert!(signed.success(), "could not sign the Secure Enclave helper");
}