Mark Poliakov 7a0d528cda Add 'lib/runtime/' from commit 'db5cddbec10c4b7c086eda716d48d4711632901f'
git-subtree-dir: lib/runtime
git-subtree-mainline: 566a2341f5b726d86f5d42a72beb9c70b83f31b6
git-subtree-split: db5cddbec10c4b7c086eda716d48d4711632901f
2024-03-12 15:54:48 +02:00

66 lines
1.7 KiB
Rust

use std::{fs, path::Path};
use abi_generator::{
abi::{ty::TypeWidth, AbiBuilder},
syntax::UnwrapFancy,
TargetEnv,
};
fn add_file<'a>(build: &'a mut cc::Build, name: &'a str) -> &'a mut cc::Build {
println!("cargo:rerun-if-changed={}", name);
build.file(name)
}
fn build_libm() {
println!("cargo:rerun-if-changed=libm/private.h");
let mut build = cc::Build::new();
build
.compiler("clang")
.flag("-ffreestanding")
.flag("-nostdlib");
add_file(&mut build, "libm/s_truncf.c");
add_file(&mut build, "libm/s_ceilf.c");
add_file(&mut build, "libm/s_floorf.c");
add_file(&mut build, "libm/s_fabsf.c");
add_file(&mut build, "libm/s_scalbnf.c");
add_file(&mut build, "libm/s_copysignf.c");
add_file(&mut build, "libm/e_powf.c");
add_file(&mut build, "libm/e_sqrtf.c");
add_file(&mut build, "libm/e_hypotf.c");
add_file(&mut build, "libm/e_fmodf.c");
add_file(&mut build, "libm/w_powf.c");
add_file(&mut build, "libm/w_hypotf.c");
add_file(&mut build, "libm/w_fmodf.c");
build.compile("m");
}
fn generate_abi() {
let output_dir = std::env::var("OUT_DIR").expect("$OUT_DIR not set");
let generated_calls = Path::new(&output_dir).join("generated_calls.rs");
let abi = AbiBuilder::from_string(
yggdrasil_abi_def::ABI_FILE,
TargetEnv {
thin_pointer_width: TypeWidth::U64,
fat_pointer_width: TypeWidth::U64,
},
)
.unwrap_fancy("Could not parse/read ABI file");
let calls = prettyplease::unparse(
&abi.emit_file(false, true)
.unwrap_fancy("Could not emit system calls"),
);
fs::write(generated_calls, calls).unwrap();
}
fn main() {
build_libm();
generate_abi();
}