* feat: scaffold Rust native engine with grep module (napi-rs)
Adds a Rust N-API addon architecture inspired by Oh My Pi's pi-natives.
The grep module wraps ripgrep's core crates (grep-regex, grep-searcher,
grep-matcher) and exposes `search()` and `grep()` to Node.js via napi-rs.
Includes:
- Cargo workspace at native/ with engine (cdylib) and grep (lib) crates
- Build script (native/scripts/build.js) producing platform-tagged .node files
- TypeScript wrapper package (@gsd/native) with types and loader
- 6 Rust unit tests + 9 Node.js integration tests (all passing)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix: audit fixes for rust native engine PR
- Fix repository URL to gsd-build/gsd-2
- Remove dead add_custom_ignore_filename("") call
- Unify error model: search() now returns Result<> (throws) matching grep()
- Remove error field from NapiSearchResult and SearchResult types
- Use t.after() in integration tests for reliable temp dir cleanup
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
80 lines
1.8 KiB
Markdown
80 lines
1.8 KiB
Markdown
# GSD Native Engine
|
|
|
|
Rust N-API addon providing high-performance native modules for GSD.
|
|
|
|
## Architecture
|
|
|
|
```
|
|
JS (packages/native) -> N-API -> Rust crates
|
|
├── engine/ (N-API bindings, cdylib)
|
|
└── grep/ (ripgrep internals, pure Rust lib)
|
|
```
|
|
|
|
Inspired by [Oh My Pi's pi-natives](https://github.com/can1357/oh-my-pi), adapted for GSD's Node.js runtime.
|
|
|
|
## Prerequisites
|
|
|
|
- **Rust** (stable, 1.70+): https://rustup.rs
|
|
- **Node.js** (20.6+)
|
|
|
|
## Build
|
|
|
|
```bash
|
|
# Release build (optimized)
|
|
npm run build:native
|
|
|
|
# Debug build (fast compile, no optimizations)
|
|
npm run build:native:dev
|
|
```
|
|
|
|
The build script compiles the Rust code and copies the `.node` shared library to `native/addon/`.
|
|
|
|
## Test
|
|
|
|
```bash
|
|
# Rust unit tests
|
|
cd native && cargo test
|
|
|
|
# Node.js integration tests
|
|
npm run test:native
|
|
```
|
|
|
|
## Modules
|
|
|
|
### grep
|
|
|
|
Ripgrep-backed regex search using the `grep-regex`, `grep-searcher`, and `grep-matcher` crates.
|
|
|
|
**Functions:**
|
|
|
|
- `search(content, options)` — Search in-memory Buffer/Uint8Array content
|
|
- `grep(options)` — Search files on disk with glob filtering and .gitignore support
|
|
|
|
**TypeScript usage:**
|
|
|
|
```typescript
|
|
import { grep, searchContent } from "@gsd/native";
|
|
|
|
// Search files
|
|
const result = grep({
|
|
pattern: "TODO",
|
|
path: "./src",
|
|
glob: "*.ts",
|
|
ignoreCase: true,
|
|
maxCount: 100,
|
|
});
|
|
|
|
// Search content
|
|
const contentResult = searchContent(Buffer.from(fileContent), {
|
|
pattern: "function\\s+\\w+",
|
|
contextBefore: 2,
|
|
contextAfter: 2,
|
|
});
|
|
```
|
|
|
|
## Adding New Modules
|
|
|
|
1. Create a new crate in `native/crates/` (pure Rust library)
|
|
2. Add N-API bindings in `native/crates/engine/src/`
|
|
3. Add TypeScript wrapper in `packages/native/src/`
|
|
4. Add the crate to `engine/Cargo.toml` dependencies
|