-
Notifications
You must be signed in to change notification settings - Fork 7
Explicit weak-node-api linkage
#249
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
Conversation
abb960b to
9b75af3
Compare
d9f5485 to
8d96678
Compare
…licit way of linking with Node-API
8d96678 to
e002331
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Introduces an explicit weak-node-api linkage workflow, decoupling default behavior from cmake-js style variable injection and adding opt-in flags across tooling.
- Adds includable WEAK_NODE_API_CONFIG exposing an imported weak-node-api target for addon linkage.
- Makes cmake-js compatibility optional via --cmake-js and adds --weak-node-api / --cpp / --define-napi-version options to gyp-to-cmake.
- Refactors definition handling to allow multiple -D entries with same key and restructures transformer for flexible target parameters.
Reviewed Changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/node-tests/scripts/build-tests.mts | Switch to execSync and enable cmake-js mode during test builds. |
| packages/node-addon-examples/tests/*/CMakeLists.txt | Transition examples to weak-node-api includable config usage. |
| packages/node-addon-examples/package.json | Opt-in to weak-node-api aware gyp-to-cmake generation. |
| packages/host/weak-node-api/weak-node-api.cmake | Adds imported weak-node-api target definition template. |
| packages/gyp-to-cmake/src/transformer.ts | Refactors emission logic to support weak-node-api, optional NAPI version, compile features. |
| packages/gyp-to-cmake/src/cli.ts | Adds new CLI options (--weak-node-api, --define-napi-version, --cpp). |
| packages/cmake-rn/src/weak-node-api.ts | Splits variable sets between weak-node-api and cmake-js compatibility. |
| packages/cmake-rn/src/cli.ts | Supports multiple -D entries, adds --cmake-js, refactors definition aggregation. |
| packages/cmake-rn/README.md | Documents new weak-node-api linkage approach. |
| docs/WEAK-NODE-API.md | Introduces dedicated documentation for weak-node-api. |
| .changeset/*.md | Release notes for new minor versions and breaking default define change. |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| libraries.push("weak-node-api"); | ||
| } else { | ||
| libraries.push("${CMAKE_JS_LIB}"); | ||
| escapedSources.push("${CMAKE_JS_SRC}"); |
Copilot
AI
Sep 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Mutating the escapedSources array in conditional logic makes the code harder to follow. Consider building the complete sources array upfront or using immutable operations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nah - I think this is cleaner, in this particular case.
7dc57d6 to
9fe44eb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| "endif()", | ||
| ); | ||
| if (!weakNodeApi) { | ||
| // This is required by cmake-js to generate the import library for node.lib on Windows |
Copilot
AI
Sep 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The comment should be more precise. Change 'This is required by cmake-js' to 'This code is required by cmake-js'.
| // This is required by cmake-js to generate the import library for node.lib on Windows | |
| // This code is required by cmake-js to generate the import library for node.lib on Windows |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
a387f73 to
a7f3d66
Compare
From the beginning of this project we wanted to keep things compatible with
cmake-jsand this is still a priority.At the same time, I find it strange that our default configuration asks developers to inject
CMAKE_JS_*into their targets - I think we can do better than that.Merging this PR will:
cmake-rnto injecting aWEAK_NODE_QPI_CONFIGdefinition which developers can include to add theweak-node-apitarget into their project, when linking their own addon library.--cmake-jsflag tocmake-rnto opt-in to injection of theCMAKE_JS_*defines as before.--weak-node-apioption ingyp-to-cmaketo generate CMake configurations compatible with the defaultcmake-rnsettings.gyp-to-cmaketransformer to make it easier to define various target parameters.cmake-rnto allow passing multiple defines with the same "key", which is generally supported by CMake. (Drive-by and not strictly needed for this change).weak-node-apilinkage in thenode-addon-examplesand avoid it in thenode-teststo have both code-paths exercised in CI. This decision is pretty arbitrary and we might want to switch overnode-testsin the future in favor of a specific test forcmake-jscompatibility.As-is (the cmake-js template)
The config I suggest
Note: Instead of relying on
$CMAKE_JS_*defines, we ask users toinclude(${WEAK_NODE_API_CONFIG})which defines aweak-node-apitarget that they can link their addon with.