Skip to content

Commit 9eb2086

Browse files
committed
initial attempt
1 parent 25c3951 commit 9eb2086

File tree

8 files changed

+410
-1
lines changed

8 files changed

+410
-1
lines changed

Cargo.lock

+63
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
22

33
[workspace]
4-
members = ["cpp-linter", "py-binding", "docs"]
4+
members = ["cpp-linter", "py-binding", "node-binding", "docs"]
55
resolver = "2"
66

77
[workspace.package]

node-binding/.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
target
2+
index.node
3+
**/node_modules
4+
**/.DS_Store
5+
npm-debug.log*cargo.log
6+
cross.log

node-binding/Cargo.toml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[package]
2+
name = "cpp-linter-js"
3+
edition = "2021"
4+
exclude = ["index.node"]
5+
readme = "README.md"
6+
keywords = ["clang-tidy", "clang-format", "linter"]
7+
categories = ["command-line-utilities", "development-tools", "filesystem"]
8+
repository = "https://github.com/cpp-linter/cpp_linter_rs"
9+
version.workspace = true
10+
authors.workspace = true
11+
description.workspace = true
12+
homepage.workspace = true
13+
license.workspace = true
14+
15+
[lib]
16+
crate-type = ["cdylib"]
17+
18+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
19+
20+
[dependencies]
21+
cpp-linter = { path = "../cpp-linter" }
22+
once_cell = "1.19.0"
23+
tokio = { version = "1.40.0", features = ["rt-multi-thread"]}
24+
25+
[dependencies.neon]
26+
version = "1"
27+
features = ["napi-6"]

node-binding/README.md

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# cpp-linter-js
2+
3+
This project was bootstrapped by [create-neon](https://www.npmjs.com/package/create-neon).
4+
5+
## Building cpp-linter-js
6+
7+
Building cpp-linter-js requires a [supported version of Node and Rust](https://github.com/neon-bindings/neon#platform-support).
8+
9+
To run the build, run:
10+
11+
```sh
12+
npm run build
13+
```
14+
15+
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`.
16+
17+
## Exploring cpp-linter-js
18+
19+
After building cpp-linter-js:
20+
21+
```text
22+
cd node-binding
23+
npm i
24+
npm run build
25+
```
26+
27+
You can explore its exports in the `node` console:
28+
29+
```sh
30+
> cpp_linter_js = require('.')
31+
> // CLI args are passed as optional args to `run_main()`
32+
> await cpp_linter_js.run_main('--help')
33+
```
34+
35+
## Available Scripts
36+
37+
In the project directory, you can run:
38+
39+
### `npm install`
40+
41+
Installs the project, including running `npm run build`.
42+
43+
### `npm run build`
44+
45+
Builds the Node addon (`index.node`) from source, generating a release build with `cargo --release`.
46+
47+
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):
48+
49+
```text
50+
npm run build -- --feature=beetle
51+
```
52+
53+
### `npm run debug`
54+
55+
Similar to `npm run build` but generates a debug build with `cargo`.
56+
57+
### `npm run cross`
58+
59+
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.
60+
61+
## Project Layout
62+
63+
The directory structure of this project is:
64+
65+
```text
66+
node-binding/
67+
├── Cargo.toml
68+
├── README.md
69+
├── src/
70+
| └── lib.rs
71+
├── index.node
72+
└── package.json
73+
target/
74+
```
75+
76+
| Entry | Purpose |
77+
|------:|:--------|
78+
| `Cargo.toml` | The Cargo [manifest file](https://doc.rust-lang.org/cargo/reference/manifest.html), which informs the `cargo` command. |
79+
| `README.md` | This file. |
80+
| `src/` | The directory tree containing the Rust source code for the project. |
81+
| `lib.rs` | Entry point for the Rust source code. |
82+
| `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`. |
83+
| `package.json` | The npm [manifest file](https://docs.npmjs.com/cli/v7/configuring-npm/package-json), which informs the `npm` command. |
84+
| `target/` | Binary artifacts generated by the Rust build. |
85+
86+
## Learn More
87+
88+
Learn more about:
89+
90+
- [Neon](https://neon-bindings.com).
91+
- [Rust](https://www.rust-lang.org).
92+
- [Node](https://nodejs.org).

node-binding/package-lock.json

+133
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node-binding/package.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "cpp-linter-js",
3+
"version": "2.0.0",
4+
"description": "",
5+
"main": "index.node",
6+
"scripts": {
7+
"test": "cargo test",
8+
"cargo-build": "cargo build --message-format=json > cargo.log",
9+
"cross-build": "cross build --message-format=json > cross.log",
10+
"postcargo-build": "neon dist < cargo.log",
11+
"postcross-build": "neon dist -m /target < cross.log",
12+
"debug": "npm run cargo-build --",
13+
"build": "npm run cargo-build -- --release",
14+
"cross": "npm run cross-build -- --release"
15+
},
16+
"author": "",
17+
"license": "MIT",
18+
"devDependencies": {
19+
"@neon-rs/cli": "0.1.73"
20+
}
21+
}

0 commit comments

Comments
 (0)