-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from Meta-A/feat/js-bindings
feat(js-bindings): integrate js bindings
- Loading branch information
Showing
9 changed files
with
469 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
target | ||
index.node | ||
**/node_modules | ||
**/.DS_Store | ||
npm-debug.log*cargo.log | ||
cross.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[package] | ||
name = "js-bindings" | ||
version = "0.1.0" | ||
license = "ISC" | ||
edition = "2021" | ||
exclude = ["index.node"] | ||
|
||
[lib] | ||
crate-type = ["cdylib"] | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
bpm_core = { workspace = true } | ||
hex = "0.4.3" | ||
home = "0.5.9" | ||
neon = "1" | ||
once_cell = "1" | ||
tokio = { version = "1", features = ["rt-multi-thread"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# js-bindings | ||
|
||
This project was bootstrapped by [create-neon](https://www.npmjs.com/package/create-neon). | ||
|
||
## Building js-bindings | ||
|
||
Building js-bindings requires a [supported version of Node and Rust](https://github.com/neon-bindings/neon#platform-support). | ||
|
||
To run the build, run: | ||
|
||
```sh | ||
$ npm run build | ||
``` | ||
|
||
This command uses the [@neon-rs/cli](https://www.npmjs.com/package/@neon-rs/cli) utility to assemble the binary Node addon from the output of `cargo`. | ||
|
||
## Exploring js-bindings | ||
|
||
After building js-bindings, you can explore its exports at the Node console: | ||
|
||
```sh | ||
$ npm i | ||
$ npm run build | ||
$ node | ||
> require('.').hello() | ||
'hello node' | ||
``` | ||
|
||
## Available Scripts | ||
|
||
In the project directory, you can run: | ||
|
||
#### `npm install` | ||
|
||
Installs the project, including running `npm run build`. | ||
|
||
#### `npm run build` | ||
|
||
Builds the Node addon (`index.node`) from source, generating a release build with `cargo --release`. | ||
|
||
Additional [`cargo build`](https://doc.rust-lang.org/cargo/commands/cargo-build.html) arguments may be passed to `npm run build` and similar commands. For example, to enable a [cargo feature](https://doc.rust-lang.org/cargo/reference/features.html): | ||
|
||
``` | ||
npm run build -- --feature=beetle | ||
``` | ||
|
||
#### `npm run debug` | ||
|
||
Similar to `npm run build` but generates a debug build with `cargo`. | ||
|
||
#### `npm run cross` | ||
|
||
Similar to `npm run build` but uses [cross-rs](https://github.com/cross-rs/cross) to cross-compile for another platform. Use the [`CARGO_BUILD_TARGET`](https://doc.rust-lang.org/cargo/reference/config.html#buildtarget) environment variable to select the build target. | ||
|
||
#### `npm test` | ||
|
||
Runs the unit tests by calling `cargo test`. You can learn more about [adding tests to your Rust code](https://doc.rust-lang.org/book/ch11-01-writing-tests.html) from the [Rust book](https://doc.rust-lang.org/book/). | ||
|
||
## Project Layout | ||
|
||
The directory structure of this project is: | ||
|
||
``` | ||
js-bindings/ | ||
├── Cargo.toml | ||
├── README.md | ||
├── src/ | ||
| └── lib.rs | ||
├── index.node | ||
├── package.json | ||
└── target/ | ||
``` | ||
|
||
| Entry | Purpose | | ||
|----------------|------------------------------------------------------------------------------------------------------------------------------------------| | ||
| `Cargo.toml` | The Cargo [manifest file](https://doc.rust-lang.org/cargo/reference/manifest.html), which informs the `cargo` command. | | ||
| `README.md` | This file. | | ||
| `src/` | The directory tree containing the Rust source code for the project. | | ||
| `lib.rs` | Entry point for the Rust source code. | | ||
| `index.node` | The main module, a [Node addon](https://nodejs.org/api/addons.html) generated by the build and pointed to by `"main"` in `package.json`. | | ||
| `package.json` | The npm [manifest file](https://docs.npmjs.com/cli/v7/configuring-npm/package-json), which informs the `npm` command. | | ||
| `target/` | Binary artifacts generated by the Rust build. | | ||
|
||
## Learn More | ||
|
||
Learn more about: | ||
|
||
- [Neon](https://neon-bindings.com). | ||
- [Rust](https://www.rust-lang.org). | ||
- [Node](https://nodejs.org). |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "js-bindings", | ||
"version": "0.1.0", | ||
"description": "", | ||
"main": "index.node", | ||
"scripts": { | ||
"test": "cargo test", | ||
"cargo-build": "cargo build --message-format=json-render-diagnostics > cargo.log", | ||
"cross-build": "cross build --message-format=json-render-diagnostics > cross.log", | ||
"postcargo-build": "neon dist < cargo.log", | ||
"postcross-build": "neon dist -m /target < cross.log", | ||
"debug": "npm run cargo-build --", | ||
"build": "npm run cargo-build -- --release", | ||
"cross": "npm run cross-build -- --release" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"@neon-rs/cli": "0.1.82" | ||
} | ||
} |
Oops, something went wrong.