From b620e3ef8f5788aaa7cbcf3093a20fd41bd13372 Mon Sep 17 00:00:00 2001 From: Jorge Prendes Date: Tue, 5 May 2026 21:33:02 +0100 Subject: [PATCH 01/10] move libc from hl-guest-bin to hl-libc Signed-off-by: Jorge Prendes --- .gitmodules | 4 +- Cargo.lock | 34 +++- Cargo.toml | 2 + NOTICE.txt | 2 +- c.just | 2 +- docs/picolibc.md | 6 +- src/hyperlight_guest_bin/Cargo.toml | 6 +- src/hyperlight_guest_bin/src/lib.rs | 7 +- .../src/{libc.rs => libc_stubs.rs} | 60 +++---- src/hyperlight_libc/.cargo/config.toml | 2 + src/hyperlight_libc/Cargo.toml | 30 ++++ .../build.rs | 77 +++++++-- .../build_files.rs | 0 .../include/picolibc.h | 0 src/hyperlight_libc/src/lib.rs | 35 ++++ .../third_party/README.md | 0 .../third_party/picolibc | 0 src/tests/c_guests/c_simpleguest/main.c | 2 +- src/tests/rust_guests/dummyguest/Cargo.lock | 163 +++++++++++++++++- src/tests/rust_guests/simpleguest/Cargo.lock | 163 +++++++++++++++++- src/tests/rust_guests/witguest/Cargo.lock | 107 +++++++++++- 21 files changed, 620 insertions(+), 82 deletions(-) rename src/hyperlight_guest_bin/src/{libc.rs => libc_stubs.rs} (69%) create mode 100644 src/hyperlight_libc/.cargo/config.toml create mode 100644 src/hyperlight_libc/Cargo.toml rename src/{hyperlight_guest_bin => hyperlight_libc}/build.rs (83%) rename src/{hyperlight_guest_bin => hyperlight_libc}/build_files.rs (100%) rename src/{hyperlight_guest_bin => hyperlight_libc}/include/picolibc.h (100%) create mode 100644 src/hyperlight_libc/src/lib.rs rename src/{hyperlight_guest_bin => hyperlight_libc}/third_party/README.md (100%) rename src/{hyperlight_guest_bin => hyperlight_libc}/third_party/picolibc (100%) diff --git a/.gitmodules b/.gitmodules index 36518194f..b7b8a5c57 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,4 @@ -[submodule "src/hyperlight_guest_bin/third_party/picolibc"] - path = src/hyperlight_guest_bin/third_party/picolibc +[submodule "src/hyperlight_libc/third_party/picolibc"] + path = src/hyperlight_libc/third_party/picolibc url = https://github.com/hyperlight-dev/picolibc-bsd.git shallow = true diff --git a/Cargo.lock b/Cargo.lock index 8c38dde6a..4f1d81215 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -213,6 +213,26 @@ dependencies = [ "syn", ] +[[package]] +name = "bindgen" +version = "0.71.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f58bf3d7db68cfbac37cfc485a8d711e87e064c3d0fe0435b92f7a407f9d6b3" +dependencies = [ + "bitflags 2.11.1", + "cexpr", + "clang-sys", + "itertools 0.13.0", + "log", + "prettyplease", + "proc-macro2", + "quote", + "regex", + "rustc-hash 2.1.1", + "shlex", + "syn", +] + [[package]] name = "bindgen" version = "0.72.1" @@ -1506,14 +1526,13 @@ version = "0.14.0" dependencies = [ "anyhow", "buddy_system_allocator", - "cc", "cfg-if", "flatbuffers", - "glob", "hyperlight-common", "hyperlight-guest", "hyperlight-guest-macro", "hyperlight-guest-tracing", + "hyperlight-libc", "linkme", "log", "spin", @@ -1610,6 +1629,17 @@ dependencies = [ "windows-version", ] +[[package]] +name = "hyperlight-libc" +version = "0.14.0" +dependencies = [ + "anyhow", + "bindgen 0.71.1", + "cc", + "cfg-if", + "glob", +] + [[package]] name = "hyperlight-testing" version = "0.0.0" diff --git a/Cargo.toml b/Cargo.toml index 6c3ce9624..207750f1f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,7 @@ members = [ "fuzz", "src/hyperlight_guest_bin", "src/hyperlight_guest_macro", + "src/hyperlight_libc", "src/hyperlight_component_util", "src/hyperlight_component_macro", "src/trace_dump", @@ -43,6 +44,7 @@ hyperlight-guest-bin = { path = "src/hyperlight_guest_bin", version = "0.14.0", hyperlight-guest-macro = { path = "src/hyperlight_guest_macro", version = "0.14.0", default-features = false } hyperlight-testing = { path = "src/hyperlight_testing", default-features = false } hyperlight-guest-tracing = { path = "src/hyperlight_guest_tracing", version = "0.14.0", default-features = false } +hyperlight-libc = { path = "src/hyperlight_libc", version = "0.14.0", default-features = false } hyperlight-component-util = { path = "src/hyperlight_component_util", version = "0.14.0", default-features = false } hyperlight-component-macro = { path = "src/hyperlight_component_macro", version = "0.14.0", default-features = false } diff --git a/NOTICE.txt b/NOTICE.txt index d520215d9..6c1513e6f 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -53,7 +53,7 @@ Copyright © 2020 The Newlib Project Newlib code is licensed under a collection of BSD-compatible and permissive licenses. The full license details for all files are documented in the COPYING.picolibc and COPYING.NEWLIB files in the -picolibc submodule at src/hyperlight_guest_bin/third_party/picolibc/. +picolibc submodule at src/hyperlight_libc/third_party/picolibc/. Note: The picolibc submodule uses the picolibc-bsd fork (https://github.com/hyperlight-dev/picolibc-bsd), which is a redistribution diff --git a/c.just b/c.just index 957669952..92bcf8f6c 100644 --- a/c.just +++ b/c.just @@ -3,7 +3,7 @@ mkdir := if os() == "windows" { "mkdir -f -p" } else { "mkdir -p"} # Elf options # We don't support stack protectors at the moment, but Arch Linux clang auto-enables them for -linux platforms, so explicitly disable them. c-compile-options-elf := '-nostdlibinc -H --target=x86_64-unknown-linux-none -fno-stack-protector -fstack-clash-protection -mstack-probe-size=4096 -fPIC' -c-include-flags-elf := "-I " + root / "src/hyperlight_guest_capi/include/" + " -I " + root / "src/hyperlight_guest_bin/third_party/picolibc/libc/include/" + " -I " + root / "src/hyperlight_guest_bin/third_party/picolibc/libc/stdio/" + " -I " + root / "src/hyperlight_guest_bin/include/" +c-include-flags-elf := "-I " + root / "src/hyperlight_guest_capi/include/" + " -I " + root / "src/hyperlight_libc/third_party/picolibc/libc/include/" + " -I " + root / "src/hyperlight_libc/third_party/picolibc/libc/stdio/" + " -I " + root / "src/hyperlight_libc/include/" c-linker-options-elf := '--entry "entrypoint" --nostdlib -pie --no-dynamic-linker' c-flags-debug-elf := '-O0' c-flags-release-elf := '-O3' diff --git a/docs/picolibc.md b/docs/picolibc.md index a1eb0200f..d6a7ce44f 100644 --- a/docs/picolibc.md +++ b/docs/picolibc.md @@ -8,7 +8,7 @@ for embedded systems, making it well-suited for Hyperlight's micro-VM environmen The picolibc integration is controlled by the `libc` feature flag on the `hyperlight-guest-bin` crate (enabled by default). When enabled, the build script compiles picolibc from source using the -vendored submodule at `src/hyperlight_guest_bin/third_party/picolibc`. +vendored submodule at `src/hyperlight_libc/third_party/picolibc`. The submodule points to [picolibc-bsd](https://github.com/hyperlight-dev/picolibc-bsd), a redistribution of picolibc with all copyleft-licensed files (GPL/AGPL) removed from the tree and @@ -66,11 +66,11 @@ To update picolibc to a new version: 2. Update the submodule in hyperlight: ```bash - cd src/hyperlight_guest_bin/third_party/picolibc + cd src/hyperlight_libc/third_party/picolibc git fetch origin git checkout cd ../../../.. - git add src/hyperlight_guest_bin/third_party/picolibc + git add src/hyperlight_libc/third_party/picolibc ``` 3. Verify licensing: The fork's CI runs scancode-toolkit to ensure no copyleft files are present. diff --git a/src/hyperlight_guest_bin/Cargo.toml b/src/hyperlight_guest_bin/Cargo.toml index 961b4aecf..f2d966abf 100644 --- a/src/hyperlight_guest_bin/Cargo.toml +++ b/src/hyperlight_guest_bin/Cargo.toml @@ -1,6 +1,5 @@ [package] name = "hyperlight-guest-bin" -links = "c" version.workspace = true edition.workspace = true rust-version.workspace = true @@ -15,7 +14,7 @@ and third-party code used by our C-API needed to build a native hyperlight-guest [features] default = ["libc", "macros"] -libc = [] # compile libc from picolibc +libc = ["dep:hyperlight-libc"] # compile libc from picolibc trace_guest = ["hyperlight-common/trace_guest", "hyperlight-guest/trace_guest", "hyperlight-guest-tracing/trace"] mem_profile = ["hyperlight-common/mem_profile"] macros = ["dep:hyperlight-guest-macro", "dep:linkme"] @@ -25,6 +24,7 @@ hyperlight-guest = { workspace = true, default-features = false } hyperlight-common = { workspace = true, default-features = false } hyperlight-guest-tracing = { workspace = true, default-features = false } hyperlight-guest-macro = { workspace = true, default-features = false, optional = true } +hyperlight-libc = { workspace = true, default-features = false, optional = true } buddy_system_allocator = "0.13.0" log = { version = "0.4", default-features = false } linkme = { version = "0.3.36", optional = true } @@ -37,6 +37,4 @@ workspace = true [build-dependencies] anyhow = "1" -cc = "1.2" cfg-if = "1.0" -glob = "0.3.3" diff --git a/src/hyperlight_guest_bin/src/lib.rs b/src/hyperlight_guest_bin/src/lib.rs index 84e328892..450b54930 100644 --- a/src/hyperlight_guest_bin/src/lib.rs +++ b/src/hyperlight_guest_bin/src/lib.rs @@ -55,8 +55,13 @@ pub mod memory; pub mod paging; /// Bridge between picolibc's POSIX expectations and the Hyperlight host. +/// cbindgen:ignore #[cfg(feature = "libc")] -mod libc; +mod libc_stubs; + +/// Re-export the libc bindings from hyperlight-libc when the libc feature is enabled. +#[cfg(feature = "libc")] +pub use hyperlight_libc as libc; // Globals #[cfg(all(feature = "mem_profile", target_arch = "x86_64"))] diff --git a/src/hyperlight_guest_bin/src/libc.rs b/src/hyperlight_guest_bin/src/libc_stubs.rs similarity index 69% rename from src/hyperlight_guest_bin/src/libc.rs rename to src/hyperlight_guest_bin/src/libc_stubs.rs index dbb0d4cab..1d1810291 100644 --- a/src/hyperlight_guest_bin/src/libc.rs +++ b/src/hyperlight_guest_bin/src/libc_stubs.rs @@ -16,48 +16,25 @@ limitations under the License. use alloc::string::String; use alloc::vec; -use core::ffi::*; +use core::ffi::{c_int, c_long, c_void}; use core::sync::atomic::{AtomicU64, Ordering}; use hyperlight_common::flatbuffer_wrappers::function_types::{ParameterValue, ReturnType}; use crate::host_comm::call_host_function; +use crate::libc::{ + CLOCK_MONOTONIC, CLOCK_REALTIME, EBADF, EINVAL, EIO, ENOSYS, clockid_t, errno, timespec, + timeval, +}; -unsafe extern "C" { - static mut errno: c_int; -} - -fn set_errno(val: c_int) { +fn set_errno(val: u32) { // SAFETY: single-threaded guest, errno is a global int (__GLOBAL_ERRNO) - unsafe { errno = val }; + // Bindgen uses u32 for the errno definitions, so we convert it to the expected c_int type here + unsafe { errno = val as _ }; } -// POSIX errno values (matching picolibc sys/errno.h) -const EINVAL: c_int = 22; -const EIO: c_int = 5; -const EBADF: c_int = 9; -const ENOSYS: c_int = 88; - -// picolibc clock IDs (from time.h) -const CLOCK_REALTIME: c_ulong = 1; -const CLOCK_MONOTONIC: c_ulong = 4; - static CURRENT_TIME: AtomicU64 = AtomicU64::new(0); -/// Matches picolibc `struct timespec` layout for x86_64 and aarch64. -#[repr(C)] -pub(crate) struct Timespec { - tv_sec: c_long, - tv_nsec: c_long, -} - -/// Matches picolibc `struct timeval` layout for x86_64 and aarch64. -#[repr(C)] -pub(crate) struct Timeval { - tv_sec: c_long, - tv_usec: c_long, -} - /// Returns a synthetic monotonically-increasing time starting at Unix epoch /// increasing 1s each call. fn current_time() -> (u64, u64) { @@ -66,7 +43,7 @@ fn current_time() -> (u64, u64) { } #[unsafe(no_mangle)] -pub extern "C" fn read(fd: c_int, buf: *mut c_void, count: usize) -> isize { +extern "C" fn read(fd: c_int, buf: *mut c_void, count: usize) -> isize { if buf.is_null() && count > 0 { set_errno(EINVAL); return -1; @@ -81,7 +58,7 @@ pub extern "C" fn read(fd: c_int, buf: *mut c_void, count: usize) -> isize { } #[unsafe(no_mangle)] -pub extern "C" fn write(fd: c_int, buf: *const c_void, count: usize) -> isize { +extern "C" fn write(fd: c_int, buf: *const c_void, count: usize) -> isize { if buf.is_null() && count > 0 { set_errno(EINVAL); return -1; @@ -108,14 +85,19 @@ pub extern "C" fn write(fd: c_int, buf: *const c_void, count: usize) -> isize { } #[unsafe(no_mangle)] -pub extern "C" fn clock_gettime(clk_id: c_ulong, tp: *mut Timespec) -> c_int { +extern "C" fn clock_gettime(clk_id: clockid_t, tp: *mut timespec) -> c_int { + // The libc bindings generated by bindgen are u32, but we expect them to be clockid_t, + // so we convert the constants to the expected type here for comparison. + const CLOCK_ID_REALTIME: clockid_t = CLOCK_REALTIME as _; + const CLOCK_ID_MONOTONIC: clockid_t = CLOCK_MONOTONIC as _; + if tp.is_null() { set_errno(EINVAL); return -1; } match clk_id { - CLOCK_REALTIME | CLOCK_MONOTONIC => { + CLOCK_ID_REALTIME | CLOCK_ID_MONOTONIC => { let (secs, nanos) = current_time(); unsafe { (*tp).tv_sec = secs as c_long; @@ -131,7 +113,7 @@ pub extern "C" fn clock_gettime(clk_id: c_ulong, tp: *mut Timespec) -> c_int { } #[unsafe(no_mangle)] -pub extern "C" fn gettimeofday(tv: *mut Timeval, _tz: *mut c_void) -> c_int { +extern "C" fn gettimeofday(tv: *mut timeval, _tz: *mut c_void) -> c_int { if tv.is_null() { set_errno(EINVAL); return -1; @@ -146,17 +128,17 @@ pub extern "C" fn gettimeofday(tv: *mut Timeval, _tz: *mut c_void) -> c_int { } #[unsafe(no_mangle)] -pub extern "C" fn _exit(ec: c_int) -> ! { +extern "C" fn _exit(ec: c_int) -> ! { hyperlight_guest::exit::abort_with_code(&[ec as u8]); } #[unsafe(no_mangle)] -pub extern "C" fn lseek(_fd: c_int, _offset: c_long, _whence: c_int) -> c_long { +extern "C" fn lseek(_fd: c_int, _offset: c_long, _whence: c_int) -> c_long { set_errno(ENOSYS); -1 } #[unsafe(no_mangle)] -pub extern "C" fn close(_fd: c_int) -> c_int { +extern "C" fn close(_fd: c_int) -> c_int { 0 } diff --git a/src/hyperlight_libc/.cargo/config.toml b/src/hyperlight_libc/.cargo/config.toml new file mode 100644 index 000000000..d430fa44c --- /dev/null +++ b/src/hyperlight_libc/.cargo/config.toml @@ -0,0 +1,2 @@ +[build] +target = "x86_64-unknown-none" diff --git a/src/hyperlight_libc/Cargo.toml b/src/hyperlight_libc/Cargo.toml new file mode 100644 index 000000000..b0fa84511 --- /dev/null +++ b/src/hyperlight_libc/Cargo.toml @@ -0,0 +1,30 @@ + +[package] +name = "hyperlight-libc" +links = "c" +version.workspace = true +edition.workspace = true +rust-version.workspace = true +license.workspace = true +homepage.workspace = true +repository.workspace = true +readme.workspace = true +description = """ +This crate provides picolibc for Hyperlight guests. +It builds the picolibc library and generates bindings to the libc types and functions. +""" + +[features] +default = [] + +[dependencies] + +[lints] +workspace = true + +[build-dependencies] +anyhow = "1" +cc = "1.2" +cfg-if = "1.0" +glob = "0.3.3" +bindgen = { version = "0.71", features = ["prettyplease"] } diff --git a/src/hyperlight_guest_bin/build.rs b/src/hyperlight_libc/build.rs similarity index 83% rename from src/hyperlight_guest_bin/build.rs rename to src/hyperlight_libc/build.rs index 310f7f6fb..9367038da 100644 --- a/src/hyperlight_guest_bin/build.rs +++ b/src/hyperlight_libc/build.rs @@ -21,6 +21,8 @@ use std::process::Command; use std::{env, fs}; use anyhow::{Context, Result, bail}; +use bindgen::Formatter::Prettyplease; +use bindgen::RustEdition::Edition2021; use build_files::{LIBC_FILES, LIBC_FILES_X86, LIBM_FILES, LIBM_FILES_X86}; fn copy_includes, Q: AsRef + std::fmt::Debug>( @@ -59,6 +61,7 @@ fn cc_build(picolibc_dir: &PathBuf, target: &str) -> Result { build .flag("-fPIC") .flag("-nostdlib") + .flag("-nostdlibinc") .flag("-ffreestanding") .flag("-fno-common") .flag("-fno-builtin") @@ -176,6 +179,45 @@ fn init_submodule() -> Result<()> { Ok(()) } +fn generate_bindings(include_dir: &Path, out_dir: &Path) -> Result<()> { + bindgen::Builder::default() + .header(include_dir.join("stdlib.h").to_string_lossy()) + .header(include_dir.join("stdio.h").to_string_lossy()) + .header(include_dir.join("string.h").to_string_lossy()) + .header(include_dir.join("math.h").to_string_lossy()) + .header(include_dir.join("stdint.h").to_string_lossy()) + .header(include_dir.join("ctype.h").to_string_lossy()) + .header(include_dir.join("errno.h").to_string_lossy()) + .header(include_dir.join("time.h").to_string_lossy()) + .header(include_dir.join("limits.h").to_string_lossy()) + .header(include_dir.join("signal.h").to_string_lossy()) + .header(include_dir.join("setjmp.h").to_string_lossy()) + .header(include_dir.join("locale.h").to_string_lossy()) + .header(include_dir.join("wchar.h").to_string_lossy()) + .header(include_dir.join("wctype.h").to_string_lossy()) + .header(include_dir.join("fenv.h").to_string_lossy()) + .header(include_dir.join("inttypes.h").to_string_lossy()) + .header(include_dir.join("sys/time.h").to_string_lossy()) + .clang_arg(format!("-I{}", include_dir.display())) + .clang_arg("-nostdlibinc") + .clang_arg("--target=x86_64-unknown-linux-none") + .clang_arg("-fno-stack-protector") + .clang_arg("-D_POSIX_MONOTONIC_CLOCK=1") + .use_core() + .wrap_unsafe_ops(true) + .rust_edition(Edition2021) + .formatter(Prettyplease) + .ctypes_prefix("core::ffi") + .generate_cstr(true) + .layout_tests(false) + .generate() + .context("Unable to generate bindings")? + .write_to_file(out_dir.join("bindings.rs")) + .context("Couldn't write bindings")?; + + Ok(()) +} + fn cargo_main() -> Result<()> { println!("cargo:rerun-if-changed=build.rs"); println!("cargo:rerun-if-changed=third_party/picolibc"); @@ -193,29 +235,30 @@ fn cargo_main() -> Result<()> { let manifest_dir = PathBuf::from(manifest_dir); let picolibc_dir = manifest_dir.join("third_party/picolibc"); - if cfg!(feature = "libc") { - if !picolibc_dir.join("COPYING.picolibc").exists() { - eprintln!("Setting up submodules"); - init_submodule().with_context(|| "failed to init picolibc submodule")?; - } - - let mut build = cc_build(&picolibc_dir, &target)?; + if !picolibc_dir.join("COPYING.picolibc").exists() { + eprintln!("Setting up submodules"); + init_submodule().with_context(|| "failed to init picolibc submodule")?; + } - // include for picolibc configuration: picolibc.h - build.include(manifest_dir.join("include")); + let mut build = cc_build(&picolibc_dir, &target)?; - add_libc(&mut build, &picolibc_dir, &target)?; - add_libm(&mut build, &picolibc_dir, &target)?; + // include for picolibc configuration: picolibc.h + build.include(manifest_dir.join("include")); - if cfg!(windows) { - unsafe { env::set_var("AR_x86_64_unknown_none", "llvm-ar") }; - } + add_libc(&mut build, &picolibc_dir, &target)?; + add_libm(&mut build, &picolibc_dir, &target)?; - build.compile("hyperlight_guest_bin"); - copy_includes(&include_dir, picolibc_dir.join("libc/include"))?; - copy_includes(&include_dir, manifest_dir.join("include"))?; + if cfg!(windows) { + unsafe { env::set_var("AR_x86_64_unknown_none", "llvm-ar") }; } + build.compile("hyperlight_libc"); + copy_includes(&include_dir, picolibc_dir.join("libc/include"))?; + copy_includes(&include_dir, manifest_dir.join("include"))?; + + // Generate bindings using bindgen + generate_bindings(&include_dir, &PathBuf::from(&out_dir))?; + let include_str = include_dir .to_str() .with_context(|| "out dir include dir was not valid utf-8")?; diff --git a/src/hyperlight_guest_bin/build_files.rs b/src/hyperlight_libc/build_files.rs similarity index 100% rename from src/hyperlight_guest_bin/build_files.rs rename to src/hyperlight_libc/build_files.rs diff --git a/src/hyperlight_guest_bin/include/picolibc.h b/src/hyperlight_libc/include/picolibc.h similarity index 100% rename from src/hyperlight_guest_bin/include/picolibc.h rename to src/hyperlight_libc/include/picolibc.h diff --git a/src/hyperlight_libc/src/lib.rs b/src/hyperlight_libc/src/lib.rs new file mode 100644 index 000000000..741e3b8d9 --- /dev/null +++ b/src/hyperlight_libc/src/lib.rs @@ -0,0 +1,35 @@ +/* +Copyright 2025 The Hyperlight Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +//! Hyperlight libc crate +//! +//! This crate provides the picolibc library for Hyperlight guests. +//! It builds picolibc from source and generates Rust bindings to the +//! C library types and functions. + +#![no_std] +#![allow(non_upper_case_globals)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] +#![allow(dead_code)] +#![allow(clippy::missing_safety_doc)] +#![allow(clippy::approx_constant)] +#![allow(clippy::useless_transmute)] +#![allow(clippy::unnecessary_cast)] +#![allow(improper_ctypes)] + +// Include the generated bindings +include!(concat!(env!("OUT_DIR"), "/bindings.rs")); diff --git a/src/hyperlight_guest_bin/third_party/README.md b/src/hyperlight_libc/third_party/README.md similarity index 100% rename from src/hyperlight_guest_bin/third_party/README.md rename to src/hyperlight_libc/third_party/README.md diff --git a/src/hyperlight_guest_bin/third_party/picolibc b/src/hyperlight_libc/third_party/picolibc similarity index 100% rename from src/hyperlight_guest_bin/third_party/picolibc rename to src/hyperlight_libc/third_party/picolibc diff --git a/src/tests/c_guests/c_simpleguest/main.c b/src/tests/c_guests/c_simpleguest/main.c index d59df3729..91da1973c 100644 --- a/src/tests/c_guests/c_simpleguest/main.c +++ b/src/tests/c_guests/c_simpleguest/main.c @@ -1,6 +1,6 @@ // Included from hyperlight_guest_capi/include #include "hyperlight_guest.h" -// Included from hyperlight_guest_bin/third_party/picolibc +// Included from hyperlight_libc/third_party/picolibc #include "stdint.h" #include "string.h" #include "stdlib.h" diff --git a/src/tests/rust_guests/dummyguest/Cargo.lock b/src/tests/rust_guests/dummyguest/Cargo.lock index 6ee29f78e..795e44fec 100644 --- a/src/tests/rust_guests/dummyguest/Cargo.lock +++ b/src/tests/rust_guests/dummyguest/Cargo.lock @@ -2,12 +2,41 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "aho-corasick" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301" +dependencies = [ + "memchr", +] + [[package]] name = "anyhow" version = "1.0.102" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" +[[package]] +name = "bindgen" +version = "0.71.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f58bf3d7db68cfbac37cfc485a8d711e87e064c3d0fe0435b92f7a407f9d6b3" +dependencies = [ + "bitflags", + "cexpr", + "clang-sys", + "itertools", + "log", + "prettyplease", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "syn", +] + [[package]] name = "bitflags" version = "2.11.0" @@ -33,12 +62,32 @@ dependencies = [ "shlex", ] +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom", +] + [[package]] name = "cfg-if" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" +[[package]] +name = "clang-sys" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" +dependencies = [ + "glob", + "libc", + "libloading", +] + [[package]] name = "dummyguest" version = "0.10.0" @@ -47,6 +96,12 @@ dependencies = [ "hyperlight-guest-bin", ] +[[package]] +name = "either" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" + [[package]] name = "equivalent" version = "1.0.2" @@ -111,14 +166,13 @@ version = "0.14.0" dependencies = [ "anyhow", "buddy_system_allocator", - "cc", "cfg-if", "flatbuffers", - "glob", "hyperlight-common", "hyperlight-guest", "hyperlight-guest-macro", "hyperlight-guest-tracing", + "hyperlight-libc", "linkme", "log", "spin", @@ -145,6 +199,17 @@ dependencies = [ "tracing-core", ] +[[package]] +name = "hyperlight-libc" +version = "0.14.0" +dependencies = [ + "anyhow", + "bindgen", + "cc", + "cfg-if", + "glob", +] + [[package]] name = "indexmap" version = "2.13.0" @@ -155,12 +220,37 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "itertools" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" +[[package]] +name = "libc" +version = "0.2.186" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66" + +[[package]] +name = "libloading" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55" +dependencies = [ + "cfg-if", + "windows-link", +] + [[package]] name = "linkme" version = "0.3.36" @@ -202,12 +292,38 @@ version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + [[package]] name = "pin-project-lite" version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" +[[package]] +name = "prettyplease" +version = "0.2.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" +dependencies = [ + "proc-macro2", + "syn", +] + [[package]] name = "proc-macro-crate" version = "3.5.0" @@ -235,6 +351,41 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "regex" +version = "1.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e10754a14b9137dd7b1e3e5b0493cc9171fdd105e0ab477f51b72e7f3ac0e276" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a" + +[[package]] +name = "rustc-hash" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94300abf3f1ae2e2b8ffb7b58043de3d399c73fa6f4b73826402a5c457614dbe" + [[package]] name = "rustc_version" version = "0.4.1" @@ -408,6 +559,12 @@ version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + [[package]] name = "winnow" version = "1.0.0" @@ -421,4 +578,4 @@ dependencies = [ name = "zmij" version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" \ No newline at end of file +checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" diff --git a/src/tests/rust_guests/simpleguest/Cargo.lock b/src/tests/rust_guests/simpleguest/Cargo.lock index dafa6297c..ba00d8408 100644 --- a/src/tests/rust_guests/simpleguest/Cargo.lock +++ b/src/tests/rust_guests/simpleguest/Cargo.lock @@ -2,12 +2,41 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "aho-corasick" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301" +dependencies = [ + "memchr", +] + [[package]] name = "anyhow" version = "1.0.102" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" +[[package]] +name = "bindgen" +version = "0.71.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f58bf3d7db68cfbac37cfc485a8d711e87e064c3d0fe0435b92f7a407f9d6b3" +dependencies = [ + "bitflags", + "cexpr", + "clang-sys", + "itertools", + "log", + "prettyplease", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "syn", +] + [[package]] name = "bitflags" version = "2.11.0" @@ -33,12 +62,38 @@ dependencies = [ "shlex", ] +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom", +] + [[package]] name = "cfg-if" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" +[[package]] +name = "clang-sys" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" +dependencies = [ + "glob", + "libc", + "libloading", +] + +[[package]] +name = "either" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" + [[package]] name = "equivalent" version = "1.0.2" @@ -103,14 +158,13 @@ version = "0.14.0" dependencies = [ "anyhow", "buddy_system_allocator", - "cc", "cfg-if", "flatbuffers", - "glob", "hyperlight-common", "hyperlight-guest", "hyperlight-guest-macro", "hyperlight-guest-tracing", + "hyperlight-libc", "linkme", "log", "spin", @@ -137,6 +191,17 @@ dependencies = [ "tracing-core", ] +[[package]] +name = "hyperlight-libc" +version = "0.14.0" +dependencies = [ + "anyhow", + "bindgen", + "cc", + "cfg-if", + "glob", +] + [[package]] name = "indexmap" version = "2.13.0" @@ -147,12 +212,37 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "itertools" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" +[[package]] +name = "libc" +version = "0.2.186" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66" + +[[package]] +name = "libloading" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55" +dependencies = [ + "cfg-if", + "windows-link", +] + [[package]] name = "linkme" version = "0.3.36" @@ -194,12 +284,38 @@ version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + [[package]] name = "pin-project-lite" version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" +[[package]] +name = "prettyplease" +version = "0.2.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" +dependencies = [ + "proc-macro2", + "syn", +] + [[package]] name = "proc-macro-crate" version = "3.5.0" @@ -227,6 +343,41 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "regex" +version = "1.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e10754a14b9137dd7b1e3e5b0493cc9171fdd105e0ab477f51b72e7f3ac0e276" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a" + +[[package]] +name = "rustc-hash" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94300abf3f1ae2e2b8ffb7b58043de3d399c73fa6f4b73826402a5c457614dbe" + [[package]] name = "rustc_version" version = "0.4.1" @@ -413,6 +564,12 @@ version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + [[package]] name = "winnow" version = "1.0.0" @@ -426,4 +583,4 @@ dependencies = [ name = "zmij" version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" \ No newline at end of file +checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" diff --git a/src/tests/rust_guests/witguest/Cargo.lock b/src/tests/rust_guests/witguest/Cargo.lock index e3d4c4663..1fa76f964 100644 --- a/src/tests/rust_guests/witguest/Cargo.lock +++ b/src/tests/rust_guests/witguest/Cargo.lock @@ -67,6 +67,26 @@ version = "1.0.102" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" +[[package]] +name = "bindgen" +version = "0.71.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f58bf3d7db68cfbac37cfc485a8d711e87e064c3d0fe0435b92f7a407f9d6b3" +dependencies = [ + "bitflags", + "cexpr", + "clang-sys", + "itertools 0.13.0", + "log", + "prettyplease", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "syn", +] + [[package]] name = "bitflags" version = "2.11.0" @@ -92,12 +112,32 @@ dependencies = [ "shlex", ] +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom", +] + [[package]] name = "cfg-if" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" +[[package]] +name = "clang-sys" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" +dependencies = [ + "glob", + "libc", + "libloading", +] + [[package]] name = "colorchoice" version = "1.0.5" @@ -196,7 +236,7 @@ version = "0.14.0" dependencies = [ "env_logger", "hyperlight-component-util", - "itertools", + "itertools 0.14.0", "prettyplease", "proc-macro2", "quote", @@ -208,7 +248,7 @@ dependencies = [ name = "hyperlight-component-util" version = "0.14.0" dependencies = [ - "itertools", + "itertools 0.14.0", "prettyplease", "proc-macro2", "quote", @@ -235,14 +275,13 @@ version = "0.14.0" dependencies = [ "anyhow", "buddy_system_allocator", - "cc", "cfg-if", "flatbuffers", - "glob", "hyperlight-common", "hyperlight-guest", "hyperlight-guest-macro", "hyperlight-guest-tracing", + "hyperlight-libc", "linkme", "log", "spin", @@ -269,6 +308,17 @@ dependencies = [ "tracing-core", ] +[[package]] +name = "hyperlight-libc" +version = "0.14.0" +dependencies = [ + "anyhow", + "bindgen", + "cc", + "cfg-if", + "glob", +] + [[package]] name = "indexmap" version = "2.14.0" @@ -287,6 +337,15 @@ version = "1.70.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" +[[package]] +name = "itertools" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" +dependencies = [ + "either", +] + [[package]] name = "itertools" version = "0.14.0" @@ -326,6 +385,22 @@ dependencies = [ "syn", ] +[[package]] +name = "libc" +version = "0.2.186" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66" + +[[package]] +name = "libloading" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55" +dependencies = [ + "cfg-if", + "windows-link", +] + [[package]] name = "linkme" version = "0.3.36" @@ -367,6 +442,22 @@ version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + [[package]] name = "once_cell" version = "1.21.4" @@ -466,6 +557,12 @@ version = "0.8.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a" +[[package]] +name = "rustc-hash" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94300abf3f1ae2e2b8ffb7b58043de3d399c73fa6f4b73826402a5c457614dbe" + [[package]] name = "rustc_version" version = "0.4.1" @@ -701,4 +798,4 @@ dependencies = [ name = "zmij" version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" \ No newline at end of file +checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" From 2c44d53ec5092b6467f34afef7a21dcfb7958ef5 Mon Sep 17 00:00:00 2001 From: Jorge Prendes Date: Wed, 6 May 2026 09:30:28 +0100 Subject: [PATCH 02/10] cleanup Cargo.toml Signed-off-by: Jorge Prendes --- Cargo.lock | 3 --- src/hyperlight_guest_bin/Cargo.toml | 4 ---- src/hyperlight_libc/Cargo.toml | 1 - src/tests/rust_guests/dummyguest/Cargo.lock | 3 --- src/tests/rust_guests/simpleguest/Cargo.lock | 3 --- src/tests/rust_guests/witguest/Cargo.lock | 3 --- 6 files changed, 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4f1d81215..a91bfef34 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1524,9 +1524,7 @@ dependencies = [ name = "hyperlight-guest-bin" version = "0.14.0" dependencies = [ - "anyhow", "buddy_system_allocator", - "cfg-if", "flatbuffers", "hyperlight-common", "hyperlight-guest", @@ -1636,7 +1634,6 @@ dependencies = [ "anyhow", "bindgen 0.71.1", "cc", - "cfg-if", "glob", ] diff --git a/src/hyperlight_guest_bin/Cargo.toml b/src/hyperlight_guest_bin/Cargo.toml index f2d966abf..060f67b88 100644 --- a/src/hyperlight_guest_bin/Cargo.toml +++ b/src/hyperlight_guest_bin/Cargo.toml @@ -34,7 +34,3 @@ tracing = { version = "0.1.44", default-features = false, features = ["attribute [lints] workspace = true - -[build-dependencies] -anyhow = "1" -cfg-if = "1.0" diff --git a/src/hyperlight_libc/Cargo.toml b/src/hyperlight_libc/Cargo.toml index b0fa84511..7100280c9 100644 --- a/src/hyperlight_libc/Cargo.toml +++ b/src/hyperlight_libc/Cargo.toml @@ -25,6 +25,5 @@ workspace = true [build-dependencies] anyhow = "1" cc = "1.2" -cfg-if = "1.0" glob = "0.3.3" bindgen = { version = "0.71", features = ["prettyplease"] } diff --git a/src/tests/rust_guests/dummyguest/Cargo.lock b/src/tests/rust_guests/dummyguest/Cargo.lock index 795e44fec..ae882df07 100644 --- a/src/tests/rust_guests/dummyguest/Cargo.lock +++ b/src/tests/rust_guests/dummyguest/Cargo.lock @@ -164,9 +164,7 @@ dependencies = [ name = "hyperlight-guest-bin" version = "0.14.0" dependencies = [ - "anyhow", "buddy_system_allocator", - "cfg-if", "flatbuffers", "hyperlight-common", "hyperlight-guest", @@ -206,7 +204,6 @@ dependencies = [ "anyhow", "bindgen", "cc", - "cfg-if", "glob", ] diff --git a/src/tests/rust_guests/simpleguest/Cargo.lock b/src/tests/rust_guests/simpleguest/Cargo.lock index ba00d8408..0866175d8 100644 --- a/src/tests/rust_guests/simpleguest/Cargo.lock +++ b/src/tests/rust_guests/simpleguest/Cargo.lock @@ -156,9 +156,7 @@ dependencies = [ name = "hyperlight-guest-bin" version = "0.14.0" dependencies = [ - "anyhow", "buddy_system_allocator", - "cfg-if", "flatbuffers", "hyperlight-common", "hyperlight-guest", @@ -198,7 +196,6 @@ dependencies = [ "anyhow", "bindgen", "cc", - "cfg-if", "glob", ] diff --git a/src/tests/rust_guests/witguest/Cargo.lock b/src/tests/rust_guests/witguest/Cargo.lock index 1fa76f964..0af6a2747 100644 --- a/src/tests/rust_guests/witguest/Cargo.lock +++ b/src/tests/rust_guests/witguest/Cargo.lock @@ -273,9 +273,7 @@ dependencies = [ name = "hyperlight-guest-bin" version = "0.14.0" dependencies = [ - "anyhow", "buddy_system_allocator", - "cfg-if", "flatbuffers", "hyperlight-common", "hyperlight-guest", @@ -315,7 +313,6 @@ dependencies = [ "anyhow", "bindgen", "cc", - "cfg-if", "glob", ] From dc46f7bf1da9aee14a3eb876e8c258115342b415 Mon Sep 17 00:00:00 2001 From: Jorge Prendes Date: Wed, 6 May 2026 09:30:44 +0100 Subject: [PATCH 03/10] remove crate local .cargo/config.toml Signed-off-by: Jorge Prendes --- src/hyperlight_guest_bin/.cargo/config.toml | 2 -- src/hyperlight_libc/.cargo/config.toml | 2 -- 2 files changed, 4 deletions(-) delete mode 100644 src/hyperlight_guest_bin/.cargo/config.toml delete mode 100644 src/hyperlight_libc/.cargo/config.toml diff --git a/src/hyperlight_guest_bin/.cargo/config.toml b/src/hyperlight_guest_bin/.cargo/config.toml deleted file mode 100644 index d430fa44c..000000000 --- a/src/hyperlight_guest_bin/.cargo/config.toml +++ /dev/null @@ -1,2 +0,0 @@ -[build] -target = "x86_64-unknown-none" diff --git a/src/hyperlight_libc/.cargo/config.toml b/src/hyperlight_libc/.cargo/config.toml deleted file mode 100644 index d430fa44c..000000000 --- a/src/hyperlight_libc/.cargo/config.toml +++ /dev/null @@ -1,2 +0,0 @@ -[build] -target = "x86_64-unknown-none" From 64ea2ab8148e50c4882211f993b4c087e0811886 Mon Sep 17 00:00:00 2001 From: Jorge Prendes Date: Wed, 6 May 2026 09:45:36 +0100 Subject: [PATCH 04/10] use cargo-hyperlight 0.1.10 Signed-off-by: Jorge Prendes --- .github/workflows/RustNightly.yml | 2 +- .github/workflows/dep_build_guests.yml | 2 +- .github/workflows/dep_code_checks.yml | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/RustNightly.yml b/.github/workflows/RustNightly.yml index 6813bb9de..a04941d93 100644 --- a/.github/workflows/RustNightly.yml +++ b/.github/workflows/RustNightly.yml @@ -78,7 +78,7 @@ jobs: src/tests/rust_guests/witguest -> target - name: Install cargo-hyperlight - run: cargo install cargo-hyperlight --version 0.1.9 --locked --force + run: cargo install cargo-hyperlight --version 0.1.10 --locked --force - name: Build and move Rust guests run: | diff --git a/.github/workflows/dep_build_guests.yml b/.github/workflows/dep_build_guests.yml index 108a7a3b5..74df33cb2 100644 --- a/.github/workflows/dep_build_guests.yml +++ b/.github/workflows/dep_build_guests.yml @@ -68,7 +68,7 @@ jobs: src/tests/rust_guests/witguest -> target - name: Install cargo-hyperlight - run: cargo install cargo-hyperlight --version 0.1.9 --locked --force + run: cargo install cargo-hyperlight --version 0.1.10 --locked --force - name: Build Rust guests run: | diff --git a/.github/workflows/dep_code_checks.yml b/.github/workflows/dep_code_checks.yml index 9b916fe5b..dbfcccdeb 100644 --- a/.github/workflows/dep_code_checks.yml +++ b/.github/workflows/dep_code_checks.yml @@ -74,7 +74,7 @@ jobs: run: just fmt-check - name: Install cargo-hyperlight - run: cargo install cargo-hyperlight --version 0.1.9 --locked --force + run: cargo install cargo-hyperlight --version 0.1.10 --locked --force - name: clippy exhaustive check (debug) run: just clippy-exhaustive debug @@ -145,7 +145,7 @@ jobs: run: just fmt-check - name: Install cargo-hyperlight - run: cargo install cargo-hyperlight --version 0.1.9 --locked --force + run: cargo install cargo-hyperlight --version 0.1.10 --locked --force - name: clippy (debug) run: | From da1e7a3a67c54a4fb7948e31e7e8d4e8a8cb5d26 Mon Sep 17 00:00:00 2001 From: Jorge Prendes Date: Wed, 6 May 2026 11:14:46 +0100 Subject: [PATCH 05/10] Add derives to bindings Signed-off-by: Jorge Prendes --- src/hyperlight_libc/build.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/hyperlight_libc/build.rs b/src/hyperlight_libc/build.rs index 9367038da..d80c66de5 100644 --- a/src/hyperlight_libc/build.rs +++ b/src/hyperlight_libc/build.rs @@ -208,6 +208,13 @@ fn generate_bindings(include_dir: &Path, out_dir: &Path) -> Result<()> { .rust_edition(Edition2021) .formatter(Prettyplease) .ctypes_prefix("core::ffi") + .derive_copy(true) + .derive_debug(true) + .derive_default(true) + .derive_eq(true) + .derive_hash(true) + .derive_ord(true) + .generate_comments(true) .generate_cstr(true) .layout_tests(false) .generate() From 1b9ecb1cb906a18a6e9f320fbf066be9a3989833 Mon Sep 17 00:00:00 2001 From: Jorge Prendes Date: Wed, 6 May 2026 11:15:19 +0100 Subject: [PATCH 06/10] Move gettimeofday to use clock_gettime Signed-off-by: Jorge Prendes --- src/hyperlight_guest_bin/src/libc_stubs.rs | 20 ++------------------ src/hyperlight_libc/src/lib.rs | 4 ++++ src/hyperlight_libc/src/stubs.rs | 22 ++++++++++++++++++++++ 3 files changed, 28 insertions(+), 18 deletions(-) create mode 100644 src/hyperlight_libc/src/stubs.rs diff --git a/src/hyperlight_guest_bin/src/libc_stubs.rs b/src/hyperlight_guest_bin/src/libc_stubs.rs index 1d1810291..6dc208421 100644 --- a/src/hyperlight_guest_bin/src/libc_stubs.rs +++ b/src/hyperlight_guest_bin/src/libc_stubs.rs @@ -16,15 +16,14 @@ limitations under the License. use alloc::string::String; use alloc::vec; -use core::ffi::{c_int, c_long, c_void}; use core::sync::atomic::{AtomicU64, Ordering}; use hyperlight_common::flatbuffer_wrappers::function_types::{ParameterValue, ReturnType}; use crate::host_comm::call_host_function; use crate::libc::{ - CLOCK_MONOTONIC, CLOCK_REALTIME, EBADF, EINVAL, EIO, ENOSYS, clockid_t, errno, timespec, - timeval, + CLOCK_MONOTONIC, CLOCK_REALTIME, EBADF, EINVAL, EIO, ENOSYS, c_int, c_long, c_void, clockid_t, + errno, timespec, }; fn set_errno(val: u32) { @@ -112,21 +111,6 @@ extern "C" fn clock_gettime(clk_id: clockid_t, tp: *mut timespec) -> c_int { } } -#[unsafe(no_mangle)] -extern "C" fn gettimeofday(tv: *mut timeval, _tz: *mut c_void) -> c_int { - if tv.is_null() { - set_errno(EINVAL); - return -1; - } - - let (secs, nanos) = current_time(); - unsafe { - (*tv).tv_sec = secs as c_long; - (*tv).tv_usec = (nanos / 1000) as c_long; - } - 0 -} - #[unsafe(no_mangle)] extern "C" fn _exit(ec: c_int) -> ! { hyperlight_guest::exit::abort_with_code(&[ec as u8]); diff --git a/src/hyperlight_libc/src/lib.rs b/src/hyperlight_libc/src/lib.rs index 741e3b8d9..b18f0cd4c 100644 --- a/src/hyperlight_libc/src/lib.rs +++ b/src/hyperlight_libc/src/lib.rs @@ -33,3 +33,7 @@ limitations under the License. // Include the generated bindings include!(concat!(env!("OUT_DIR"), "/bindings.rs")); + +pub use core::ffi::*; + +mod stubs; diff --git a/src/hyperlight_libc/src/stubs.rs b/src/hyperlight_libc/src/stubs.rs new file mode 100644 index 000000000..3308dddee --- /dev/null +++ b/src/hyperlight_libc/src/stubs.rs @@ -0,0 +1,22 @@ +use crate::{CLOCK_REALTIME, EINVAL, c_int, c_void, clock_gettime, errno, timespec, timeval}; + +#[unsafe(no_mangle)] +extern "C" fn gettimeofday(tv: *mut timeval, _tz: *mut c_void) -> c_int { + if tv.is_null() { + unsafe { errno = EINVAL as _ }; + return -1; + } + + let mut ts = timespec::default(); + let res = unsafe { clock_gettime(CLOCK_REALTIME as _, &raw mut ts) }; + if res != 0 { + return -1; + } + + unsafe { + (*tv).tv_sec = ts.tv_sec; + (*tv).tv_usec = ts.tv_nsec / 1000; + } + + 0 +} From eeac5c1f77dfaf6c96fe24c10a08ba5720e32acd Mon Sep 17 00:00:00 2001 From: Jorge Prendes Date: Wed, 6 May 2026 11:15:47 +0100 Subject: [PATCH 07/10] fix picolibc.md Signed-off-by: Jorge Prendes --- docs/picolibc.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/picolibc.md b/docs/picolibc.md index d6a7ce44f..e37a6a816 100644 --- a/docs/picolibc.md +++ b/docs/picolibc.md @@ -17,7 +17,7 @@ licensing details. ## Host Function Stubs -When the `libc` feature is enabled, the POSIX stubs in `src/hyperlight_guest_bin/src/libc.rs` +When the `libc` feature is enabled, the POSIX stubs in `src/hyperlight_guest_bin/src/libc_stubs.rs` provide C-compatible implementations of `read`, `write`, `clock_gettime`, `gettimeofday`, and other functions that picolibc calls internally. From a49512bdf386eff46394291543c9de63f524a14a Mon Sep 17 00:00:00 2001 From: Jorge Prendes Date: Wed, 6 May 2026 11:16:04 +0100 Subject: [PATCH 08/10] Add README.md to hyperlight-libc Signed-off-by: Jorge Prendes --- src/hyperlight_libc/README.md | 107 ++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 src/hyperlight_libc/README.md diff --git a/src/hyperlight_libc/README.md b/src/hyperlight_libc/README.md new file mode 100644 index 000000000..1a9ff2a4a --- /dev/null +++ b/src/hyperlight_libc/README.md @@ -0,0 +1,107 @@ +# hyperlight-libc + +This crate provides a C standard library implementation for Hyperlight guest binaries based on +[picolibc](https://github.com/picolibc/picolibc). It compiles picolibc from source and generates +Rust bindings to the C library types and functions using [bindgen](https://github.com/rust-lang/rust-bindgen). + +## Overview + +`hyperlight-libc` is designed to be used together with `hyperlight-guest-bin` to build Hyperlight +guest binaries. When the `libc` feature is enabled on `hyperlight-guest-bin` (enabled by default), +this crate is automatically included as a dependency. + +The crate: +- Builds picolibc from source during compilation +- Generates Rust bindings to libc types (e.g., `timespec`, `timeval`, `clockid_t`) and constants + (e.g., `EINVAL`, `EBADF`, `CLOCK_REALTIME`) +- Exports the include directory via cargo metadata for downstream C compilation needs + +## Picolibc Configuration + +Picolibc is configured for Hyperlight's micro-VM environment with: + +- **Single-threaded**: No locking or TLS support +- **Global errno**: Uses a single global `errno` variable +- **Tiny stdio**: Minimal stdio implementation +- **No malloc**: Memory allocation is handled by the Rust global allocator +- **IEEE math**: Math library without errno side effects + +The configuration is defined in `include/picolibc.h`. + +## Using the Bindings + +When using `hyperlight-guest-bin` with the `libc` feature enabled, the bindings are re-exported as +`hyperlight_guest_bin::libc`: + +```rust +use hyperlight_guest_bin::libc::{errno, timespec, EINVAL, CLOCK_REALTIME}; +``` + +## POSIX Stub Requirements + +Picolibc expects certain POSIX functions to be available at link time. When using this crate, +downstream code must provide implementations for these functions. The `hyperlight-guest-bin` crate +provides these in `src/libc_stubs.rs`, which can serve as a reference. + +Required stubs include: + +| Function | Purpose | +|----------|---------| +| `read` | Read from file descriptor (e.g., stdin support) | +| `write` | Write to file descriptor (e.g., stdout/stderr for `printf`) | +| `clock_gettime` | Get current time | +| `_exit` | Terminate the program | +| `lseek` | Seek in file (can return `ENOSYS` for basic stdio support) | +| `close` | Close file descriptor | + +### Example Stub Implementation + +Here's an example of how to implement the `write` stub that delegates to a host function: + +```rust +use alloc::string::String; +use core::ffi::{c_int, c_void}; +use hyperlight_guest_bin::host_function; +use hyperlight_guest_bin::libc::{errno, EINVAL, EBADF, EIO}; + +#[host_function("HostPrint")] +fn host_print(message: String) -> i32; + +#[unsafe(no_mangle)] +extern "C" fn write(fd: c_int, buf: *const c_void, count: usize) -> isize { + // Validate input buffer + if buf.is_null() && count > 0 { + unsafe { errno = EINVAL as _ }; + return -1; + } + + // Only support stdout (1) and stderr (2) + if fd != 1 && fd != 2 { + unsafe { errno = EBADF as _ }; + return -1; + } + + // Read the buffer and convert to a String + let buf = unsafe { core::slice::from_raw_parts(buf as *const u8, count) }; + let text = String::from_utf8_lossy(buf).into_owned(); + + // Delegate to the host function + host_print(text); + + count as isize +} +``` + +## Picolibc Source + +The picolibc source is vendored as a git submodule at `third_party/picolibc`, pointing to +[picolibc-bsd](https://github.com/hyperlight-dev/picolibc-bsd) - a redistribution of picolibc with +all copyleft-licensed files (GPL/AGPL) removed. Only BSD/MIT/permissive-licensed source files are +present. + +See `NOTICE.txt` in the `picolibc-bsd` repository root for full licensing details. + +## For More Information + +For detailed information about the picolibc integration, including how to update picolibc to a new +version, see [docs/picolibc.md](../../docs/picolibc.md). From 9ffb3db9156df243db0ab066b60c5320ed2b66d1 Mon Sep 17 00:00:00 2001 From: Jorge Prendes Date: Wed, 6 May 2026 11:17:51 +0100 Subject: [PATCH 09/10] add license header Signed-off-by: Jorge Prendes --- src/hyperlight_libc/src/stubs.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/hyperlight_libc/src/stubs.rs b/src/hyperlight_libc/src/stubs.rs index 3308dddee..f1be0c97e 100644 --- a/src/hyperlight_libc/src/stubs.rs +++ b/src/hyperlight_libc/src/stubs.rs @@ -1,3 +1,19 @@ +/* +Copyright 2026 The Hyperlight Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + use crate::{CLOCK_REALTIME, EINVAL, c_int, c_void, clock_gettime, errno, timespec, timeval}; #[unsafe(no_mangle)] From d7ced65a99306a42fb9711fca1e604b8a3be7c24 Mon Sep 17 00:00:00 2001 From: Jorge Prendes Date: Wed, 6 May 2026 11:43:21 +0100 Subject: [PATCH 10/10] fix clippy Signed-off-by: Jorge Prendes --- src/hyperlight_libc/src/lib.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/hyperlight_libc/src/lib.rs b/src/hyperlight_libc/src/lib.rs index b18f0cd4c..ff4161173 100644 --- a/src/hyperlight_libc/src/lib.rs +++ b/src/hyperlight_libc/src/lib.rs @@ -21,15 +21,16 @@ limitations under the License. //! C library types and functions. #![no_std] -#![allow(non_upper_case_globals)] -#![allow(non_camel_case_types)] -#![allow(non_snake_case)] -#![allow(dead_code)] -#![allow(clippy::missing_safety_doc)] #![allow(clippy::approx_constant)] -#![allow(clippy::useless_transmute)] +#![allow(clippy::missing_safety_doc)] #![allow(clippy::unnecessary_cast)] +#![allow(clippy::useless_transmute)] +#![allow(dead_code)] #![allow(improper_ctypes)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] +#![allow(non_upper_case_globals)] +#![allow(unpredictable_function_pointer_comparisons)] // Include the generated bindings include!(concat!(env!("OUT_DIR"), "/bindings.rs"));