Rewrite findup to use no_std with direct libc syscalls for minimal bi…#1
Open
steveklabnik wants to merge 1 commit intoglehmann:mainfrom
Open
Rewrite findup to use no_std with direct libc syscalls for minimal bi…#1steveklabnik wants to merge 1 commit intoglehmann:mainfrom
steveklabnik wants to merge 1 commit intoglehmann:mainfrom
Conversation
…nary size This is a complete rewrite that eliminates all std dependencies and heap allocations: - Converted from std to no_std with custom C entry point (main) and panic handler - Replaced std::fs and PathBuf with direct libc calls (getcwd, stat, strlen) - All operations now use stack-allocated buffers (4096 byte arrays) - Added comprehensive error handling for edge cases (empty paths, buffer overflow) The implementation now directly interfaces with libc: - Uses getcwd() for current directory instead of env::current_dir() - Uses stat() syscall to check file existence instead of Path::exists() - Manual path string manipulation with byte slices instead of PathBuf - Zero-copy argument parsing from argv Added rust_eh_personality() symbol to satisfy DWARF debug info references in libcore that appear with panic=abort in recent Rust versions. This empty function is never actually called at runtime but prevents linker errors. Added extensive test suite with 24 unit tests covering: - Path traversal logic (find_parent edge cases) - Buffer safety (overflow handling, PATH_MAX limits) - C string operations (strlen with various inputs) - File existence checking with Miri-compatible mocks Cargo.toml changes: - Added libc dependency with default-features = false - Enhanced release profile for maximum size optimization
steveklabnik
commented
Nov 18, 2025
| #[cfg(not(test))] | ||
| use core::slice; | ||
| #[cfg(test)] | ||
| use std::slice; |
Author
There was a problem hiding this comment.
might want to just universally use core::slice
steveklabnik
commented
Nov 18, 2025
| name = "findup" | ||
| version = "0.1.0" | ||
| edition = "2024" | ||
| edition = "2021" |
Author
There was a problem hiding this comment.
this is the result of bad conflict handling, should stay 2024
steveklabnik
commented
Nov 18, 2025
| len | ||
| } | ||
|
|
||
| // Find parent directory by looking for last '/' |
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
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.
…nary size
This is a complete rewrite that eliminates all std dependencies and heap allocations:
The implementation now directly interfaces with libc:
Added rust_eh_personality() symbol to satisfy DWARF debug info references in libcore that appear with panic=abort in recent Rust versions. This empty function is never actually called at runtime but prevents linker errors.
Added extensive test suite with 24 unit tests covering:
Cargo.toml changes: