Skip to content

Build rust guests without hyperlight-libc#1505

Open
ludfjig wants to merge 1 commit into
hyperlight-dev:mainfrom
ludfjig:fix_rust_libc
Open

Build rust guests without hyperlight-libc#1505
ludfjig wants to merge 1 commit into
hyperlight-dev:mainfrom
ludfjig:fix_rust_libc

Conversation

@ludfjig
Copy link
Copy Markdown
Contributor

@ludfjig ludfjig commented Jun 4, 2026

Rust guests transitively depend on hyperlight-libc (picolibc) through hyperlight-guest-bin's default libc feature. The only reason the dependency was needed was an unconditional call to picolibc's srand in generic_init. The Rust guests themselves never use it.

This PR:

  • Gates the srand extern and the call in generic_init behind #[cfg(feature = "libc")].
  • Sets default-features = false on hyperlight-guest-bin in simpleguest, dummyguest, and witguest

I am also strongly considering making cargo feature libc a non-default cargo feature of hyperlight-guest-bin, since I am guessing most people who write rust guests do not need hyperlight-libc, but would appreciate more thoughts/feedback on that.

Closes #1483

Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
@ludfjig ludfjig added the kind/refactor For PRs that restructure or remove code without adding new functionality. label Jun 4, 2026
@ludfjig ludfjig marked this pull request as ready for review June 4, 2026 00:52
Copilot AI review requested due to automatic review settings June 4, 2026 00:52
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR reduces Rust guest dependencies by allowing hyperlight-guest-bin to be used without its default libc feature (and therefore without pulling in hyperlight-libc/picolibc) when the guest doesn’t need C/POSIX support.

Changes:

  • Gate the srand extern declaration and call in generic_init behind #[cfg(feature = "libc")].
  • Update Rust test guests (simpleguest, dummyguest, witguest) to depend on hyperlight-guest-bin with default-features = false (re-enabling only macros where needed).
  • Refresh the nested src/tests/rust_guests/Cargo.lock to reflect the reduced dependency graph (dropping hyperlight-libc and its transitive build deps).

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/hyperlight_guest_bin/src/lib.rs Makes srand usage conditional on the libc feature to avoid requiring picolibc when not needed.
src/tests/rust_guests/simpleguest/Cargo.toml Disables default features for hyperlight-guest-bin and explicitly enables macros for macro usage.
src/tests/rust_guests/dummyguest/Cargo.toml Disables default features for hyperlight-guest-bin to avoid transitive hyperlight-libc.
src/tests/rust_guests/witguest/Cargo.toml Disables default features for hyperlight-guest-bin to avoid transitive hyperlight-libc.
src/tests/rust_guests/Cargo.lock Updates lockfile to remove hyperlight-libc and related build dependencies from the guest workspace graph.
Comments suppressed due to low confidence (1)

src/hyperlight_guest_bin/src/lib.rs:232

  • generic_init renames seed to _seed, but the value is still used when feature = "libc" is enabled. This can trigger the used_underscore_binding warning (and CI runs clippy with -D warnings for hyperlight-guest-bin with --features libc). Prefer keeping the parameter named seed and explicitly marking it as used only in the non-libc configuration.
pub(crate) extern "C" fn generic_init(
    peb_address: u64,
    _seed: u64,
    ops: u64,
    max_log_level: u64,
) -> u64 {
    unsafe {
        GUEST_HANDLE = GuestHandle::init(peb_address as *mut HyperlightPEB);

Comment thread src/hyperlight_guest_bin/src/lib.rs
Copy link
Copy Markdown
Member

@andreiltd andreiltd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/refactor For PRs that restructure or remove code without adding new functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rust guests uses picolibc

3 participants