From 72794f7c039c07febd7273bc5a820a3505ee1185 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Fri, 27 Dec 2024 10:11:04 +0000 Subject: [PATCH 1/2] chore: create basic rust crate structure for tnf Co-Authored-By: wqoy gqle --- crates/tnf/Cargo.toml | 6 ++++++ crates/tnf/src/lib.rs | 7 +++++++ crates/tnf_binding/Cargo.toml | 7 +++++++ crates/tnf_binding/src/lib.rs | 7 +++++++ packages/tnf-binding/package.json | 5 +++++ 5 files changed, 32 insertions(+) create mode 100644 crates/tnf/Cargo.toml create mode 100644 crates/tnf/src/lib.rs create mode 100644 crates/tnf_binding/Cargo.toml create mode 100644 crates/tnf_binding/src/lib.rs create mode 100644 packages/tnf-binding/package.json diff --git a/crates/tnf/Cargo.toml b/crates/tnf/Cargo.toml new file mode 100644 index 0000000..bfaf1d4 --- /dev/null +++ b/crates/tnf/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "tnf" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/crates/tnf/src/lib.rs b/crates/tnf/src/lib.rs new file mode 100644 index 0000000..98b4541 --- /dev/null +++ b/crates/tnf/src/lib.rs @@ -0,0 +1,7 @@ +pub fn build() { + // TODO: implement heavy-lifting logic +} + +pub fn update() { + // TODO: implement file change updates +} diff --git a/crates/tnf_binding/Cargo.toml b/crates/tnf_binding/Cargo.toml new file mode 100644 index 0000000..af5cbfd --- /dev/null +++ b/crates/tnf_binding/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "tnf_binding" +version = "0.1.0" +edition = "2021" + +[dependencies] +tnf = { path = "../tnf" } diff --git a/crates/tnf_binding/src/lib.rs b/crates/tnf_binding/src/lib.rs new file mode 100644 index 0000000..bec9bd1 --- /dev/null +++ b/crates/tnf_binding/src/lib.rs @@ -0,0 +1,7 @@ +pub fn build() { + // TODO: integrate with the tnf crate +} + +pub fn update() { + // TODO: integrate with the tnf crate +} diff --git a/packages/tnf-binding/package.json b/packages/tnf-binding/package.json new file mode 100644 index 0000000..ee2e93c --- /dev/null +++ b/packages/tnf-binding/package.json @@ -0,0 +1,5 @@ +{ + "name": "@umijs/tnf-binding", + "version": "0.0.1", + "main": "dist/index.js" +} From edf4b700e552bd67d9ebd467803101c27ec62be2 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Fri, 27 Dec 2024 12:46:39 +0000 Subject: [PATCH 2/2] feat: add napi-rs bindings for tnf crate Co-Authored-By: wqoy gqle --- crates/tnf_binding/Cargo.toml | 2 ++ crates/tnf_binding/src/lib.rs | 17 +++++++++++++---- packages/tnf-binding/package.json | 6 +++++- packages/tnf-binding/src/index.ts | 16 ++++++++++++++++ 4 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 packages/tnf-binding/src/index.ts diff --git a/crates/tnf_binding/Cargo.toml b/crates/tnf_binding/Cargo.toml index af5cbfd..c173208 100644 --- a/crates/tnf_binding/Cargo.toml +++ b/crates/tnf_binding/Cargo.toml @@ -4,4 +4,6 @@ version = "0.1.0" edition = "2021" [dependencies] +napi = "2" +napi-derive = "2" tnf = { path = "../tnf" } diff --git a/crates/tnf_binding/src/lib.rs b/crates/tnf_binding/src/lib.rs index bec9bd1..e7cd37c 100644 --- a/crates/tnf_binding/src/lib.rs +++ b/crates/tnf_binding/src/lib.rs @@ -1,7 +1,16 @@ -pub fn build() { - // TODO: integrate with the tnf crate +use napi::bindgen_prelude::*; +use napi_derive::napi; +use tnf; + +#[napi] +pub fn build() -> Result<()> { + // Call your Rust logic in the tnf crate + tnf::build(); + Ok(()) } -pub fn update() { - // TODO: integrate with the tnf crate +#[napi] +pub fn update() -> Result<()> { + tnf::update(); + Ok(()) } diff --git a/packages/tnf-binding/package.json b/packages/tnf-binding/package.json index ee2e93c..83af24d 100644 --- a/packages/tnf-binding/package.json +++ b/packages/tnf-binding/package.json @@ -1,5 +1,9 @@ { "name": "@umijs/tnf-binding", "version": "0.0.1", - "main": "dist/index.js" + "main": "dist/index.js", + "scripts": { + "build:native": "cargo build --release --manifest-path=../../crates/tnf_binding/Cargo.toml", + "build": "tsc && pnpm build:native" + } } diff --git a/packages/tnf-binding/src/index.ts b/packages/tnf-binding/src/index.ts new file mode 100644 index 0000000..15d2da3 --- /dev/null +++ b/packages/tnf-binding/src/index.ts @@ -0,0 +1,16 @@ +// Native bindings +const native = require('../build/Release/tnf_binding.node'); + +/** + * Build the project using native Rust implementation + */ +export function build(): void { + return native.build(); +} + +/** + * Update the project using native Rust implementation + */ +export function update(): void { + return native.update(); +}