v6/build.rs

50 lines
1.3 KiB
Rust
Raw Normal View History

2023-01-03 18:41:31 +00:00
use serde::Deserialize;
use std::process::Command;
2022-12-10 18:15:32 +00:00
fn main() {
// trigger recompilation when a new migration is added
println!("cargo:rerun-if-changed=migrations");
2023-01-03 18:41:31 +00:00
let target = get_swift_target_info();
if target.target.unversioned_triple.contains("linux") {
target.paths.runtime_library_paths.iter().for_each(|path| {
println!("cargo:rustc-link-arg=-Wl,-rpath={}", path);
});
2023-01-03 19:10:23 +00:00
let arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap();
println!(
"cargo:rustc-link-arg={}/linux/{}/swiftrt.o",
&target.paths.runtime_resource_path, arch
);
2023-01-03 18:41:31 +00:00
}
}
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SwiftTargetInfo {
pub unversioned_triple: String,
}
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SwiftPaths {
pub runtime_library_paths: Vec<String>,
2023-01-03 19:10:23 +00:00
pub runtime_resource_path: String,
2023-01-03 18:41:31 +00:00
}
#[derive(Debug, Deserialize)]
pub struct SwiftTarget {
pub target: SwiftTargetInfo,
pub paths: SwiftPaths,
}
pub fn get_swift_target_info() -> SwiftTarget {
let swift_target_info_str = Command::new("swift")
.args(&["-print-target-info"])
.output()
.unwrap()
.stdout;
serde_json::from_slice(&swift_target_info_str).unwrap()
}