Skip to content

Commit b39fd69

Browse files
committed
Refactor creation of universal apple libraries and add support for ios libraries too
1 parent 9e99519 commit b39fd69

File tree

1 file changed

+36
-16
lines changed

1 file changed

+36
-16
lines changed

packages/ferric/src/build.ts

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -311,34 +311,54 @@ export const buildCommand = new Command("build")
311311
),
312312
);
313313

314+
async function createUniversalAppleLibraries(libraryPathGroups: string[][]) {
315+
const result = await oraPromise(
316+
Promise.all(
317+
libraryPathGroups.map(async (libraryPaths) => {
318+
if (libraryPaths.length === 0) {
319+
return [];
320+
} else if (libraryPaths.length === 1) {
321+
return libraryPaths;
322+
} else {
323+
return [await createUniversalAppleLibrary(libraryPaths)];
324+
}
325+
}),
326+
),
327+
{
328+
text: "Combining arch-specific libraries into universal libraries",
329+
successText: "Combined arch-specific libraries into universal libraries",
330+
failText: (error) =>
331+
`Failed to combine arch-specific libraries: ${error.message}`,
332+
},
333+
);
334+
return result.flat();
335+
}
336+
314337
async function combineLibraries(
315338
libraries: Readonly<[AppleTargetName, string]>[],
316339
): Promise<string[]> {
317340
const result = [];
318341
const darwinLibraries = [];
342+
const iosSimulatorLibraries = [];
319343
for (const [target, libraryPath] of libraries) {
320344
if (target.endsWith("-darwin")) {
321345
darwinLibraries.push(libraryPath);
346+
} else if (
347+
target === "aarch64-apple-ios-sim" ||
348+
target === "x86_64-apple-ios" // Simulator despite name missing -sim suffix
349+
) {
350+
iosSimulatorLibraries.push(libraryPath);
322351
} else {
323352
result.push(libraryPath);
324353
}
325354
}
326-
if (darwinLibraries.length === 0) {
327-
return result;
328-
} else if (darwinLibraries.length === 1) {
329-
return [...result, darwinLibraries[0]];
330-
} else {
331-
const universalPath = await oraPromise(
332-
createUniversalAppleLibrary(darwinLibraries),
333-
{
334-
text: "Combining Darwin libraries into a universal library",
335-
successText: "Combined Darwin libraries into a universal library",
336-
failText: (error) =>
337-
`Failed to combine Darwin libraries: ${error.message}`,
338-
},
339-
);
340-
return [...result, universalPath];
341-
}
355+
356+
const combinedLibraryPaths = await createUniversalAppleLibraries([
357+
darwinLibraries,
358+
iosSimulatorLibraries,
359+
]);
360+
361+
return [...result, ...combinedLibraryPaths];
342362
}
343363

344364
export function isAndroidSupported() {

0 commit comments

Comments
 (0)