-
Notifications
You must be signed in to change notification settings - Fork 4
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}"); |
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.
Copilot uses AI. Check for mistakes.
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 |
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 |
Copilot uses AI. Check for mistakes.
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-js
and 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-rn
to injecting aWEAK_NODE_QPI_CONFIG
definition which developers can include to add theweak-node-api
target into their project, when linking their own addon library.--cmake-js
flag tocmake-rn
to opt-in to injection of theCMAKE_JS_*
defines as before.--weak-node-api
option ingyp-to-cmake
to generate CMake configurations compatible with the defaultcmake-rn
settings.gyp-to-cmake
transformer to make it easier to define various target parameters.cmake-rn
to 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-api
linkage in thenode-addon-examples
and avoid it in thenode-tests
to have both code-paths exercised in CI. This decision is pretty arbitrary and we might want to switch overnode-tests
in the future in favor of a specific test forcmake-js
compatibility.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-api
target that they can link their addon with.