cpp-linter / cpp-linter-rs

A CLI tool that scans a batch of files with clang-tidy and/or clang-format, then provides feedback in the form of comments, annotations, summaries, and reviews.
https://cpp-linter.github.io/cpp-linter-rs/
MIT License
1 stars 0 forks source link

consider node.js binding #12

Closed 2bndy5 closed 2 months ago

2bndy5 commented 3 months ago

Recently, I discovered napi-rs which generates bindings from rust code to WASM targets. I believe it could be used in conjunction with github's octokit library[^1] because it would be installable via npm.

[^1]: The official API used to implement native actions agnostic of the runner's OS, not for composite or docker actions

2bndy5 commented 3 months ago

I looked into this. It might be possible with a thin TS wrapper that (collects all the action inputs and then) calls into the rust run_main() entrypoint. One of the other problems is with how to create output variables using @action/core (from octokit ecosystem).

I'm not going to persuing this. The napi-rs project is setup to create libraries installed via npm only. I don't think its engineered to be used as an executable wrapper.

2bndy5 commented 3 months ago

It would probably be easier to write a javascript action using dart's JS interoperability (generates javascript code from dart code). But I pretty much abandoned the cpp_linter_dart experiment when I learned the glory of rust.

2bndy5 commented 2 months ago

I'm reopening this because I think I found a way to do this. I'm still investigating, but I have a branch that employs the neon package to generate a native node.js module from the cpp-linter lib... See node-binding/ directory in the new branch.

The tricky parts are

2bndy5 commented 2 months ago

Success! 🎉

It took me a while to figure out all the steps performed in publishing platform-specific packages, but it works now. See npmjs page.

With Attestation

image


Going forward I think I can create another package (call it @cpp-linter/gh-action) that doesn't require a special install step and uses the @cpp-linter/cpp-linter pkg as a dependency. My aim is to have something like the following (in cpp-linter-action/action.yml):


- uses: cpp-linter/cpp_linter_rs/gh-action@v2.0.0
  with:
    version: ${{ inputs.version }}
    thread-comments: ${{ inputs.thread-comments }}
    # ...