Skip to content

Conversation

@kraenhansen
Copy link
Collaborator

@kraenhansen kraenhansen commented May 4, 2025

This PR is stacked on the branch of #33 and merging it will:

  • Add an option to skip auto-linking Add --skip-autolink option to react-native-node-api-cmake CLI #13 (I needed this to build the weak-node-api binary).
  • Add an option to skip linking against the weak-node-api dynamic library (because - recursion 😬)
  • Refactor scripts into TypeScript (because why not?)
  • Add a script to generate and build weak-node-api
    • Looks at the Node-API header files
    • Uses clang to dump and AST
    • Generates a C++ file based on the AST, with failing stub implementations.
    • The stub implementations have __attribute__((weak)) annotations in case we'd actually want to link this in some day and allow for the real native code to override the implementations.

@changeset-bot
Copy link

changeset-bot bot commented May 4, 2025

⚠️ No Changeset found

Latest commit: 5ad833d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@kraenhansen kraenhansen self-assigned this May 4, 2025
@kraenhansen kraenhansen marked this pull request as ready for review May 5, 2025 15:01
@kraenhansen kraenhansen requested a review from Copilot May 5, 2025 15:01
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for a dynamic weak-node-api library while refactoring several build scripts into TypeScript. Key changes include:

  • Adding an option to skip auto-linking and weak-node-api linking.
  • Introducing scripts to generate and build a stubbed weak-node-api C++ file based on the Node-API header AST.
  • Updating the CMake CLI and associated modules to support both Android and Apple triplet builds.

Reviewed Changes

Copilot reviewed 9 out of 15 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/react-native-node-api-modules/scripts/copy-node-api-headers.ts Updated header path resolution using an import from node-api-headers and using __dirname for a consistent destination path.
packages/react-native-node-api-modules/scripts/build-weak-node-api.ts New script generating the fake Node API source; uses clang AST dump and builds stub implementations with weak symbols.
packages/react-native-node-api-cmake/src/weak-node-api.ts Retrieves the weak-node-api path based on the target triplet.
packages/react-native-node-api-cmake/src/triplets.ts Updated the supported triplets, consolidating Android and Apple values.
packages/react-native-node-api-cmake/src/cli.ts Refactored the CLI to include new options for Android/Apple builds and to pass along auto-linking and weak-node-api linkage options.
packages/react-native-node-api-cmake/src/apple.ts Adjusted Apple configuration with updated naming for SDK and system names, and ensured autoLink behavior in XCFramework creation.
packages/react-native-node-api-cmake/src/android.ts Added new Android build configurations and a routine to assemble the Android libs directory with weak-node-api integration.
Files not reviewed (6)
  • packages/react-native-node-api-modules/.gitignore: Language not supported
  • packages/react-native-node-api-modules/package.json: Language not supported
  • packages/react-native-node-api-modules/tsconfig.json: Language not supported
  • packages/react-native-node-api-modules/tsconfig.node-scripts.json: Language not supported
  • packages/react-native-node-api-modules/tsconfig.node.json: Language not supported
  • packages/react-native-node-api-modules/weak-node-api/CMakeLists.txt: Language not supported

);
lines.push(
`__attribute__((weak)) ${returnType} ${node.name}(${argumentTypes}) {`,
returnType === "void" ? "" : " napi_status::napi_generic_failure;",
Copy link

Copilot AI May 5, 2025

Choose a reason for hiding this comment

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

For functions with non-void return types, the generated stub code might be invalid because it lacks a 'return' keyword. Consider updating the line to include 'return' (e.g. 'return napi_status::napi_generic_failure;') to ensure proper stub implementation.

Suggested change
returnType === "void" ? "" : " napi_status::napi_generic_failure;",
returnType === "void" ? "" : " return napi_status::napi_generic_failure;",

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This line will go away in #39

Base automatically changed from kh/android to main May 6, 2025 07:42
@kraenhansen kraenhansen force-pushed the kh/weak-node-api-library branch from 025310b to 5ad833d Compare May 6, 2025 07:43
@kraenhansen kraenhansen merged commit 4afa6ef into main May 6, 2025
@kraenhansen kraenhansen deleted the kh/weak-node-api-library branch May 6, 2025 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants