-
Notifications
You must be signed in to change notification settings - Fork 0
feat(std): implement Phase 1 Rust std support via libc approach #72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2512efb to
92fb85c
Compare
Adds breenix_std crate providing std-like APIs for Breenix userspace: - GlobalAlloc implementation using brk/sbrk syscalls (bump allocator) - print!/println!/eprint!/eprintln! macros via StdoutWriter/StderrWriter - Panic handler with location information, exits with code 101 - Process module re-exporting libbreenix functions - Prelude module for convenient imports Also includes: - hello_std test program demonstrating Vec, String, Box, format! - Target spec update: os="none" -> os="breenix" - Build system integration (build.sh, kernel/build.rs) This enables Rust programs to use familiar patterns (println!, Vec, Box) without requiring the full Rust standard library. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Adds test_hello_std() function to test_exec.rs that validates breenix_std Stage 1 functionality (println!, Vec, String, Box, format!). Test marker: HELLO_STD_COMPLETE 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This document outlines the correct architecture for supporting the real Rust standard library on Breenix: - Rust-based libc (libbreenix-libc) providing C ABI wrappers - Leverages existing libbreenix syscall wrappers (~80% complete) - Follows Redox OS relibc model - Phased implementation: minimal std -> fs -> full libc -> threading The previous breenix_std approach was incorrect as it created a "std-like" library rather than enabling the real Rust std. This document clarifies the proper path forward. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Implement real Rust standard library support for Breenix userspace programs using a libc compatibility layer. This replaces the previous breenix_std approach with a more standard-compliant implementation. Key changes: - Add libbreenix-libc: C ABI wrappers around libbreenix syscalls - Add userspace/tests-std: Test programs using real Rust std (not no_std) - Update target spec with "os": "linux" for std compatibility - Add 20 boot stages (96-115) for comprehensive Rust std validation - Fix mmap region validation in kernel memory layout Test coverage (19 tests, all passing): - Core I/O: println!, read (error + success), write edge cases, close, pipe - Memory: malloc, realloc (grow/shrink), free, posix_memalign, mprotect, sbrk, mmap/munmap - Process: getpid, gettid, exit - Stubs: pthread_*, signal, sysconf, poll, fcntl, getenv, etc. - Honest failures: getrandom returns ENOSYS (no fake randomness) Removes deprecated breenix_std crate in favor of real std support. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The CI was failing because hello_std_real wasn't being built. This adds build steps for: 1. libbreenix-libc (produces libc.a and stub libraries) 2. userspace/tests-std (produces hello_std_real binary) Key fix: Clear inherited CARGO_* environment variables when building tests-std to avoid conflicts with the kernel build environment. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The CI was failing because hello_std_real wasn't being included in the test disk. The root cause was that create_test_disk() was called before the std test binaries were built. This fix adds a build_std_test_binaries() function that: 1. Builds libs/libbreenix-libc (produces libc.a) 2. Builds userspace/tests-std (produces hello_std_real) Both are built before create_test_disk() is called in boot_stages(), ensuring hello_std_real is available to be included in the test disk. The build uses cargo +nightly with environment variable isolation to avoid conflicts with the kernel build's cargo invocation. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The .gitignore was excluding these library directories, causing CI to fail because they were not included in the repository. Added exceptions to .gitignore and committed both libraries. - libs/libbreenix-libc: wrapper around libc for Breenix kernel - libs/libc: fork of rust-lang/libc with Breenix support 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The Rust nightly 1.94.0 expects target-pointer-width to be a u16 instead of a string in custom target specifications. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The xtask boot-stages command invokes `cargo +nightly` to build libbreenix-libc which uses -Z build-std. This requires rust-src to be installed for the latest nightly toolchain, not just the pinned nightly-2025-06-24. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add rust-toolchain.toml files to libs/libbreenix-libc and userspace/tests-std that pin to nightly-2025-06-24 - Remove +nightly flag from xtask cargo commands since the toolchain file specifies the version - Revert libc version to 0.2.174 to match our fork - Remove the extra "Install latest nightly" step from CI This ensures the std test builds use the same nightly version as the main kernel build, avoiding libc version mismatches. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The nightly-2025-06-24 toolchain expects target-pointer-width and target-c-int-width to be strings, not integers. The integer format was only introduced in later nightly versions. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Rust's std library expects to link against -lm, -lrt, -lpthread. Since
Breenix provides these functions through libc.a (libbreenix-libc), we
create empty archive stubs to satisfy the linker.
The stub libraries are just the AR magic header ("!<arch>\n") with no
members, which the linker accepts as empty archives.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The xtask boot-stages command has a 60-second timeout waiting for the serial output file to appear. Previously, this timeout would start before the kernel finished building (since cargo run triggers a build), leaving insufficient time for QEMU to actually boot. Added a pre-build step to ensure the kernel is compiled before the boot-stages test runs, so the full 60 seconds is available for QEMU. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
31c1542 to
63641bd
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Implement real Rust standard library support for Breenix userspace programs using a libc compatibility layer. This replaces the previous
breenix_stdapproach with a more standard-compliant implementation that enables realstdprograms (not#![no_std]) to run on Breenix.Key Changes
-Z build-std"os": "linux"for std compatibility (Breenix syscalls are Linux-compatible)Test Coverage (19 tests, all 115 boot stages passing)
Architecture
Validation
Test plan
cargo run -p xtask -- boot-stages)🤖 Generated with Claude Code