Skip to content

Commit dc7e0b0

Browse files
committed
feat: adapt to picolibc
Signed-off-by: Tomasz Andrzejak <andreiltd@gmail.com>
1 parent 8f21b64 commit dc7e0b0

1 file changed

Lines changed: 29 additions & 10 deletions

File tree

src/toolchain.rs

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,34 @@ pub fn prepare(args: &Args) -> Result<()> {
5353
std::fs::create_dir_all(&include_dst_dir)
5454
.context("Failed to create sysroot include directory")?;
5555

56-
const INCLUDE_DIRS: &[&str] = &[
57-
"third_party/printf/",
58-
"third_party/musl/include",
59-
"third_party/musl/arch/generic",
60-
"third_party/musl/arch/x86_64",
61-
"third_party/musl/src/internal",
62-
];
63-
64-
for dir in INCLUDE_DIRS {
56+
// Detect which libc variant is present: picolibc or legacy musl
57+
let include_dirs: &[&str] = if hyperlight_guest_bin_dir
58+
.join("third_party/picolibc/libc/include")
59+
.is_dir()
60+
{
61+
&[
62+
"third_party/picolibc/libc/include",
63+
"third_party/picolibc/libc/stdio",
64+
]
65+
} else if hyperlight_guest_bin_dir
66+
.join("third_party/musl/include")
67+
.is_dir()
68+
{
69+
&[
70+
"third_party/printf/",
71+
"third_party/musl/include",
72+
"third_party/musl/arch/generic",
73+
"third_party/musl/arch/x86_64",
74+
"third_party/musl/src/internal",
75+
]
76+
} else {
77+
anyhow::bail!(
78+
"Could not detect libc variant in {}",
79+
hyperlight_guest_bin_dir.display()
80+
);
81+
};
82+
83+
for dir in include_dirs {
6584
let include_src_dir = hyperlight_guest_bin_dir.join(dir);
6685
let files = glob::glob(&format!("{}/**/*.h", include_src_dir.display()))
6786
.context("Failed to read include source directory")?;
@@ -94,7 +113,7 @@ pub fn cflags(args: &Args) -> OsString {
94113
"-fstack-clash-protection",
95114
"-mstack-probe-size=4096",
96115
"-mno-red-zone",
97-
"-nostdinc",
116+
"-nostdlibinc",
98117
// Define HYPERLIGHT as we use this to conditionally enable/disable code
99118
// in the libc headers
100119
"-DHYPERLIGHT=1",

0 commit comments

Comments
 (0)