@geastack/apple 0.2.20 → 0.2.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
package/targets/ios/build-ios.sh
CHANGED
|
@@ -324,7 +324,8 @@ GEA_CLI_BIN="$GEA_CLI" node "$IOS_DIR/generate-xcode-project.mjs" \
|
|
|
324
324
|
--app-name "$APP_NAME" \
|
|
325
325
|
--bundle-id "$BUNDLE_ID" \
|
|
326
326
|
--generated-dir "$GENERATED_DIR" \
|
|
327
|
-
--project-path "$PROJECT_PATH"
|
|
327
|
+
--project-path "$PROJECT_PATH" \
|
|
328
|
+
--destination "$DESTINATION"
|
|
328
329
|
|
|
329
330
|
SDK="$SIMULATOR_SDK"
|
|
330
331
|
SIMULATOR_DEVICE_ID="${GEA_IOS_SIMULATOR_UDID:-}"
|
|
@@ -6,6 +6,8 @@ import { fileURLToPath } from 'node:url'
|
|
|
6
6
|
|
|
7
7
|
import { execFileSync } from 'node:child_process'
|
|
8
8
|
|
|
9
|
+
import { readUikitNativePackages } from './native-packages.mjs'
|
|
10
|
+
|
|
9
11
|
// The project is the directory this ran in -- the one being compiled, which is
|
|
10
12
|
// also what the CLI resolves from cwd. iOS target sources live next to this
|
|
11
13
|
// script, not in the project. App metadata and icon generation come from the
|
|
@@ -166,14 +168,30 @@ const rendererSources = [
|
|
|
166
168
|
'renderer/view_reconciler.mm',
|
|
167
169
|
].map((file) => source(path.join(iosDir, 'main', file), 'sourcecode.cpp.objcpp'))
|
|
168
170
|
// gea.targets.<ios|tvos>: per-target native sources, static archives, system
|
|
169
|
-
// frameworks
|
|
171
|
+
// frameworks, SDK libraries by name (nativeSystemLibraries, linked as -l<name>)
|
|
172
|
+
// and include directories (validated by the CLI's nativeLink), and
|
|
170
173
|
// resource directories staged into the app bundle (nativeResources).
|
|
171
174
|
const uikitTarget = tvos ? 'tvos' : 'ios'
|
|
172
175
|
const appNativeLink = appMeta.nativeLink?.[uikitTarget] || {}
|
|
176
|
+
// Native code the packages the program uses declare in their own gea-native.json
|
|
177
|
+
// (native-packages.mjs): their sources, frameworks, libraries and defines, and
|
|
178
|
+
// any static library they build once on this Mac (ANGLE for WebGL on tvOS).
|
|
179
|
+
let nativePackages
|
|
180
|
+
try {
|
|
181
|
+
nativePackages = readUikitNativePackages({
|
|
182
|
+
appRoot,
|
|
183
|
+
moduleGraphPath: path.join(generatedDir, 'module-graph', 'gea-module-graph.json'),
|
|
184
|
+
target: uikitTarget,
|
|
185
|
+
simulator: (opt('--destination') || 'simulator') === 'simulator',
|
|
186
|
+
})
|
|
187
|
+
} catch (error) {
|
|
188
|
+
fail(`native packages: ${error.message}`)
|
|
189
|
+
}
|
|
173
190
|
const appNativeSources = [...new Map([
|
|
174
191
|
...findAppNativeSources(),
|
|
175
192
|
...(appMeta.nativeSourcePaths || []).map((file) => source(file, nativeSourceKind(file))),
|
|
176
193
|
...(appMeta.targetNativeSourcePaths?.[uikitTarget] || []).map((file) => source(file, nativeSourceKind(file))),
|
|
194
|
+
...nativePackages.sources.map((file) => source(file, nativeSourceKind(file))),
|
|
177
195
|
].map((entry) => [entry.file, entry])).values()]
|
|
178
196
|
const sources = [
|
|
179
197
|
source(path.join(iosDir, 'main/ios_main.mm'), 'sourcecode.cpp.objcpp'),
|
|
@@ -214,7 +232,8 @@ const assetsGenerated = source(path.join(generatedDir, 'gea_embedded_assets_gene
|
|
|
214
232
|
if (existing(assetsGenerated)) sources.push(assetsGenerated)
|
|
215
233
|
const hasGeneratedFonts = sources.some((entry) => path.basename(entry.file) === 'gea_embedded_font_generated.cpp')
|
|
216
234
|
|
|
217
|
-
|
|
235
|
+
// Plain files copied into the bundle: fonts, and the packages' resources (license notices).
|
|
236
|
+
const fontResources = [...findFontResources(), ...nativePackages.resources].map((file) => resource(file))
|
|
218
237
|
// Each nativeResources destination becomes a folder of the same name in the
|
|
219
238
|
// bundle: stage them under the generated directory, then reference the folders.
|
|
220
239
|
const nativeResourceDir = path.join(generatedDir, 'native-resources')
|
|
@@ -248,7 +267,7 @@ const frameworks = [
|
|
|
248
267
|
'MetalKit.framework',
|
|
249
268
|
'Foundation.framework',
|
|
250
269
|
]
|
|
251
|
-
for (const name of appNativeLink.frameworks || []) {
|
|
270
|
+
for (const name of [...(appNativeLink.frameworks || []), ...nativePackages.frameworks]) {
|
|
252
271
|
if (!frameworks.includes(`${name}.framework`)) frameworks.push(`${name}.framework`)
|
|
253
272
|
}
|
|
254
273
|
|
|
@@ -331,6 +350,7 @@ const includePaths = [
|
|
|
331
350
|
path.join(appRoot, tvos ? 'tvos' : 'ios'),
|
|
332
351
|
...new Set(appNativeSources.map(({ file }) => path.dirname(file))),
|
|
333
352
|
...(appNativeLink.nativeIncludeDirectories || []),
|
|
353
|
+
...nativePackages.includeDirs,
|
|
334
354
|
// Framework include roots (core/host/engine includes + vendor/stb + AnimatedGIF)
|
|
335
355
|
// from the shared manifest gea_sources.sh, passed by build-ios.sh via env.
|
|
336
356
|
...(process.env.GEA_FW_INCLUDE_DIRS || '').split('\n').filter(Boolean),
|
|
@@ -360,6 +380,7 @@ function buildSettings(configuration) {
|
|
|
360
380
|
...(hasGeneratedFonts ? ['GEA_EMBEDDED_HAS_GENERATED_FONTS=1'] : []),
|
|
361
381
|
// gea.defines and the resolved build settings' macros.
|
|
362
382
|
...(buildConfig.defines || []),
|
|
383
|
+
...nativePackages.defines,
|
|
363
384
|
]
|
|
364
385
|
return `{
|
|
365
386
|
ALWAYS_SEARCH_USER_PATHS = NO;${skipAppIcon ? '' : `
|
|
@@ -378,7 +399,7 @@ function buildSettings(configuration) {
|
|
|
378
399
|
${tvos ? 'TVOS_DEPLOYMENT_TARGET = 17.0;' : 'IPHONEOS_DEPLOYMENT_TARGET = 16.0;'}
|
|
379
400
|
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
|
380
401
|
ONLY_ACTIVE_ARCH = ${configuration === 'Debug' ? 'YES' : 'NO'};
|
|
381
|
-
OTHER_LDFLAGS = (${['$(inherited)', '-Wl,-no_deduplicate', ...(appNativeLink.nativeLibraries || [])].map(q).join(', ')});
|
|
402
|
+
OTHER_LDFLAGS = (${['$(inherited)', '-Wl,-no_deduplicate', ...(appNativeLink.nativeLibraries || []), ...nativePackages.libraries, ...[...(appNativeLink.nativeSystemLibraries || []), ...nativePackages.systemLibraries].map((name) => `-l${name}`)].map(q).join(', ')});
|
|
382
403
|
PRODUCT_BUNDLE_IDENTIFIER = ${q(bundleId)};
|
|
383
404
|
PRODUCT_NAME = ${q(appName)};
|
|
384
405
|
SDKROOT = ${tvos ? 'appletvos' : 'iphoneos'};
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
// Native code that packages contribute to an iOS or tvOS build, the UIKit
|
|
2
|
+
// counterpart of the Windows target's native-packages.mjs. A package that
|
|
3
|
+
// carries native code for these targets says so in its own `gea-native.json`,
|
|
4
|
+
// and the build picks it up without the app repeating any of it:
|
|
5
|
+
//
|
|
6
|
+
// { "tvos": { (and/or "ios")
|
|
7
|
+
// "sources": [...], .m, .mm, .c, .cpp compiled into the app
|
|
8
|
+
// "includeDirs": [...], "frameworks": ["Metal"], "systemLibraries": ["z"],
|
|
9
|
+
// "defines": { "NAME": "value" }, "libraries": [...], "resources": [...],
|
|
10
|
+
// "build": { "command": ["tools/build.sh", "{platform}"],
|
|
11
|
+
// "libraries": ["libX.a"], "resources": ["NOTICES.txt"] } } }
|
|
12
|
+
//
|
|
13
|
+
// Paths are relative to the package root. Only the packages the program uses
|
|
14
|
+
// count: those owning a module of the compiled module graph (the app's
|
|
15
|
+
// declared dependencies when there is no graph).
|
|
16
|
+
//
|
|
17
|
+
// `{platform}` in a build command is the SDK being built for: tvos,
|
|
18
|
+
// tvos-simulator, ios or ios-simulator.
|
|
19
|
+
//
|
|
20
|
+
// `build` is for a static library the package cannot ship prebuilt (ANGLE for
|
|
21
|
+
// tvOS is 600 MB and built from upstream sources). The build runs the command
|
|
22
|
+
// with `--out <dir>` once and caches the result under
|
|
23
|
+
// $GEA_NATIVE_CACHE (default ~/.geastack/cache/native), keyed by package,
|
|
24
|
+
// version, target and the command script's contents; its `libraries` are
|
|
25
|
+
// linked and its `resources` (license notices) are copied into the app bundle.
|
|
26
|
+
|
|
27
|
+
import crypto from 'node:crypto'
|
|
28
|
+
import fs from 'node:fs'
|
|
29
|
+
import os from 'node:os'
|
|
30
|
+
import path from 'node:path'
|
|
31
|
+
import { execFileSync } from 'node:child_process'
|
|
32
|
+
import { createRequire } from 'node:module'
|
|
33
|
+
|
|
34
|
+
function readJson(file) {
|
|
35
|
+
try {
|
|
36
|
+
return JSON.parse(fs.readFileSync(file, 'utf8'))
|
|
37
|
+
} catch {
|
|
38
|
+
return null
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// The nearest enclosing directory whose package.json names a package.
|
|
43
|
+
function packageRootOf(file, cache) {
|
|
44
|
+
let dir = path.dirname(file)
|
|
45
|
+
const visited = []
|
|
46
|
+
let found = ''
|
|
47
|
+
for (;;) {
|
|
48
|
+
if (cache.has(dir)) {
|
|
49
|
+
found = cache.get(dir)
|
|
50
|
+
break
|
|
51
|
+
}
|
|
52
|
+
visited.push(dir)
|
|
53
|
+
if (readJson(path.join(dir, 'package.json'))?.name) {
|
|
54
|
+
found = dir
|
|
55
|
+
break
|
|
56
|
+
}
|
|
57
|
+
const parent = path.dirname(dir)
|
|
58
|
+
if (parent === dir) break
|
|
59
|
+
dir = parent
|
|
60
|
+
}
|
|
61
|
+
for (const entry of visited) cache.set(entry, found)
|
|
62
|
+
return found
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function usedPackageRoots(appRoot, moduleGraphPath) {
|
|
66
|
+
const roots = new Set()
|
|
67
|
+
const graph = moduleGraphPath ? readJson(moduleGraphPath) : null
|
|
68
|
+
if (graph && Array.isArray(graph.modules)) {
|
|
69
|
+
const cache = new Map()
|
|
70
|
+
for (const module of graph.modules) {
|
|
71
|
+
const file = module?.file
|
|
72
|
+
if (typeof file !== 'string' || !path.isAbsolute(file) || !fs.existsSync(file)) continue
|
|
73
|
+
const root = packageRootOf(file, cache)
|
|
74
|
+
if (root) roots.add(fs.realpathSync(root))
|
|
75
|
+
}
|
|
76
|
+
return roots
|
|
77
|
+
}
|
|
78
|
+
const manifest = readJson(path.join(appRoot, 'package.json')) || {}
|
|
79
|
+
const appRequire = createRequire(path.join(appRoot, 'package.json'))
|
|
80
|
+
for (const name of [...Object.keys(manifest.dependencies || {}), ...Object.keys(manifest.devDependencies || {})]) {
|
|
81
|
+
try {
|
|
82
|
+
roots.add(fs.realpathSync(path.dirname(appRequire.resolve(`${name}/package.json`))))
|
|
83
|
+
} catch {
|
|
84
|
+
// Not resolvable from the app; it contributes nothing.
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return roots
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function list(value, what, where) {
|
|
91
|
+
if (value === undefined) return []
|
|
92
|
+
if (!Array.isArray(value) || value.some((entry) => typeof entry !== 'string' || !entry)) {
|
|
93
|
+
throw new Error(`${where}: ${what} must be a list of strings`)
|
|
94
|
+
}
|
|
95
|
+
return value
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function inside(root, relative, where) {
|
|
99
|
+
if (path.isAbsolute(relative) || relative.split(/[\\/]/).includes('..')) throw new Error(`${where}: ${relative} must stay inside the package`)
|
|
100
|
+
return path.join(root, relative)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function mustExist(file, where) {
|
|
104
|
+
if (!fs.existsSync(file)) throw new Error(`${where}: ${file} does not exist`)
|
|
105
|
+
return file
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Runs a package's library build once per package version, target and script.
|
|
109
|
+
function buildOutputs(root, manifest, platform, build, where, log) {
|
|
110
|
+
const command = list(build.command, 'build.command', where).map((part) => part.replaceAll('{platform}', platform))
|
|
111
|
+
if (!command.length) throw new Error(`${where}: build.command is empty`)
|
|
112
|
+
const script = mustExist(inside(root, command[0], where), where)
|
|
113
|
+
const libraries = list(build.libraries, 'build.libraries', where)
|
|
114
|
+
const resources = list(build.resources, 'build.resources', where)
|
|
115
|
+
const key = crypto.createHash('sha256').update(fs.readFileSync(script)).update(JSON.stringify(command)).digest('hex').slice(0, 12)
|
|
116
|
+
const cacheRoot = process.env.GEA_NATIVE_CACHE || path.join(os.homedir(), '.geastack', 'cache', 'native')
|
|
117
|
+
const out = path.join(cacheRoot, `${manifest.name.replace(/[\\/]/g, '+')}@${manifest.version || '0'}`, `${platform}-${key}`)
|
|
118
|
+
const outputs = [...libraries, ...resources].map((file) => inside(out, file, where))
|
|
119
|
+
if (outputs.some((file) => !fs.existsSync(file))) {
|
|
120
|
+
log(`[gea] building ${libraries.join(', ')} for ${platform} from ${manifest.name} (once; cached in ${out})`)
|
|
121
|
+
const runner = /\.sh$/.test(script) ? ['bash', [script, ...command.slice(1), '--out', out]] : [script, [...command.slice(1), '--out', out]]
|
|
122
|
+
execFileSync(runner[0], runner[1], { cwd: root, stdio: ['ignore', 'inherit', 'inherit'] })
|
|
123
|
+
for (const file of outputs) mustExist(file, `${where} (after ${command[0]})`)
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
libraries: libraries.map((file) => inside(out, file, where)),
|
|
127
|
+
resources: resources.map((file) => inside(out, file, where)),
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function readUikitNativePackages({ appRoot, moduleGraphPath, target, simulator = false, log = (line) => process.stderr.write(`${line}\n`) }) {
|
|
132
|
+
const result = { sources: [], includeDirs: [], frameworks: [], systemLibraries: [], defines: [], libraries: [], resources: [], packages: [] }
|
|
133
|
+
const appReal = fs.realpathSync(appRoot)
|
|
134
|
+
for (const root of [...usedPackageRoots(appRoot, moduleGraphPath)].sort()) {
|
|
135
|
+
if (root === appReal) continue
|
|
136
|
+
const descriptorFile = path.join(root, 'gea-native.json')
|
|
137
|
+
if (!fs.existsSync(descriptorFile)) continue
|
|
138
|
+
const descriptor = readJson(descriptorFile)
|
|
139
|
+
if (!descriptor) throw new Error(`${descriptorFile} is not readable JSON`)
|
|
140
|
+
const section = descriptor[target]
|
|
141
|
+
if (!section) continue
|
|
142
|
+
const manifest = readJson(path.join(root, 'package.json')) || {}
|
|
143
|
+
const where = `${manifest.name || root} gea-native.json (${target})`
|
|
144
|
+
result.packages.push(manifest.name || root)
|
|
145
|
+
for (const file of list(section.sources, 'sources', where)) result.sources.push(mustExist(inside(root, file, where), where))
|
|
146
|
+
for (const dir of list(section.includeDirs, 'includeDirs', where)) result.includeDirs.push(mustExist(inside(root, dir, where), where))
|
|
147
|
+
for (const file of list(section.libraries, 'libraries', where)) result.libraries.push(mustExist(inside(root, file, where), where))
|
|
148
|
+
for (const file of list(section.resources, 'resources', where)) result.resources.push(mustExist(inside(root, file, where), where))
|
|
149
|
+
result.frameworks.push(...list(section.frameworks, 'frameworks', where))
|
|
150
|
+
for (const name of list(section.systemLibraries, 'systemLibraries', where)) {
|
|
151
|
+
if (!/^[A-Za-z][A-Za-z0-9_.+-]*$/.test(name)) throw new Error(`${where}: invalid system library ${name}`)
|
|
152
|
+
result.systemLibraries.push(name)
|
|
153
|
+
}
|
|
154
|
+
for (const [name, value] of Object.entries(section.defines || {})) {
|
|
155
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(name)) throw new Error(`${where}: invalid define ${name}`)
|
|
156
|
+
result.defines.push(value === true || value === '' ? name : `${name}=${value}`)
|
|
157
|
+
}
|
|
158
|
+
if (section.build) {
|
|
159
|
+
const built = buildOutputs(root, manifest, simulator ? `${target}-simulator` : target, section.build, where, log)
|
|
160
|
+
result.libraries.push(...built.libraries)
|
|
161
|
+
result.resources.push(...built.resources)
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
for (const key of Object.keys(result)) result[key] = [...new Set(result[key])]
|
|
165
|
+
return result
|
|
166
|
+
}
|
|
@@ -1978,6 +1978,8 @@ APP_LINK_RECORD="$(node -e 'const a=JSON.parse(process.argv[1]);const c=a.native
|
|
|
1978
1978
|
APP_NATIVE_LIBRARIES=()
|
|
1979
1979
|
while IFS= read -r library; do [[ -z "$library" ]] || APP_NATIVE_LIBRARIES+=("$library"); done < <(node -e 'for(const p of JSON.parse(process.argv[1]).nativeLibraries)console.log(p)' "$APP_LINK_RECORD")
|
|
1980
1980
|
while IFS= read -r framework; do [[ -z "$framework" ]] || LINK_FRAMEWORKS+=(-framework "$framework"); done < <(node -e 'for(const p of JSON.parse(process.argv[1]).frameworks)console.log(p)' "$APP_LINK_RECORD")
|
|
1981
|
+
# SDK libraries by name (nativeSystemLibraries: "z" links the SDK's libz).
|
|
1982
|
+
while IFS= read -r library; do [[ -z "$library" ]] || LINK_FRAMEWORKS+=("-l$library"); done < <(node -e 'for(const p of JSON.parse(process.argv[1]).nativeSystemLibraries||[])console.log(p)' "$APP_LINK_RECORD")
|
|
1981
1983
|
|
|
1982
1984
|
node "$GEA_CLI" apps sync-native-resources "$APP_ID" --target macos --output "$RES_DIR" > "$BUILD_DIR/native-resources.json"
|
|
1983
1985
|
if [[ "$(node -e 'process.stdout.write(String(JSON.parse(require("fs").readFileSync(process.argv[1],"utf8")).changed))' "$BUILD_DIR/native-resources.json")" == "true" ]]; then BUNDLE_CONTENT_CHANGED=1; fi
|