Skip to content

Commit 32c8061

Browse files
committed
What if zx?
1 parent d6f72ba commit 32c8061

3 files changed

Lines changed: 95 additions & 83 deletions

File tree

.github/scripts/xcodebuild.mts

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/usr/bin/env node
2+
import { $ } from 'zx';
3+
import path from 'node:path';
4+
import { parseArgs } from 'node:util';
5+
6+
$.verbose = true;
7+
8+
const { positionals } = parseArgs({ allowPositionals: true });
9+
const [workspace, sdk, scheme, action, ...extra] = positionals;
10+
11+
if (!workspace || !sdk || !scheme || !action) {
12+
console.error('Usage: xcodebuild.mts <workspace> <sdk> <scheme> <action> [...args]');
13+
process.exit(1);
14+
}
15+
16+
async function getDestination(): Promise<string[]> {
17+
const isTest = action === 'test' || action === 'test-without-building';
18+
19+
if (sdk === 'iphoneos' || sdk === 'iphonesimulator') {
20+
if (isTest) {
21+
const devices = (await $`xcrun simctl list devices iPhone available`).stdout;
22+
const match = devices.match(/iPhone \d+ \(([-0-9A-Fa-f]+)\)/);
23+
if (!match) throw new Error('No available iPhone simulator found');
24+
return ['-destination', `platform=iOS Simulator,id=${match[1]}`];
25+
}
26+
return ['-destination', 'generic/platform=iOS Simulator'];
27+
}
28+
29+
if (sdk === 'macosx') {
30+
return [];
31+
}
32+
33+
if (sdk === 'xros' || sdk === 'xrsimulator') {
34+
if (isTest) {
35+
const devices = (await $`xcrun simctl list devices visionOS available`).stdout;
36+
const match = devices.match(/Apple Vision Pro \(([-0-9A-Fa-f]+)\)/);
37+
if (!match) throw new Error('No available visionOS simulator found');
38+
return ['-destination', `platform=visionOS Simulator,id=${match[1]}`];
39+
}
40+
return ['-destination', 'generic/platform=visionOS Simulator'];
41+
}
42+
43+
throw new Error(`Cannot detect sdk: ${sdk}`);
44+
}
45+
46+
async function setupCcache(): Promise<void> {
47+
if (!(await $`command -v ccache`.nothrow()).stdout) {
48+
await $`brew install ccache`;
49+
}
50+
51+
const ccachePath = (await $`which ccache`).stdout.trim();
52+
const ccacheHome = path.join(path.dirname(path.dirname(ccachePath)), 'opt', 'ccache');
53+
const repoRoot = (await $`git rev-parse --show-toplevel`).stdout.trim();
54+
55+
process.env.CCACHE_DIR = path.join(repoRoot, '.ccache');
56+
process.env.CC = path.join(ccacheHome, 'libexec', 'clang');
57+
process.env.CXX = path.join(ccacheHome, 'libexec', 'clang++');
58+
process.env.CMAKE_C_COMPILER_LAUNCHER = ccachePath;
59+
process.env.CMAKE_CXX_COMPILER_LAUNCHER = ccachePath;
60+
61+
await $`ccache --zero-stats`.quiet();
62+
}
63+
64+
const destination = await getDestination();
65+
const derivedDataPath = path.join(path.dirname(workspace), 'build');
66+
const useCcache = process.env.CCACHE_DISABLE !== '1';
67+
68+
if (useCcache) {
69+
await setupCcache();
70+
}
71+
72+
if (!(await $`command -v xcbeautify`.nothrow()).stdout) {
73+
await $`brew install xcbeautify`;
74+
}
75+
76+
const xcodebuildArgs = [
77+
'-workspace', workspace,
78+
'-scheme', scheme,
79+
'-sdk', sdk,
80+
...destination,
81+
'-derivedDataPath', derivedDataPath,
82+
'CODE_SIGNING_ALLOWED=NO',
83+
'COMPILER_INDEX_STORE_ENABLE=NO',
84+
action,
85+
...extra,
86+
];
87+
88+
// Pipe xcodebuild through xcbeautify
89+
await $`xcodebuild ${xcodebuildArgs} | xcbeautify --report junit`;
90+
91+
if (useCcache) {
92+
await $`ccache --show-stats --verbose`;
93+
}

.github/scripts/xcodebuild.sh

Lines changed: 0 additions & 77 deletions
This file was deleted.

.github/workflows/pr.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,7 @@ jobs:
100100
working-directory: apps/fluent-tester/macos
101101

102102
- name: Build macOS app
103-
run: |
104-
set -eox pipefail
105-
./.github/scripts/xcodebuild.sh apps/fluent-tester/macos/FluentTester.xcworkspace macosx ReactTestApp build
103+
run: ./.github/scripts/xcodebuild.mts apps/fluent-tester/macos/FluentTester.xcworkspace macosx ReactTestApp build
106104
env:
107105
CCACHE_DISABLE: 1
108106

@@ -157,9 +155,7 @@ jobs:
157155
working-directory: apps/fluent-tester/ios
158156

159157
- name: Build iOS app
160-
run: |
161-
set -eox pipefail
162-
./.github/scripts/xcodebuild.sh apps/fluent-tester/ios/FluentTester.xcworkspace iphonesimulator ReactTestApp build
158+
run: ./.github/scripts/xcodebuild.mts apps/fluent-tester/ios/FluentTester.xcworkspace iphonesimulator ReactTestApp build
163159
env:
164160
CCACHE_DISABLE: 1
165161

0 commit comments

Comments
 (0)