63 lines
2.1 KiB
Rust
63 lines
2.1 KiB
Rust
extern crate cc;
|
|
|
|
use std::{env, fs};
|
|
|
|
fn main() {
|
|
let _crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set");
|
|
let target = env::var("TARGET").unwrap();
|
|
|
|
println!("cargo:rerun-if-changed=src/c");
|
|
|
|
// The Redoxer toolchain and some upstream nightlies keep the older
|
|
// `VaList<'a>` ABI for `extern "C" fn(...)` parameters, while others
|
|
// pass `VaListImpl<'f>` and require `.as_va_list()` to obtain
|
|
// `VaList<'_, '_>`. This is a host-compiler property, so probe
|
|
// directly with the host rustc (avoiding autocfg's target probing).
|
|
println!("cargo:rustc-check-cfg=cfg(relibc_valist_impl)");
|
|
let rustc = env::var("RUSTC").unwrap_or_else(|_| "rustc".to_string());
|
|
let out_dir = env::var("OUT_DIR").unwrap_or_else(|_| "/tmp".to_string());
|
|
let probe_file = std::path::Path::new(&out_dir).join("relibc_valist_probe.rs");
|
|
let probe_out = std::path::Path::new(&out_dir).join("librelibc_valist_probe.rlib");
|
|
std::fs::write(
|
|
&probe_file,
|
|
"#![feature(c_variadic)] pub fn _relibc_valist_probe(_: core::ffi::VaList<'_, '_>) {}",
|
|
)
|
|
.ok();
|
|
let probe_ok = std::process::Command::new(&rustc)
|
|
.args([
|
|
"--crate-type",
|
|
"lib",
|
|
"--edition",
|
|
"2024",
|
|
probe_file.to_str().unwrap(),
|
|
"-o",
|
|
probe_out.to_str().unwrap(),
|
|
])
|
|
.status()
|
|
.ok()
|
|
.map_or(false, |s| s.success());
|
|
if probe_ok {
|
|
println!("cargo:rustc-cfg=relibc_valist_impl");
|
|
}
|
|
|
|
let mut cc_builder = &mut cc::Build::new();
|
|
|
|
cc_builder = cc_builder.flag("-nostdinc").flag("-nostdlib");
|
|
|
|
if target.starts_with("aarch64") {
|
|
cc_builder = cc_builder.flag("-mno-outline-atomics")
|
|
}
|
|
|
|
cc_builder
|
|
.flag("-fno-stack-protector")
|
|
.flag("-Wno-expansion-to-defined")
|
|
.files(
|
|
fs::read_dir("src/c")
|
|
.expect("src/c directory missing")
|
|
.map(|res| res.expect("read_dir error").path()),
|
|
)
|
|
.compile("relibc_c");
|
|
|
|
println!("cargo:rustc-link-lib=static=relibc_c");
|
|
}
|