45 lines
1.4 KiB
Rust
Executable file
45 lines
1.4 KiB
Rust
Executable file
fn env(s: &str) -> String {
|
|
std::env::var(s).unwrap()
|
|
}
|
|
|
|
fn main() {
|
|
std::process::Command::new("ceedling")
|
|
.arg("clobber")
|
|
.current_dir("./algorithms-c/")
|
|
.status()
|
|
.expect("could not cleanup old algorithms-c files");
|
|
|
|
let mut cmd = std::process::Command::new("ceedling");
|
|
cmd.arg("release");
|
|
|
|
let arch = env("CARGO_CFG_TARGET_ARCH");
|
|
let pw = env("CARGO_CFG_TARGET_POINTER_WIDTH");
|
|
let os = env("CARGO_CFG_TARGET_OS");
|
|
|
|
if arch == "arm" && pw == "32" && os == "none" {
|
|
cmd.env("CC", "arm-none-eabi-gcc")
|
|
.env("AR", "arm-none-eabi-ar");
|
|
} else if os == "linux" {
|
|
cmd.env("CC", "gcc").env("AR", "ar");
|
|
} else {
|
|
panic!("Unsupported build target")
|
|
}
|
|
|
|
let status = cmd
|
|
.current_dir("./algorithms-c/")
|
|
.status()
|
|
.expect("could not make c stuff");
|
|
if !status.success() {
|
|
panic!("make returned an error")
|
|
}
|
|
let cwd = std::env::current_dir().unwrap().display().to_string();
|
|
let libpath_s = format!("{cwd}/algorithms-c/build/artifacts/release/libalgorithms.a");
|
|
let libpath = std::path::Path::new(&libpath_s);
|
|
assert!(libpath.exists());
|
|
println!("cargo::rustc-link-lib=algorithms");
|
|
println!("cargo::rerun-if-changed={cwd}/algorithms-c/src/");
|
|
println!(
|
|
"cargo::rustc-link-search={}",
|
|
libpath.parent().unwrap().display()
|
|
);
|
|
}
|