Skip to content

Commit ee7226e

Browse files
authored
feat(native): scaffold the NAPI-RS binding (#252)
1 parent 401d5c2 commit ee7226e

19 files changed

Lines changed: 2296 additions & 1 deletion

.gitattributes

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
# Let GitHub languages ignores MDX files
22
*.mdx linguist-documentation
3+
4+
# NAPI-RS owns these generated files; keep regeneration deterministic on Windows.
5+
packages/rstack/binding.cjs text eol=lf
6+
packages/rstack/binding.d.cts text eol=lf

.github/workflows/lint.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ jobs:
3737
- name: Build Packages
3838
run: node --run build
3939

40+
- name: Check Rust Format
41+
run: cargo fmt --all -- --check
42+
43+
- name: Lint Rust
44+
run: cargo clippy --workspace --all-targets --locked -- -D warnings
45+
4046
- name: Lint
4147
run: node --run lint
4248

.github/workflows/test.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,17 @@ jobs:
4040
- name: Build Packages
4141
run: node --run build
4242

43+
- name: Run Rust Tests
44+
run: cargo test --workspace --locked
45+
46+
- name: Build Native Binding
47+
run: pnpm --filter rstack build:native:release
48+
49+
- name: Test Native Binding
50+
run: pnpm --filter rstack test:native
51+
52+
- name: Check Generated Native Files
53+
run: git diff --exit-code -- packages/rstack/binding.cjs packages/rstack/binding.d.cts
54+
4355
- name: Run Test
4456
run: node --run test

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ dist-*/
1010
test-results
1111
doc_build
1212

13+
# Rust / NAPI-RS
14+
/target/
15+
/artifacts/
16+
/packages/rstack/*.node
17+
/packages/rstack/npm/
18+
1319
# Temp files
1420
test-temp-*
1521
TODO.md

Cargo.lock

Lines changed: 277 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[workspace]
2+
members = ["crates/rstack-binding"]
3+
resolver = "2"
4+
5+
[workspace.package]
6+
edition = "2021"
7+
license = "MIT"
8+
repository = "https://github.com/rstackjs/rstack-cli"
9+
rust-version = "1.88"
10+
11+
[workspace.dependencies]
12+
napi = { version = "3.12.0", default-features = false, features = ["napi9"] }
13+
napi-build = "2.4.0"
14+
napi-derive = "3.6.2"
15+
16+
[profile.release]
17+
lto = true
18+
strip = "symbols"

crates/rstack-binding/Cargo.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[package]
2+
name = "rstack-binding"
3+
version = "0.1.0"
4+
edition.workspace = true
5+
license.workspace = true
6+
repository.workspace = true
7+
rust-version.workspace = true
8+
publish = false
9+
10+
[lib]
11+
crate-type = ["cdylib"]
12+
13+
[dependencies]
14+
napi.workspace = true
15+
napi-derive.workspace = true
16+
17+
[build-dependencies]
18+
napi-build.workspace = true

crates/rstack-binding/build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
napi_build::setup();
3+
}

crates/rstack-binding/src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#![deny(clippy::all)]
2+
3+
use napi_derive::napi;
4+
5+
#[napi]
6+
pub fn native_ping(input: String) -> String {
7+
format!("pong:{input}")
8+
}
9+
10+
#[cfg(test)]
11+
mod tests {
12+
use super::native_ping;
13+
14+
#[test]
15+
fn formats_ping_response() {
16+
assert_eq!(native_ping("rstack".to_string()), "pong:rstack");
17+
}
18+
}

cspell.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export default {
1919
'coverage',
2020
'doc_build',
2121
'node_modules',
22+
'packages/rstack/binding.cjs',
2223
'packages/rstack/THIRD_PARTY_NOTICES.md',
2324
'pnpm-lock.yaml',
2425
],

0 commit comments

Comments
 (0)