Skip to content

Rewrite findup to use no_std with direct libc syscalls for minimal bi…#1

Open
steveklabnik wants to merge 1 commit intoglehmann:mainfrom
steveklabnik:push-vokwmuywssxp
Open

Rewrite findup to use no_std with direct libc syscalls for minimal bi…#1
steveklabnik wants to merge 1 commit intoglehmann:mainfrom
steveklabnik:push-vokwmuywssxp

Conversation

@steveklabnik
Copy link
Copy Markdown

…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

…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
Comment thread src/main.rs
#[cfg(not(test))]
use core::slice;
#[cfg(test)]
use std::slice;
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

might want to just universally use core::slice

Comment thread Cargo.toml
name = "findup"
version = "0.1.0"
edition = "2024"
edition = "2021"
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

this is the result of bad conflict handling, should stay 2024

Comment thread src/main.rs
len
}

// Find parent directory by looking for last '/'
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

this fails on windows

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant