Skip to content

Commit 429183c

Browse files
committed
Use ".apple.node" instead of ".xcframeworks"
1 parent 9578c63 commit 429183c

File tree

6 files changed

+40
-10
lines changed

6 files changed

+40
-10
lines changed

packages/ferric-example/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Cargo.lock
33

44
/*.xcframework/
5+
/*.apple.node/
56
/*.android.node/
67

78
# Generated files

packages/ferric/src/build.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ const ndkVersionOption = new Option(
6666
"--ndk-version <version>",
6767
"The NDK version to use for Android builds"
6868
).default(DEFAULT_NDK_VERSION);
69+
const xcframeworkExtensionOption = new Option(
70+
"--xcframework-extension",
71+
"Don't rename the xcframework to .apple.node"
72+
).default(false);
73+
6974
const outputPathOption = new Option(
7075
"--output <path>",
7176
"Writing outputs to this directory"
@@ -85,6 +90,7 @@ export const buildCommand = new Command("build")
8590
.addOption(ndkVersionOption)
8691
.addOption(outputPathOption)
8792
.addOption(configurationOption)
93+
.addOption(xcframeworkExtensionOption)
8894
.action(
8995
async ({
9096
target: targetArg,
@@ -93,6 +99,7 @@ export const buildCommand = new Command("build")
9399
ndkVersion,
94100
output: outputPath,
95101
configuration,
102+
xcframeworkExtension,
96103
}) => {
97104
try {
98105
const targets = new Set([...targetArg]);
@@ -221,8 +228,10 @@ export const buildCommand = new Command("build")
221228
if (appleLibraries.length > 0) {
222229
const libraryPaths = await combineLibraries(appleLibraries);
223230
const frameworkPaths = libraryPaths.map(createAppleFramework);
224-
const xcframeworkFilename =
225-
determineXCFrameworkFilename(frameworkPaths);
231+
const xcframeworkFilename = determineXCFrameworkFilename(
232+
frameworkPaths,
233+
xcframeworkExtension ? ".xcframework" : ".apple.node"
234+
);
226235

227236
// Create the xcframework
228237
const xcframeworkOutputPath = path.resolve(

packages/react-native-node-api-cmake/src/cli.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ const noWeakNodeApiLinkageOption = new Option(
9191
"Don't pass the path of the weak-node-api library from react-native-node-api-modules"
9292
);
9393

94+
const xcframeworkExtensionOption = new Option(
95+
"--xcframework-extension",
96+
"Don't rename the xcframework to .apple.node"
97+
).default(false);
98+
9499
export const program = new Command("react-native-node-api-cmake")
95100
.description("Build React Native Node API modules with CMake")
96101
.addOption(sourcePathOption)
@@ -104,6 +109,7 @@ export const program = new Command("react-native-node-api-cmake")
104109
.addOption(ndkVersionOption)
105110
.addOption(noAutoLinkOption)
106111
.addOption(noWeakNodeApiLinkageOption)
112+
.addOption(xcframeworkExtensionOption)
107113
.action(async ({ triplet: tripletValues, ...globalContext }) => {
108114
try {
109115
const buildPath = getBuildPath(globalContext);
@@ -212,8 +218,10 @@ export const program = new Command("react-native-node-api-cmake")
212218
})
213219
);
214220
const frameworkPaths = libraryPaths.map(createAppleFramework);
215-
const xcframeworkFilename =
216-
determineXCFrameworkFilename(frameworkPaths);
221+
const xcframeworkFilename = determineXCFrameworkFilename(
222+
frameworkPaths,
223+
globalContext.xcframeworkExtension ? ".xcframework" : ".apple.node"
224+
);
217225

218226
// Create the xcframework
219227
const xcframeworkOutputPath = path.resolve(

packages/react-native-node-api-modules/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"copy-node-api-headers": "tsx scripts/copy-node-api-headers.ts",
4343
"generate-weak-node-api": "tsx scripts/generate-weak-node-api.ts",
4444
"generate-weak-node-api-injector": "tsx scripts/generate-weak-node-api-injector.ts",
45-
"build-weak-node-api": "npm run generate-weak-node-api && react-native-node-api-cmake --android --apple --no-auto-link --no-weak-node-api-linkage --source ./weak-node-api",
45+
"build-weak-node-api": "npm run generate-weak-node-api && react-native-node-api-cmake --android --apple --no-auto-link --no-weak-node-api-linkage --xcframework-extension --source ./weak-node-api",
4646
"test": "tsx --test src/node/**/*.test.ts src/node/*.test.ts"
4747
},
4848
"keywords": [

packages/react-native-node-api-modules/src/node/path-utils.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ export type PlatformName = "android" | "apple";
1313

1414
export const PLATFORM_EXTENSIONS = {
1515
android: ".android.node",
16-
// TODO: Change to .apple.node
17-
apple: ".xcframework",
16+
apple: ".apple.node",
1817
} as const satisfies Record<PlatformName, string>;
1918
export type PlatformExtentions = (typeof PLATFORM_EXTENSIONS)[PlatformName];
2019

packages/react-native-node-api-modules/src/node/prebuilds/apple.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,28 @@ export async function createXCframework({
9595
// Ideally, it would only be necessary to delete the specific platform+arch, to allow selectively building from source.
9696
fs.rmSync(outputPath, { recursive: true, force: true });
9797

98+
// Xcodebuild requires the output path to end with ".xcframework"
99+
const xcodeOutputPath =
100+
path.extname(outputPath) === ".xcframework"
101+
? outputPath
102+
: `${outputPath}.xcframework`;
103+
98104
await spawn(
99105
"xcodebuild",
100106
[
101107
"-create-xcframework",
102108
...frameworkPaths.flatMap((p) => ["-framework", p]),
103109
"-output",
104-
outputPath,
110+
xcodeOutputPath,
105111
],
106112
{
107113
outputMode: "buffered",
108114
}
109115
);
116+
if (xcodeOutputPath !== outputPath) {
117+
// Rename the xcframework to the original output path
118+
await fs.promises.rename(xcodeOutputPath, outputPath);
119+
}
110120
if (autoLink) {
111121
// Write a file to mark the xcframework is a Node-API module
112122
// TODO: Consider including this in the Info.plist file instead
@@ -122,9 +132,12 @@ export async function createXCframework({
122132
* Determine the filename of the xcframework based on the framework paths.
123133
* Ensuring that all framework paths have the same base name.
124134
*/
125-
export function determineXCFrameworkFilename(frameworkPaths: string[]) {
135+
export function determineXCFrameworkFilename(
136+
frameworkPaths: string[],
137+
extension: ".xcframework" | ".apple.node" = ".xcframework"
138+
) {
126139
const name = determineLibraryBasename(frameworkPaths);
127-
return `${name}.xcframework`;
140+
return `${name}${extension}`;
128141
}
129142

130143
export async function createUniversalAppleLibrary(libraryPaths: string[]) {

0 commit comments

Comments
 (0)