Skip to content

Commit d4105a3

Browse files
committed
Refactor to call createAppleFramework with versioned: true for Darwin
1 parent bfd07ee commit d4105a3

File tree

2 files changed

+92
-17
lines changed

2 files changed

+92
-17
lines changed

packages/ferric/src/build.ts

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ import {
3131
ANDROID_TARGETS,
3232
AndroidTargetName,
3333
APPLE_TARGETS,
34+
AppleOperatingSystem,
3435
AppleTargetName,
3536
ensureAvailableTargets,
3637
filterTargetsByPlatform,
38+
parseAppleTargetName,
3739
} from "./targets.js";
3840
import { generateTypeScriptDeclarations } from "./napi-rs.js";
3941
import { getBlockComment } from "./banner.js";
@@ -299,16 +301,16 @@ export const buildCommand = new Command("build")
299301
}
300302

301303
if (appleLibraries.length > 0) {
302-
const libraryPaths = await combineLibraries(appleLibraries);
304+
const libraries = await combineAppleLibraries(appleLibraries);
303305

304306
const frameworkPaths = await oraPromise(
305307
Promise.all(
306-
libraryPaths.map((libraryPath) =>
308+
libraries.map((library) =>
307309
limit(() =>
308-
// TODO: Pass true as `versioned` argument for -darwin targets
309310
createAppleFramework({
310-
libraryPath,
311+
libraryPath: library.path,
311312
bundleIdentifier: appleBundleIdentifier,
313+
versioned: library.os === "darwin",
312314
}),
313315
),
314316
),
@@ -389,16 +391,23 @@ export const buildCommand = new Command("build")
389391
),
390392
);
391393

392-
async function createUniversalAppleLibraries(libraryPathGroups: string[][]) {
394+
async function createUniversalAppleLibraries(
395+
groups: { os: AppleOperatingSystem; paths: string[] }[],
396+
): Promise<{ os: AppleOperatingSystem; path: string }[]> {
393397
const result = await oraPromise(
394398
Promise.all(
395-
libraryPathGroups.map(async (libraryPaths) => {
396-
if (libraryPaths.length === 0) {
399+
groups.map(async ({ os, paths }) => {
400+
if (paths.length === 0) {
397401
return [];
398-
} else if (libraryPaths.length === 1) {
399-
return libraryPaths;
402+
} else if (paths.length == 1) {
403+
return [{ os, path: paths[0] }];
400404
} else {
401-
return [await createUniversalAppleLibrary(libraryPaths)];
405+
return [
406+
{
407+
os,
408+
path: await createUniversalAppleLibrary(paths),
409+
},
410+
];
402411
}
403412
}),
404413
),
@@ -412,15 +421,21 @@ async function createUniversalAppleLibraries(libraryPathGroups: string[][]) {
412421
return result.flat();
413422
}
414423

415-
async function combineLibraries(
424+
type CombinedAppleLibrary = {
425+
path: string;
426+
os: AppleOperatingSystem;
427+
};
428+
429+
async function combineAppleLibraries(
416430
libraries: Readonly<[AppleTargetName, string]>[],
417-
): Promise<string[]> {
431+
): Promise<CombinedAppleLibrary[]> {
418432
const result = [];
419433
const darwinLibraries = [];
420434
const iosSimulatorLibraries = [];
421435
const tvosSimulatorLibraries = [];
422436
for (const [target, libraryPath] of libraries) {
423-
if (target.endsWith("-darwin")) {
437+
const { os } = parseAppleTargetName(target);
438+
if (os === "darwin") {
424439
darwinLibraries.push(libraryPath);
425440
} else if (
426441
target === "aarch64-apple-ios-sim" ||
@@ -433,14 +448,14 @@ async function combineLibraries(
433448
) {
434449
tvosSimulatorLibraries.push(libraryPath);
435450
} else {
436-
result.push(libraryPath);
451+
result.push({ os, path: libraryPath });
437452
}
438453
}
439454

440455
const combinedLibraryPaths = await createUniversalAppleLibraries([
441-
darwinLibraries,
442-
iosSimulatorLibraries,
443-
tvosSimulatorLibraries,
456+
{ os: "darwin", paths: darwinLibraries },
457+
{ os: "ios", paths: iosSimulatorLibraries },
458+
{ os: "tvos", paths: tvosSimulatorLibraries },
444459
]);
445460

446461
return [...result, ...combinedLibraryPaths];

packages/ferric/src/targets.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import assert from "node:assert";
12
import cp from "node:child_process";
23

34
import { assertFixable } from "@react-native-node-api/cli-utils";
@@ -48,6 +49,65 @@ export const APPLE_TARGETS = [
4849
] as const;
4950
export type AppleTargetName = (typeof APPLE_TARGETS)[number];
5051

52+
const APPLE_ARCHITECTURES = [
53+
"aarch64",
54+
"arm64_32",
55+
"arm64e",
56+
"armv7",
57+
"armv7s",
58+
"x86_64",
59+
"x86_64h",
60+
"i386",
61+
"i686",
62+
] as const;
63+
export type AppleArchitecture = (typeof APPLE_ARCHITECTURES)[number];
64+
export function isAppleArchitecture(
65+
architecture: string,
66+
): architecture is AppleArchitecture {
67+
return (APPLE_ARCHITECTURES as readonly string[]).includes(architecture);
68+
}
69+
70+
const APPLE_OPERATING_SYSTEMS = [
71+
"darwin",
72+
"ios",
73+
"tvos",
74+
"visionos",
75+
"watchos",
76+
] as const;
77+
export type AppleOperatingSystem = (typeof APPLE_OPERATING_SYSTEMS)[number];
78+
export function isAppleOperatingSystem(os: string): os is AppleOperatingSystem {
79+
return (APPLE_OPERATING_SYSTEMS as readonly string[]).includes(os);
80+
}
81+
82+
const APPLE_VARIANTS = ["sim", "macabi"] as const;
83+
export type AppleVariant = (typeof APPLE_VARIANTS)[number];
84+
export function isAppleVariant(variant: string): variant is AppleVariant {
85+
return (APPLE_VARIANTS as readonly string[]).includes(variant);
86+
}
87+
88+
export function parseAppleTargetName(target: AppleTargetName): {
89+
architecture: AppleArchitecture;
90+
os: AppleOperatingSystem;
91+
variant?: AppleVariant;
92+
} {
93+
const [architecture, vendor, os, variant] = target.split("-");
94+
assert(vendor === "apple", "Expected vendor to be apple");
95+
assert(
96+
isAppleArchitecture(architecture),
97+
`Unexpected architecture: ${architecture}`,
98+
);
99+
assert(isAppleOperatingSystem(os), `Unexpected operating system: ${os}`);
100+
assert(
101+
typeof variant === "undefined" || isAppleVariant(variant),
102+
`Unexpected variant: ${variant}`,
103+
);
104+
return {
105+
architecture,
106+
os,
107+
variant,
108+
};
109+
}
110+
51111
export const ALL_TARGETS = [...ANDROID_TARGETS, ...APPLE_TARGETS] as const;
52112
export type TargetName = (typeof ALL_TARGETS)[number];
53113

0 commit comments

Comments
 (0)