Skip to content

Conversation

@kraenhansen
Copy link
Collaborator

@kraenhansen kraenhansen commented May 5, 2025

Merging this PR will:

  • Refactor the host package CLI (a lot) to extract the non apple specifics from linking
    • to prepare for the Android implementation and keeping things DRY.
    • to allow linking Android and iOS from the same invocation - mainly, because it's possible with no added drawback.
  • Add an implementation of weak-node-api which use symbol lookup to defer Node-API calls into libhermes or our libnode-api-host library at runtime.

@kraenhansen kraenhansen self-assigned this May 5, 2025
@kraenhansen kraenhansen added enhancement New feature or request Android 🤖 Anything related to the Android platform (Gradle, NDK, Android SDK) labels May 5, 2025
@changeset-bot
Copy link

changeset-bot bot commented May 5, 2025

⚠️ No Changeset found

Latest commit: 44f4200

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 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 refactors the host package CLI to extract non‑Apple linking logic and add support for auto‑linking Android modules, while also implementing a weak‑node‑api using runtime symbol lookup. Key changes include:

  • Removal of the "xcframeworks" command and consolidation of linking logic into a unified "link" command
  • Addition of Android module linking support and updates to build scripts and keystore bindings for weak‑node‑api
  • Adjustments to podspec and native implementations (C++/Kotlin) for proper library naming and linking

Reviewed Changes

Copilot reviewed 20 out of 23 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/react-native-node-api-modules/src/node/duplicates.ts Added a helper to find duplicate values
packages/react-native-node-api-modules/src/node/cli/xcframeworks.ts Removed in favor of new unified linking commands
packages/react-native-node-api-modules/src/node/cli/program.ts Updated CLI command structure for linking Apple and Android modules
packages/react-native-node-api-modules/src/node/cli/options.ts Added a new option to strip path suffixes
packages/react-native-node-api-modules/src/node/cli/link-modules.ts New file for handling module linking logic
packages/react-native-node-api-modules/src/node/cli/hermes.ts Adjusted import for pretty paths
packages/react-native-node-api-modules/src/node/cli/apple.ts New file for Apple-specific linking via xcframeworks
packages/react-native-node-api-modules/src/node/cli/android.ts New file for Android-specific linking logic
packages/react-native-node-api-modules/scripts/build-weak-node-api.ts Updated weak-node-api build script with dynamic symbol resolution
packages/react-native-node-api-modules/react-native-node-api-modules.podspec Updated vendored frameworks path to support auto-linked frameworks
packages/react-native-node-api-modules/cpp/CxxNodeApiHostModule.cpp Updated Android library path naming logic
packages/react-native-node-api-modules/android/src/main/java/com/callstack/node_api_modules/NodeApiModulesPackage.kt Adjusted native library loading sequence
packages/react-native-node-api-cmake/src/weak-node-api.ts Updated naming for weak-node-api xcframework/library
packages/react-native-node-api-cmake/src/android.ts Modified library name extraction during copy
packages/node-addon-examples/scripts/build-examples.mts Updated CLI invocation parameters for supported triplets
Files not reviewed (3)
  • packages/react-native-node-api-modules/.gitignore: Language not supported
  • packages/react-native-node-api-modules/android/CMakeLists.txt: Language not supported
  • packages/react-native-node-api-modules/android/build.gradle: Language not supported

assert(libraryDirents.length === 1, "Expected exactly one library file");
const [libraryDirent] = libraryDirents;
assert(libraryDirent.isFile(), "Expected a library file");
const libraryPath = path.join(libraryDirent.parentPath, libraryDirent.name);
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.

fs.Dirent objects do not have a 'parentPath' property. Replace 'libraryDirent.parentPath' with the known directory path (likely 'archPath') to correctly construct the file path.

Suggested change
const libraryPath = path.join(libraryDirent.parentPath, libraryDirent.name);
const libraryPath = path.join(archPath, libraryDirent.name);

Copilot uses AI. Check for mistakes.
@kraenhansen kraenhansen marked this pull request as ready for review May 5, 2025 15:01
@kraenhansen kraenhansen force-pushed the kh/weak-node-api-library branch from 025310b to 5ad833d Compare May 6, 2025 07:43
Base automatically changed from kh/weak-node-api-library to main May 6, 2025 07:44
@kraenhansen kraenhansen force-pushed the kh/auto-linking-android branch from 578e776 to 44f4200 Compare May 6, 2025 07:45
@kraenhansen kraenhansen merged commit 522421d into main May 6, 2025
@kraenhansen kraenhansen deleted the kh/auto-linking-android branch May 6, 2025 07:45
@kraenhansen kraenhansen linked an issue May 6, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Android 🤖 Anything related to the Android platform (Gradle, NDK, Android SDK) enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Auto-link Node-API modules for Android

2 participants