Skip to content

Commit 2c45826

Browse files
committed
ci
1 parent 0376a26 commit 2c45826

File tree

1 file changed

+74
-15
lines changed

1 file changed

+74
-15
lines changed

scripts/build_libffi.js

Lines changed: 74 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,43 @@ const fs = require("node:fs/promises");
55
const path = require("node:path");
66

77
const archs = ["arm64", "x86_64"];
8+
const buildTargets = [
9+
{
10+
dir: "build_iphoneos-arm64",
11+
sdk: "iphoneos",
12+
arch: "arm64",
13+
host: "aarch64-apple-darwin13",
14+
minVersionFlag: "-miphoneos-version-min=13.0",
15+
},
16+
{
17+
dir: "build_iphonesimulator-x86_64",
18+
sdk: "iphonesimulator",
19+
arch: "x86_64",
20+
host: "x86_64-apple-darwin13",
21+
minVersionFlag: "-mios-simulator-version-min=13.0",
22+
},
23+
{
24+
dir: "build_iphonesimulator-arm64",
25+
sdk: "iphonesimulator",
26+
arch: "arm64",
27+
host: "aarch64-apple-darwin13",
28+
minVersionFlag: "-mios-simulator-version-min=13.0",
29+
},
30+
{
31+
dir: "build_macosx-x86_64",
32+
sdk: "macosx",
33+
arch: "x86_64",
34+
host: "x86_64-apple-darwin13",
35+
minVersionFlag: "-mmacosx-version-min=11.0",
36+
},
37+
{
38+
dir: "build_macosx-arm64",
39+
sdk: "macosx",
40+
arch: "arm64",
41+
host: "aarch64-apple-darwin13",
42+
minVersionFlag: "-mmacosx-version-min=11.0",
43+
},
44+
];
845

946
async function main() {
1047
const libffiDir = path.resolve(__dirname, "..", "libffi");
@@ -26,22 +63,24 @@ async function main() {
2663
process.argv.includes("--skip-generate-source");
2764

2865
if (!skipGenerateSource) {
29-
for (const platform of ["ios", "osx"]) {
30-
run("python", [
31-
"generate-darwin-source-and-headers.py",
32-
`--only-${platform}`,
33-
], { cwd: libffiDir, env });
66+
for (const target of buildTargets) {
67+
await configureBuildTarget(target, libffiPath, env);
68+
}
69+
} else {
70+
for (const target of buildTargets) {
71+
const configurePath = libffiPath(target.dir, "config.status");
72+
try {
73+
await fs.access(configurePath);
74+
} catch {
75+
throw new Error(
76+
`Missing ${configurePath}. Re-run without --skip-generate-source to configure build directories.`,
77+
);
78+
}
79+
run("make", [], {
80+
cwd: libffiPath(target.dir),
81+
env: buildTargetEnv(env, target),
82+
});
3483
}
35-
}
36-
37-
for (const dir of [
38-
"iphoneos-arm64",
39-
"iphonesimulator-x86_64",
40-
"iphonesimulator-arm64",
41-
"macosx-x86_64",
42-
"macosx-arm64",
43-
]) {
44-
run("make", ["-C", `build_${dir}`, "install"], { cwd: libffiDir, env });
4584
}
4685

4786
await prepareDir(libffiPath("prebuilt", "iphoneos-arm64", "include"));
@@ -81,6 +120,26 @@ async function main() {
81120
await combineHeaders("iphonesimulator", libffiPath);
82121
}
83122

123+
async function configureBuildTarget(target, libffiPath, baseEnv) {
124+
const targetDir = libffiPath(target.dir);
125+
await fs.rm(targetDir, { recursive: true, force: true });
126+
await fs.mkdir(targetDir, { recursive: true });
127+
128+
const env = buildTargetEnv(baseEnv, target);
129+
130+
run("../configure", ["--host", target.host], { cwd: targetDir, env });
131+
run("make", [], { cwd: targetDir, env });
132+
}
133+
134+
function buildTargetEnv(baseEnv, target) {
135+
return {
136+
...baseEnv,
137+
CC: `xcrun -sdk ${target.sdk} clang -arch ${target.arch}`,
138+
LD: `xcrun -sdk ${target.sdk} ld -arch ${target.arch}`,
139+
CFLAGS: `${target.minVersionFlag} -w`,
140+
};
141+
}
142+
84143
function run(command, args, options = {}) {
85144
console.log(`$ ${command} ${args.join(" ")}`);
86145
const result = spawnSync(command, args, {

0 commit comments

Comments
 (0)