From fdeba57ceeb82e6ad551b3074325dd92da79af40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Wed, 13 Nov 2024 12:10:41 +0100 Subject: [PATCH] feat: add `libc` feature for linking to the C library MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- hermit/Cargo.toml | 2 ++ hermit/build.rs | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/hermit/Cargo.toml b/hermit/Cargo.toml index 383a3d26a..55d10ccb8 100644 --- a/hermit/Cargo.toml +++ b/hermit/Cargo.toml @@ -37,6 +37,7 @@ idle-poll = [] # Build the kernel with function instrument code for mcount-based tracing instrument = [] +libc = [] mmap = [] pci = [] pci-ids = ["pci"] @@ -57,6 +58,7 @@ vga = [] vsock = [] [build-dependencies] +cc = "1" flate2 = "1" ureq = "2.4" tar = "0.4" diff --git a/hermit/build.rs b/hermit/build.rs index 6a028ee28..cbe790856 100644 --- a/hermit/build.rs +++ b/hermit/build.rs @@ -18,6 +18,18 @@ fn main() { let kernel_src = KernelSrc::local().unwrap_or_else(KernelSrc::download); kernel_src.build(); + + if has_feature("libc") { + let libc = cc::Build::new() + .get_compiler() + .to_command() + .arg("-print-file-name=libc.a") + .output() + .unwrap() + .stdout; + let libc = str::from_utf8(&libc).unwrap().trim_ascii_end(); + println!("cargo:rustc-link-lib=static:+verbatim={libc}"); + } } struct KernelSrc {