Skip to content

Commit 1d636d6

Browse files
authored
Fallback on non-universal libraries when getting path for weak-node-api framework. (#303)
1 parent 2c54ae3 commit 1d636d6

File tree

1 file changed

+45
-13
lines changed

1 file changed

+45
-13
lines changed

packages/ferric/src/cargo.ts

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,46 @@ import {
1919
isThirdTierTarget,
2020
} from "./targets.js";
2121

22-
const APPLE_XCFRAMEWORK_CHILDS_PER_TARGET: Record<AppleTargetName, string> = {
23-
"aarch64-apple-darwin": "macos-arm64_x86_64", // Universal
24-
"x86_64-apple-darwin": "macos-arm64_x86_64", // Universal
22+
/**
23+
* A per apple target mapping to a list of xcframework slices in order of priority
24+
*/
25+
const APPLE_XCFRAMEWORK_SLICES_PER_TARGET: Record<AppleTargetName, string[]> = {
26+
"aarch64-apple-darwin": [
27+
"macos-arm64_x86_64", // Universal
28+
"macos-arm64",
29+
],
30+
"x86_64-apple-darwin": [
31+
"macos-arm64_x86_64", // Universal
32+
"macos-x86_64",
33+
],
2534

26-
"aarch64-apple-ios": "ios-arm64",
27-
"aarch64-apple-ios-sim": "ios-arm64_x86_64-simulator", // Universal
28-
"x86_64-apple-ios": "ios-arm64_x86_64-simulator", // Universal
35+
"aarch64-apple-ios": ["ios-arm64"],
36+
"aarch64-apple-ios-sim": [
37+
"ios-arm64_x86_64-simulator", // Universal
38+
"ios-arm64-simulator",
39+
],
40+
"x86_64-apple-ios": [
41+
"ios-arm64_x86_64-simulator", // Universal
42+
"ios-x86_64-simulator",
43+
],
2944

30-
"aarch64-apple-visionos": "xros-arm64",
31-
"aarch64-apple-visionos-sim": "xros-arm64_x86_64-simulator", // Universal
45+
"aarch64-apple-visionos": ["xros-arm64"],
46+
"aarch64-apple-visionos-sim": [
47+
"xros-arm64_x86_64-simulator", // Universal
48+
"xros-arm64-simulator",
49+
],
3250
// The x86_64 target for vision simulator isn't supported
3351
// see https://doc.rust-lang.org/rustc/platform-support.html
3452

35-
"aarch64-apple-tvos": "tvos-arm64",
36-
"aarch64-apple-tvos-sim": "tvos-arm64_x86_64-simulator",
37-
"x86_64-apple-tvos": "tvos-arm64_x86_64-simulator",
53+
"aarch64-apple-tvos": ["tvos-arm64"],
54+
"aarch64-apple-tvos-sim": [
55+
"tvos-arm64_x86_64-simulator", // Universal
56+
"tvos-arm64-simulator",
57+
],
58+
"x86_64-apple-tvos": [
59+
"tvos-arm64_x86_64-simulator", // Universal
60+
"tvos-x86_64-simulator",
61+
],
3862

3963
// "aarch64-apple-ios-macabi": "", // Catalyst
4064
// "x86_64-apple-ios-macabi": "ios-x86_64-simulator",
@@ -145,11 +169,19 @@ export function getTargetAndroidPlatform(target: AndroidTargetName) {
145169
}
146170

147171
export function getWeakNodeApiFrameworkPath(target: AppleTargetName) {
148-
return joinPathAndAssertExistence(
172+
const xcframeworkPath = joinPathAndAssertExistence(
149173
weakNodeApiPath,
150174
"weak-node-api.xcframework",
151-
APPLE_XCFRAMEWORK_CHILDS_PER_TARGET[target],
152175
);
176+
const result = APPLE_XCFRAMEWORK_SLICES_PER_TARGET[target].find((slice) => {
177+
const candidatePath = path.join(xcframeworkPath, slice);
178+
return fs.existsSync(candidatePath);
179+
});
180+
assert(
181+
result,
182+
`No matching slice found in weak-node-api.xcframework for target ${target}`,
183+
);
184+
return joinPathAndAssertExistence(xcframeworkPath, result);
153185
}
154186

155187
export function getWeakNodeApiAndroidLibraryPath(target: AndroidTargetName) {

0 commit comments

Comments
 (0)