Skip to content

Conversation

@kraenhansen
Copy link
Collaborator

@kraenhansen kraenhansen commented Oct 20, 2025

This fixes #258 by making this this only option.

Merging this PR will:

Missing docs and I might also be missing option 1 from #262 (copying xcframeworks as is).

@kraenhansen kraenhansen self-assigned this Oct 20, 2025
@kraenhansen kraenhansen force-pushed the kh/xcode-archive-frameworks branch 3 times, most recently from 55e2dcd to b1e5821 Compare October 20, 2025 19:19
@kraenhansen kraenhansen added Apple 🍎 Anything related to the Apple platform (iOS, macOS, Cocoapods, Xcode, XCFrameworks, etc.) Android 🤖 Anything related to the Android platform (Gradle, NDK, Android SDK) labels Oct 20, 2025
@kraenhansen kraenhansen force-pushed the kh/xcode-archive-frameworks branch from cbe98e8 to b49d0eb Compare October 21, 2025 08:30
@kraenhansen kraenhansen force-pushed the kh/xcode-archive-frameworks branch from b49d0eb to 71c1fa8 Compare October 21, 2025 11:25
@kraenhansen kraenhansen marked this pull request as ready for review October 21, 2025 12:03
@kraenhansen kraenhansen requested a review from Copilot October 21, 2025 12:03
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 implements Apple framework support as the default option for building Node-API addons on Apple platforms, addressing issue #258. The changes enable CMake to generate proper Apple frameworks instead of bare dynamic libraries, and refactor the build system to give platforms more control over the build process.

Key changes:

  • Makes Apple frameworks the default build output by adding CMake framework properties to generated CMakeLists.txt files
  • Refactors cmake-rn platform interfaces to allow platforms to directly spawn build commands rather than just returning arguments
  • Fixes weak-node-api build to produce frameworks on Apple platforms

Reviewed Changes

Copilot reviewed 18 out of 19 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
packages/node-addon-examples/tests/buffers/CMakeLists.txt Updates project name and adds Apple framework configuration with option to disable
packages/node-addon-examples/tests/async/CMakeLists.txt Updates project name and adds Apple framework configuration with option to disable
packages/host/weak-node-api/CMakeLists.txt Converts weak-node-api to build as an Apple framework
packages/host/src/node/prebuilds/apple.ts Adds versioned framework parameter to createAppleFramework function
packages/host/src/node/path-utils.ts Adds dereferenceDirectory utility function for resolving symlinks
packages/host/src/node/path-utils.test.ts Adds test coverage for dereferenceDirectory function
packages/host/src/node/index.ts Exports dereferenceDirectory function
packages/gyp-to-cmake/src/transformer.ts Adds appleFramework option and generates framework-specific CMake properties
packages/gyp-to-cmake/src/cli.ts Adds --no-apple-framework flag and improves project name generation from package.json
packages/gyp-to-cmake/package.json Adds pkg-dir and read-pkg dependencies
packages/ferric/src/build.ts Updates createAppleFramework call with TODO for versioned frameworks
packages/cmake-rn/src/weak-node-api.ts Extends getWeakNodeApiPath to accept "apple" triplet
packages/cmake-rn/src/platforms/types.ts Refactors Platform interface to replace configure/buildArgs with configure/build methods
packages/cmake-rn/src/platforms/apple.ts Implements new platform interface with xcodebuild support for frameworks
packages/cmake-rn/src/platforms/android.ts Implements new platform interface for Android builds
packages/cmake-rn/src/helpers.ts Extracts toDefineArguments helper function
packages/cmake-rn/src/cli.ts Refactors to use new platform interface methods
packages/cmake-rn/package.json Adds zod dependency

} else {
lines.push(
...setTargetPropertiesLines({
PREFIX: "",
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

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

The PREFIX property is set to an empty string instead of the quoted empty string \"\" that's used in the framework branch (line 158). This inconsistency will cause CMake to interpret the value differently. Both branches should use '\"\"' for consistency.

Suggested change
PREFIX: "",
PREFIX: '""',

Copilot uses AI. Check for mistakes.
recursive: true,
verbatimSymlinks: true,
});
await fs.promises.unlink(tempPath);
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

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

Using unlink() on a directory will fail. Since tempPath is a directory (created from dirPath), this should use fs.promises.rmdir(tempPath, { recursive: true }) or fs.promises.rm(tempPath, { recursive: true }) instead.

Suggested change
await fs.promises.unlink(tempPath);
await fs.promises.rm(tempPath, { recursive: true, force: true });

Copilot uses AI. Check for mistakes.
return name
.replace(/^@/g, "")
.replace(/\//g, "--")
.replace(/[^a-zA-Z0-9_]/g, "_");
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

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

The regex replacements will convert hyphens to underscores on line 31, but the comment in escapeBundleIdentifier suggests double underscores should become dots. This transformation is inconsistent with the bundle identifier escaping logic. Consider whether hyphens should be preserved or if this should align with escapeBundleIdentifier's approach.

Suggested change
.replace(/[^a-zA-Z0-9_]/g, "_");
.replace(/[^a-zA-Z0-9_-]/g, "_");

Copilot uses AI. Check for mistakes.
},
buildArgs() {
async build({ spawn, triplet }, { build, target, configuration }) {
// const outputPath = path.join(buildPath, `${triplet.replace(/;/g, "_")}-out`)
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

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

This commented-out code should be removed rather than left in the codebase. If this was intended for future use, it should be captured in a TODO comment with context.

Suggested change
// const outputPath = path.join(buildPath, `${triplet.replace(/;/g, "_")}-out`)

Copilot uses AI. Check for mistakes.
);

// Perform post-build steps for each platform in sequence
// console.log("📦 Writing prebuilds to:", prettyPath(out));
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

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

This commented-out debugging statement should be removed from the production code.

Suggested change
// console.log("📦 Writing prebuilds to:", prettyPath(out));

Copilot uses AI. Check for mistakes.
@kraenhansen kraenhansen force-pushed the kh/xcode-archive-frameworks branch from f116caa to 36cb9a0 Compare October 21, 2025 15:32
@kraenhansen kraenhansen merged commit 427673f into main Oct 21, 2025
11 of 12 checks passed
@kraenhansen kraenhansen deleted the kh/xcode-archive-frameworks branch October 21, 2025 19:18
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) Apple 🍎 Anything related to the Apple platform (iOS, macOS, Cocoapods, Xcode, XCFrameworks, etc.)

Projects

None yet

2 participants