onig_sys builds oniguruma from C sources, so `cargo check --target wasm32-wasip1` fails unless the caller supplies a C WASI sysroot. Add a default-on `oniguruma` feature; `--no-default-features` drops the C dependency and falls back to a literal-only matcher that reports an explicit error for patterns needing a regex engine. Gating on the feature rather than on `target_os = "wasi"` keeps the real engine for WASI builds that do have a sysroot: oniguruma compiles and passes the full BRE/ERE/-P suite on wasm32-wasip2 when CC_wasm32_wasip2 and CFLAGS_wasm32_wasip2 point at a wasi-sdk. CI checks wasm32-wasip1 with --no-default-features and builds and tests the fallback natively.
Grep, now in Rust
A Rust implementation of GNU Grep. This project is an initial release and may contain bugs.
Install
cargo install uu_grep
🚀 Try it online
You can try grep directly in your browser on the uutils playground.
Arguments (and a full command) can be passed through the URL via the cmd query parameter, for example:
printf '🚀 rocket\n🛰️ satellite\n🌙 moon\n⭐ star\n' | grep 🌙
Building
Download Rust at: https://rustup.rs/
# Check out this repository
git clone https://github.com/uutils/grep
cd grep
# Build a release version
cargo build --release
# Run!
./target/release/grep --help
# Run tests (if needed; after making changes)
cargo test
The oniguruma feature
Regex matching is backed by oniguruma, a C
library built from source by onig_sys, so a build needs a C toolchain for the
target. That feature is on by default and is what provides BRE, ERE and -P.
Targets without a C toolchain can build with --no-default-features, which
drops the C dependency and leaves a matcher handling literal patterns only;
anything requiring a regex engine then exits with status 2 and an explicit
error. This is what makes cargo check --target wasm32-wasip1 --no-default-features work out of the box.
It is a feature rather than a target check on purpose: a WASI build that does have a C sysroot keeps the real engine. With a wasi-sdk installed, point the C toolchain at it and build with default features:
export CC_wasm32_wasip2=/opt/wasi-sdk/bin/clang
export CFLAGS_wasm32_wasip2="--sysroot=/opt/wasi-sdk/share/wasi-sysroot"
cargo build --target wasm32-wasip2
Pre-commit hooks
This project uses pre-commit; run pre-commit install to enable the git hooks.
Known Issues
- Does not take
LANG, etc., into account for handling file encodings (non-UTF8 matches are treated as binary) - No localization support yet
- Performances need to be improved
GNU test suite compatibility
Below is the evolution of how many GNU tests uutils passes.
Contributing
To contribute to uutils, please see CONTRIBUTING.
License
uutils is licensed under the MIT License - see the LICENSE file for details
GNU Grep is licensed under the GPL 3.0 or later.