Skip to content

feat(binding-builder): add binding-builder cli #10876

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

h-a-n-a
Copy link
Contributor

@h-a-n-a h-a-n-a commented Jul 2, 2025

Summary

Introduce a new package @rspack/binding-builder-cli to build binding (bin: rspack-builder).

The new @rspack/binding-builder-cli will be utilized for both crates/node_binding and projects using rspack-binding-template or similar.

The original build script contains special environment variables and features that are specialized for crates/node_binding. With that being said, I kept the original scripts/build.js to call rspack-builder to achieve the same effect.

Rationale

This package is designed to provide a command-line interface for building custom bindings for rspack.

Rspack internally performs post-processing modifications on the generated TypeScript definition (.d.ts) files from NAPI-RS bindings. The @rspack/binding-builder-cli synchronizes these modifications, ensuring that the generated .d.ts files are complete and provide access to all type information available in @rspack/binding plus the newly added types in custom binding.

Debug

To debug rspack-builder, set DEBUG=rspack-builder:* as a prefix to the command.

Related links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copy link

netlify bot commented Jul 2, 2025

Deploy Preview for rspack ready!

Name Link
🔨 Latest commit 4a924a7
🔍 Latest deploy log https://app.netlify.com/projects/rspack/deploys/686635884387d300081bf0ce
😎 Deploy Preview https://deploy-preview-10876--rspack.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions github-actions bot added team The issue/pr is created by the member of Rspack. release: feature release: feature related release(mr only) labels Jul 2, 2025
@h-a-n-a h-a-n-a force-pushed the binding-builder-cli branch 2 times, most recently from 7c7b928 to 63b2164 Compare July 2, 2025 10:36
@h-a-n-a h-a-n-a marked this pull request as ready for review July 2, 2025 10:46
@@ -31,7 +31,7 @@ runs:
shell: bash
run: |
cd ./crates/node_binding
pnpm install --ignore-workspace --no-lockfile
Copy link
Contributor Author

@h-a-n-a h-a-n-a Jul 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bad part is we have to link binding-builder-cli to crates/node_binding. This requires the binding to fallback to workspace install instead of plain package install. cc @stormslowly

@@ -31,7 +31,7 @@ runs:
shell: bash
run: |
cd ./crates/node_binding
pnpm install --ignore-workspace --no-lockfile
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove --ignore-workspace will install all workspace depenceies and slow down installation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could probably install the binding builder cli as a dependency (not from the current workspace) after the first release, then we can revert the workflow back.

process.exit(0);
}

const { NapiCli } = require("@napi-rs/cli");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure it's a stable public api or just an internal api, I'm afraid whether we'll miss some logic in the napi-cli/bin

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


const debug = require("debug")("rspack-builder:build");

const OPTIONS_CONFIG = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this duplicate of https://github.com/napi-rs/napi-rs/blob/main/cli/src/def/build.ts#L5 or we add custom logic here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, it's a bunch of code supposed to achieve the same functionalities with napi-rs cli. I changed it to programmatic API to make our CLI output nice and clean.

@stormslowly
Copy link
Contributor

If rspack-builder is mainly for rspack template user, in my opinion, put how we use napi in package.json's script is better.

  1. easy for napi veteran to tweak
  2. less abstraction; In my opinion, the template repo is more of a rust napi project other than rspack plugin project.

@@ -0,0 +1,31 @@
{
"name": "@rspack/binding-builder-cli",
"version": "1.4.2",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't fully understand why we need make our own cli instead of using napi-cli? can you help explain in README.md so outside contributors can understand it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Being explained in #10876 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@h-a-n-a
Copy link
Contributor Author

h-a-n-a commented Jul 2, 2025

If rspack-builder is mainly for rspack template user, in my opinion, put how we use napi in package.json's script is better.

  1. easy for napi veteran to tweak
  2. less abstraction; In my opinion, the template repo is more of a rust napi project other than rspack plugin project.

I had thought about this in the first place. But rspack's binding heavily requires some tweaking to the binding.d.ts and we need to sync these changes to the users and this is the most painful part.

@h-a-n-a h-a-n-a force-pushed the binding-builder-cli branch 2 times, most recently from d42471e to 941c66c Compare July 2, 2025 11:37
@h-a-n-a h-a-n-a enabled auto-merge (squash) July 2, 2025 12:06
Copy link
Contributor

github-actions bot commented Jul 3, 2025

📦 Binary Size-limit

Comparing binary size with Commit: fix: always rebuild error module (#10873) by jinrui

❌ Size increased by 1150.33MB from 59.79MB to 1210.13MB (⬆️1923.89%)

@h-a-n-a h-a-n-a force-pushed the binding-builder-cli branch from 144c0f4 to 4a924a7 Compare July 3, 2025 07:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release: feature release: feature related release(mr only) team The issue/pr is created by the member of Rspack.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants