peachsim 0.1.1856 → 0.1.1857

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.
Files changed (96) hide show
  1. package/cli/outbound-endpoints.ts +4 -0
  2. package/dist-lib/agent-daemon-client.cjs +1 -1
  3. package/dist-lib/agent-events.cjs +1 -1
  4. package/dist-lib/attached-projects.cjs +1 -1
  5. package/dist-lib/auth/shared-session.cjs +1 -1
  6. package/dist-lib/backend-origin.cjs +1 -1
  7. package/dist-lib/beta.cjs +1 -1
  8. package/dist-lib/beta.mjs +1 -1
  9. package/dist-lib/bridge-constants.cjs +1 -1
  10. package/dist-lib/bridge-contract-input.cjs +1 -1
  11. package/dist-lib/bridge-contract-input.mjs +1 -1
  12. package/dist-lib/bridge-contract.cjs +1 -1
  13. package/dist-lib/bridge-contract.mjs +1 -1
  14. package/dist-lib/bundle-channel.cjs +2384 -2156
  15. package/dist-lib/capture-contract.cjs +1 -1
  16. package/dist-lib/capture-contract.mjs +1 -1
  17. package/dist-lib/cloud-contract.cjs +1 -1
  18. package/dist-lib/cloud-contract.mjs +1 -1
  19. package/dist-lib/cloud-test-args.cjs +1 -1
  20. package/dist-lib/cloud-test-args.mjs +1 -1
  21. package/dist-lib/cloud.cjs +1 -1
  22. package/dist-lib/cloud.mjs +1 -1
  23. package/dist-lib/config.cjs +1 -1
  24. package/dist-lib/config.mjs +1 -1
  25. package/dist-lib/detox/index.cjs +1 -1
  26. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  27. package/dist-lib/expo-swift-bundle.cjs +1761 -1474
  28. package/dist-lib/expo-swift-metadata.cjs +1 -1
  29. package/dist-lib/expo-swift-metadata.mjs +1 -1
  30. package/dist-lib/home-paths.cjs +1 -1
  31. package/dist-lib/host/bridge-host.cjs +2699 -2461
  32. package/dist-lib/host/fetch-proxy-handler.cjs +1 -1
  33. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  34. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  35. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  36. package/dist-lib/host/websocket-proxy.cjs +1 -1
  37. package/dist-lib/index.cjs +2 -2
  38. package/dist-lib/jump-to-source-babel.cjs +1 -1
  39. package/dist-lib/jump-to-source-native.cjs +1 -1
  40. package/dist-lib/kotlin-host.cjs +1 -1
  41. package/dist-lib/menu.cjs +1 -1
  42. package/dist-lib/menu.mjs +1 -1
  43. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  44. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  45. package/dist-lib/metro-production-bundle.cjs +1 -1
  46. package/dist-lib/metro-production-bundle.mjs +1 -1
  47. package/dist-lib/metro.cjs +2 -2
  48. package/dist-lib/native-app-identity-project.cjs +2 -2
  49. package/dist-lib/native-app-identity-project.mjs +2 -2
  50. package/dist-lib/native-app-identity.cjs +1 -1
  51. package/dist-lib/native-app-identity.mjs +1 -1
  52. package/dist-lib/native-firebase-metadata.cjs +1 -1
  53. package/dist-lib/native-firebase-metadata.mjs +1 -1
  54. package/dist-lib/pdfium-raster.cjs +1 -1
  55. package/dist-lib/pdfium-raster.mjs +1 -1
  56. package/dist-lib/plist.cjs +1 -1
  57. package/dist-lib/plist.mjs +1 -1
  58. package/dist-lib/profiles.cjs +1 -1
  59. package/dist-lib/public-brand.cjs +1 -1
  60. package/dist-lib/public-origins-lib-esm.json +24 -24
  61. package/dist-lib/public-origins-lib.json +84 -68
  62. package/dist-lib/react-native-host-modules.cjs +1 -1
  63. package/dist-lib/react-native-host-modules.mjs +1 -1
  64. package/dist-lib/reap-browser.cjs +1 -1
  65. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  66. package/dist-lib/sdk.cjs +1 -1
  67. package/dist-lib/sdk.mjs +1 -1
  68. package/dist-lib/skills.cjs +3432 -3176
  69. package/dist-lib/swift-compile.cjs +33 -62
  70. package/dist-lib/swift-compile.mjs +33 -62
  71. package/dist-lib/swift-package.cjs +1 -1
  72. package/dist-lib/swift-package.mjs +1 -1
  73. package/dist-lib/swift-submit.cjs +1 -1
  74. package/dist-lib/swift-submit.mjs +1 -1
  75. package/dist-lib/swift-toolchain.cjs +1 -1
  76. package/dist-lib/swift.cjs +1 -1
  77. package/dist-lib/vite-swift.cjs +44 -72
  78. package/dist-lib/vite.cjs +1 -1
  79. package/dist-lib/worklet-executable.cjs +1 -1
  80. package/dist-lib/worklet-executable.mjs +1 -1
  81. package/package.json +1 -1
  82. package/src/expo-native-compiler-digest.ts +18 -0
  83. package/src/expo-native-prebuilt.ts +353 -0
  84. package/src/expo-native-workspace.ts +1 -1
  85. package/src/expo-swift-host.ts +9 -0
  86. package/src/native-bundles.ts +6 -6
  87. package/src/native-prebuilt.ts +7 -4
  88. package/src/nitro-compile.ts +2 -6
  89. package/src/nitro-superset.ts +7 -23
  90. package/src/package-tree-digest.ts +29 -0
  91. package/src/swift-compile.ts +22 -60
  92. package/src/swift-host.ts +6 -6
  93. package/src/swift-standin-digest.ts +24 -12
  94. package/src/swift-wasm-prune.ts +13 -16
  95. package/src/turbo-bundle.ts +9 -2
  96. package/src/turbo-compile.ts +2 -2
@@ -33,7 +33,7 @@ const utf8Env = { ...process.env, LANG: 'en_US.UTF-8', LC_ALL: 'en_US.UTF-8' }
33
33
 
34
34
  // react native uses these existing CocoaPods inputs to select source targets
35
35
  // or its prebuilt frameworks; each choice needs its own prepared workspace.
36
- function reactNativePodsEnvironment() {
36
+ export function reactNativePodsEnvironment() {
37
37
  return {
38
38
  RCT_USE_PREBUILT_RNCORE: process.env.RCT_USE_PREBUILT_RNCORE,
39
39
  RCT_USE_RN_DEP: process.env.RCT_USE_RN_DEP,
@@ -20,6 +20,7 @@ import {
20
20
  readExpoDiscovery,
21
21
  writeExpoDiscovery,
22
22
  } from './expo-discovery-cache'
23
+ import { prebuiltExpoNative, prebuiltExpoSwiftResult } from './expo-native-prebuilt'
23
24
  import {
24
25
  nativeWorkspaceAvailable,
25
26
  prepareExpoNativeWorkspace,
@@ -1884,6 +1885,13 @@ async function compileExpoSwiftModulesTraced(
1884
1885
  console.error(`[expo-swift ${Math.round(performance.now() - started)}ms] ${message}`)
1885
1886
  try {
1886
1887
  signal.throwIfAborted()
1888
+ const prebuilt = options.installedWorkspace
1889
+ ? null
1890
+ : await prebuiltExpoNative(root, options.iosTarget)
1891
+ if (prebuilt) {
1892
+ report('using the published native build for this app')
1893
+ return await prebuiltExpoSwiftResult(root, prebuilt, signal)
1894
+ }
1887
1895
  report(`discovering app-owned modules: ${root}`)
1888
1896
  const expoUnits = await collectExpoSwiftSources(
1889
1897
  root,
@@ -2202,6 +2210,7 @@ async function compileExpoSwiftModulesTraced(
2202
2210
  linkedLibraries.set(name, library)
2203
2211
  }
2204
2212
  projectFor(packagePath).oneModule = false
2213
+ projectFor(packagePath).optimize = true
2205
2214
  projectFor(packagePath).libraries =
2206
2215
  linkedLibraries.size > 0 ? Object.fromEntries(linkedLibraries) : undefined
2207
2216
  projectFor(packagePath).nativeTargets = inheritExecutableFloor([
@@ -80,14 +80,14 @@ export function nativeBundleAssets(natives: NativeBundles): CompiledModuleAsset[
80
80
 
81
81
  // compilers address each file relative to the bundle, as `/__peach/...`;
82
82
  // `locate` gives the url a file is served at, from its path without the
83
- // leading slash. an ICU url that is already absolute is shared and stays.
83
+ // leading slash. a url that is already absolute is published once for every
84
+ // app (the prebuilt registry, a shared ICU) and stays.
84
85
  export function insertNativeBundleFooters(
85
86
  source: string,
86
87
  natives: NativeBundles,
87
88
  locate: (path: string) => string,
88
89
  ): { source: string; metadata: NativeBundleMetadata | null } {
89
- const served = (url: string) => locate(url.replace(/^\//, ''))
90
- const icu = (url: string) => (url.startsWith('/') ? served(url) : url)
90
+ const served = (url: string) => (url.startsWith('/') ? locate(url.slice(1)) : url)
91
91
  const metadata: NativeBundleMetadata = {}
92
92
  if (natives.expoSwift) {
93
93
  metadata.expoSwift = {
@@ -95,7 +95,7 @@ export function insertNativeBundleFooters(
95
95
  modules: natives.expoSwift.metadata.modules.map((artifact) => ({
96
96
  ...artifact,
97
97
  url: served(artifact.url),
98
- icuUrl: icu(artifact.icuUrl),
98
+ icuUrl: served(artifact.icuUrl),
99
99
  })),
100
100
  }
101
101
  source = insertExpoSwiftFooter(source, metadata.expoSwift)
@@ -110,12 +110,12 @@ export function insertNativeBundleFooters(
110
110
  }
111
111
  if (natives.nitro) {
112
112
  const nitro = natives.nitro.metadata
113
- metadata.nitro = { ...nitro, url: served(nitro.url), icuUrl: icu(nitro.icuUrl) }
113
+ metadata.nitro = { ...nitro, url: served(nitro.url), icuUrl: served(nitro.icuUrl) }
114
114
  source = insertNitroFooter(source, metadata.nitro)
115
115
  }
116
116
  if (natives.turbo) {
117
117
  const turbo = natives.turbo.metadata
118
- metadata.turbo = { ...turbo, url: served(turbo.url), icuUrl: icu(turbo.icuUrl) }
118
+ metadata.turbo = { ...turbo, url: served(turbo.url), icuUrl: served(turbo.icuUrl) }
119
119
  source = insertTurboFooter(source, metadata.turbo)
120
120
  }
121
121
  return { source, metadata: Object.keys(metadata).length ? metadata : null }
@@ -6,9 +6,12 @@
6
6
  // native/<kind>/<name>/<key>/<file>
7
7
  //
8
8
  // <kind> is `rust` for the build cache, `slice` for a hand-ported library's
9
- // wasm slice and `turbo` for an app's compiled C++ TurboModule executable; <key> is a digest of everything the bytes depend on, so an entry
10
- // can never serve different inputs. publishers hold the bucket credentials
11
- // (scripts/ops/native-prebuilt-publish.ts); a host only reads.
9
+ // wasm slice, `turbo` for an app's compiled C++ TurboModule executable, `nitro`
10
+ // for the shared Nitro executable and `expo` for a standard Expo app's native
11
+ // build; <key> is a digest of everything the bytes depend on, so an entry can
12
+ // never serve different inputs. only CI publishers hold the bucket credentials
13
+ // (scripts/ops/native-prebuilt-publish.ts, nitro-superset.ts,
14
+ // expo-native-prebuilt.ts); a host only reads.
12
15
  import { execFileSync } from 'node:child_process'
13
16
  import { createHash } from 'node:crypto'
14
17
  import fs from 'node:fs'
@@ -18,7 +21,7 @@ import { isRecord } from './is-record'
18
21
 
19
22
  export const NATIVE_PREBUILT_ORIGIN = 'https://r2.rnxsim.com'
20
23
 
21
- export type NativeEntryKind = 'nitro' | 'rust' | 'slice' | 'turbo'
24
+ export type NativeEntryKind = 'expo' | 'nitro' | 'rust' | 'slice' | 'turbo'
22
25
 
23
26
  export interface NativeEntryFile {
24
27
  path: string
@@ -223,11 +223,7 @@ export function collectNitroCompileInput(
223
223
  ...collection.libraries,
224
224
  NitroCore: adapter.base64,
225
225
  },
226
- // a mounted view renders through SwiftUI and UIKit, whose conformance and
227
- // metadata records no symbol references, so its artifact links the whole
228
- // distribution as an Expo view artifact does; a module-only artifact loads
229
- // the framework objects its calls reach
230
- lazyDistribution: !views,
226
+ optimize: true,
231
227
  nativeTargets: [
232
228
  ...(dependencies?.nativeTargets ?? []),
233
229
  ...(collection.nativeTargets ?? []),
@@ -492,7 +488,7 @@ export async function compileNitroModule(
492
488
  const project = projectFor(packagePath)
493
489
  project.oneModule = false
494
490
  project.libraries = input.libraries
495
- project.lazyDistribution = input.lazyDistribution
491
+ project.optimize = input.optimize
496
492
  project.nativeTargets = input.nativeTargets
497
493
  project.headerAliases = input.headerAliases
498
494
  // retain the workspace's explicit membership through the package snapshot.
@@ -8,8 +8,7 @@
8
8
  // every app, port and deployment. an app with a provider outside the lock, a
9
9
  // different provider build, or a HybridObject or view its config answers
10
10
  // compiles its own executable.
11
- import { createHash } from 'node:crypto'
12
- import { readdirSync, readFileSync } from 'node:fs'
11
+ import { readFileSync } from 'node:fs'
13
12
  import { createRequire } from 'node:module'
14
13
  import { dirname, join } from 'node:path'
15
14
  import { isRecord } from './is-record'
@@ -25,28 +24,12 @@ import {
25
24
  type NitroBuildConfiguration,
26
25
  type NitroCompiledModule,
27
26
  } from './nitroContract'
27
+ import { packageTreeDigest } from './package-tree-digest'
28
28
  import { swiftNativePin } from './swift-native-pin'
29
29
  import { STANDIN_SOURCE_DIGEST } from './swift-standin-digest'
30
30
 
31
31
  export const NITRO_SUPERSET_ENTRY_NAME = 'superset'
32
32
 
33
- function treeDigest(root: string): string {
34
- const hash = createHash('sha256')
35
- const walk = (directory: string, relative: string) => {
36
- for (const entry of readdirSync(directory, { withFileTypes: true }).sort((a, b) =>
37
- a.name.localeCompare(b.name),
38
- )) {
39
- if (entry.name === 'node_modules') continue
40
- const path = `${relative}${entry.name}`
41
- if (entry.isDirectory()) walk(join(directory, entry.name), `${path}/`)
42
- else if (entry.isFile())
43
- hash.update(`${path}\0`).update(readFileSync(join(directory, entry.name)))
44
- }
45
- }
46
- walk(root, '')
47
- return hash.digest('hex')
48
- }
49
-
50
33
  const packageVersion = (root: string): string =>
51
34
  JSON.parse(readFileSync(join(root, 'package.json'), 'utf8')).version
52
35
 
@@ -57,12 +40,12 @@ const packageVersion = (root: string): string =>
57
40
  * its project compiles for, and each provider's version and source tree, Nitro
58
41
  * Modules' included.
59
42
  */
60
- export function nitroSupersetInputs(options: {
43
+ export async function nitroSupersetInputs(options: {
61
44
  appRoot: string
62
45
  configuration: NitroBuildConfiguration
63
46
  iosDeploymentTarget: string
64
47
  providers: readonly { name: string; root: string }[]
65
- }): Record<string, string> {
48
+ }): Promise<Record<string, string>> {
66
49
  const resolve = createRequire(join(options.appRoot, 'package.json')).resolve
67
50
  const pin = swiftNativePin()
68
51
  const inputs: Record<string, string> = {
@@ -77,7 +60,8 @@ export function nitroSupersetInputs(options: {
77
60
  ...options.providers,
78
61
  { name: 'react-native-nitro-modules', root: nitroModules },
79
62
  ])
80
- inputs[`provider:${name}`] = `${packageVersion(root)}\0${treeDigest(root)}`
63
+ inputs[`provider:${name}`] =
64
+ `${packageVersion(root)}\0${await packageTreeDigest(root)}`
81
65
  return inputs
82
66
  }
83
67
 
@@ -152,7 +136,7 @@ export async function sharedNitroModule(options: {
152
136
  const locked = nitroSupersetLock?.[options.configuration]
153
137
  if (!locked || options.answers.hybridObjects.size > 0 || options.answers.views.size > 0)
154
138
  return null
155
- const inputs = nitroSupersetInputs(options)
139
+ const inputs = await nitroSupersetInputs(options)
156
140
  for (const [name, value] of Object.entries(inputs))
157
141
  if (locked[name] !== value) return null
158
142
  const metadata = await publishedMetadata(
@@ -0,0 +1,29 @@
1
+ import { createHash } from 'node:crypto'
2
+ import { readdirSync } from 'node:fs'
3
+ import { readFile } from 'node:fs/promises'
4
+ import { join } from 'node:path'
5
+
6
+ const READ_AHEAD = 64
7
+
8
+ /** an installed package's source tree digest, its nested node_modules excluded. */
9
+ export async function packageTreeDigest(root: string): Promise<string> {
10
+ const files: string[] = []
11
+ const walk = (directory: string, relative: string) => {
12
+ for (const entry of readdirSync(directory, { withFileTypes: true }).sort((a, b) =>
13
+ a.name.localeCompare(b.name),
14
+ )) {
15
+ if (entry.name === 'node_modules') continue
16
+ const path = `${relative}${entry.name}`
17
+ if (entry.isDirectory()) walk(join(directory, entry.name), `${path}/`)
18
+ else if (entry.isFile()) files.push(path)
19
+ }
20
+ }
21
+ walk(root, '')
22
+ const hash = createHash('sha256')
23
+ for (let start = 0; start < files.length; start += READ_AHEAD) {
24
+ const batch = files.slice(start, start + READ_AHEAD)
25
+ const bytes = await Promise.all(batch.map((file) => readFile(join(root, file))))
26
+ batch.forEach((file, index) => hash.update(`${file}\0`).update(bytes[index]!))
27
+ }
28
+ return hash.digest('hex')
29
+ }
@@ -301,11 +301,8 @@ export interface SwiftCompileInput {
301
301
  * replace the stand-in's traps.
302
302
  */
303
303
  libraries?: Record<string, string>
304
- /**
305
- * link the distribution as an archive: only the objects the program
306
- * references by symbol, plus those that register ObjC classes at load.
307
- */
308
- lazyDistribution?: boolean
304
+ /** size-optimize the linked executable: artifacts built once and fetched many times. */
305
+ optimize?: boolean
309
306
  /** CocoaPods static targets whose C/C++ objects load only to resolve references. */
310
307
  staticClangTargets?: string[]
311
308
  }
@@ -1409,8 +1406,7 @@ export function swiftArtifactHash(
1409
1406
  hash.update(compilerSourceDigest)
1410
1407
  if (input.oneModule) hash.update('one-module\n')
1411
1408
  hash.update(swiftModuleDigest(moduleRoot))
1412
- if (input.lazyDistribution)
1413
- hash.update(`lazy-distribution\n${WASM_OPTIMIZE_IDENTITY}\n`)
1409
+ if (input.optimize) hash.update(`optimize\n${WASM_OPTIMIZE_IDENTITY}\n`)
1414
1410
  for (const file of Object.keys(input.files).sort()) {
1415
1411
  hash.update(createHash('sha256').update(file).digest())
1416
1412
  hash.update(createHash('sha256').update(input.files[file]).digest())
@@ -1602,8 +1598,6 @@ export function emitSwiftPackageManifest(args: {
1602
1598
  * then links only the stdlib and system archives its sources reference.
1603
1599
  */
1604
1600
  distributionLink?: { path: string; files: Map<string, string | Buffer> }
1605
- /** link the distribution objects other than its ObjC registrants lazily. */
1606
- lazyDistribution?: boolean
1607
1601
  /**
1608
1602
  * framework products already built in their own scratch. objects link whole,
1609
1603
  * and modules import from that scratch, so this package's targets never
@@ -1656,7 +1650,6 @@ export function emitSwiftPackageManifest(args: {
1656
1650
  (name) => !object.startsWith(`lib/${name}-`) || reachedFrameworks.has(name),
1657
1651
  ),
1658
1652
  )
1659
- const selectedObjects = new Set(objects)
1660
1653
  const quoted = (object: string) =>
1661
1654
  `"${path.join(moduleRoot, object).replaceAll('\\', '\\\\').replaceAll('"', '\\"')}"`
1662
1655
  // category-only objects have no symbol reference to pull them from the lazy
@@ -1664,30 +1657,19 @@ export function emitSwiftPackageManifest(args: {
1664
1657
  const categoryObjects = new Set(
1665
1658
  foundationCategoryObjects.map((name) => `lib/Foundation-${name}.o`),
1666
1659
  )
1667
- const roots = args.lazyDistribution
1668
- ? swiftObjcRootObjects(distribution.id, moduleRoot, distribution.objects)
1669
- : null
1660
+ const roots = swiftObjcRootObjects(distribution.id, moduleRoot, distribution.objects)
1670
1661
  const eager = new Set(
1671
- objects.filter((object) => roots?.has(object) || categoryObjects.has(object)),
1662
+ objects.filter((object) => roots.has(object) || categoryObjects.has(object)),
1672
1663
  )
1673
1664
  // native headers can reference a framework without a Swift import, and a
1674
1665
  // native target can share a module name with distribution Swift helpers.
1675
1666
  // retain those objects in the archive so undefined symbols select them.
1676
1667
  const list =
1677
1668
  [
1678
- ...(roots
1679
- ? [
1680
- ...[...eager].map(quoted),
1681
- '-Wl,--start-lib',
1682
- ...available.filter((object) => !eager.has(object)).map(quoted),
1683
- '-Wl,--end-lib',
1684
- ]
1685
- : [
1686
- ...objects.map(quoted),
1687
- '-Wl,--start-lib',
1688
- ...available.filter((object) => !selectedObjects.has(object)).map(quoted),
1689
- '-Wl,--end-lib',
1690
- ]),
1669
+ ...[...eager].map(quoted),
1670
+ '-Wl,--start-lib',
1671
+ ...available.filter((object) => !eager.has(object)).map(quoted),
1672
+ '-Wl,--end-lib',
1691
1673
  ...darwinRecordsRegion(distribution.objects.filter(isProvider).map(quoted)),
1692
1674
  ].join('\n') + '\n'
1693
1675
  distributionLinkPath = distributionLink.path.replace(
@@ -5399,7 +5381,6 @@ export function writeSwiftProject(
5399
5381
  path: path.join(layout.root, '.peach-distribution-objects.rsp'),
5400
5382
  files,
5401
5383
  },
5402
- lazyDistribution: input.lazyDistribution,
5403
5384
  }
5404
5385
  : {}),
5405
5386
  ...(prebuilt && frameworkLink
@@ -6316,22 +6297,6 @@ function compileSwiftProjectOnce(
6316
6297
  const root = realpathSync(options.buildRoot)
6317
6298
  const moduleRoot = path.resolve(options.moduleRoot)
6318
6299
  const distribution = swiftDistributionAt(moduleRoot)
6319
- const entrySource = input.files[input.entry]
6320
- // foundation-only entries need the distribution's providers without eagerly
6321
- // linking the entire ui framework graph.
6322
- if (distribution && entrySource && !input.lazyDistribution) {
6323
- const imports = swiftImportNames(entrySource)
6324
- const sources = Object.keys(input.files).filter(
6325
- (file) => /\.(?:swift|c|cc|cpp|cxx|m|mm)$/.test(file) && file !== 'Package.swift',
6326
- )
6327
- if (
6328
- sources.length === 1 &&
6329
- sources[0] === input.entry &&
6330
- imports.includes('Foundation') &&
6331
- !imports.some((name) => distribution.modules.includes(name))
6332
- )
6333
- input = { ...input, lazyDistribution: true }
6334
- }
6335
6300
  const layout: SwiftProjectLayout = {
6336
6301
  root,
6337
6302
  sources: path.join(root, 'Sources', 'App'),
@@ -6493,7 +6458,7 @@ function compileSwiftProjectOnce(
6493
6458
  .join(':'),
6494
6459
  }
6495
6460
  : {}),
6496
- ...(input.lazyDistribution ? { PEACH_DEFER_WASM_LINK: '1' } : {}),
6461
+ PEACH_DEFER_WASM_LINK: '1',
6497
6462
  },
6498
6463
  maxBuffer: 64 * 1024 * 1024,
6499
6464
  timeout: options.timeoutMs,
@@ -6613,11 +6578,9 @@ function compileSwiftProjectOnce(
6613
6578
  ]),
6614
6579
  ]
6615
6580
  const linked = builtArtifact(layout)
6616
- if (input.lazyDistribution) {
6617
- rmSync(path.join(root, '.peach-link.rsp'), { force: true })
6618
- if (existsSync(linked) && statSync(linked).size <= 8)
6619
- rmSync(linked, { force: true })
6620
- }
6581
+ rmSync(path.join(root, '.peach-link.rsp'), { force: true })
6582
+ if (existsSync(linked) && statSync(linked).size <= 8)
6583
+ rmSync(linked, { force: true })
6621
6584
  report('compiling and linking Swift modules')
6622
6585
  try {
6623
6586
  // clang consumes the real emitted headers after swift finishes.
@@ -6755,22 +6718,21 @@ function compileSwiftProjectOnce(
6755
6718
  )
6756
6719
  }
6757
6720
  if (options.project) removeProjectLinks(root)
6721
+ pruneSwiftWasmLink(
6722
+ root,
6723
+ options.toolchainBin,
6724
+ frameworkRoot,
6725
+ input.staticClangTargets,
6726
+ options.project,
6727
+ )
6758
6728
  const output = options.project
6759
6729
  ? projectOutputFile(root, linked, options.project)
6760
6730
  : linked
6761
6731
  const optimized = `${output}.optimized`
6762
- if (input.lazyDistribution) {
6763
- pruneSwiftWasmLink(
6764
- root,
6765
- options.toolchainBin,
6766
- frameworkRoot,
6767
- input.staticClangTargets,
6768
- )
6769
- await optimizeWasm(output, optimized)
6770
- }
6732
+ if (input.optimize) await optimizeWasm(output, optimized)
6771
6733
  const artifact = {
6772
6734
  hash,
6773
- bytes: readFileSync(input.lazyDistribution ? optimized : output),
6735
+ bytes: readFileSync(input.optimize ? optimized : output),
6774
6736
  icu: await icu,
6775
6737
  }
6776
6738
  if (!options.project) saveCompiledArtifact(root, artifact)
package/src/swift-host.ts CHANGED
@@ -242,7 +242,7 @@ export interface SwiftProject {
242
242
  hosted?: SwiftHostedCompileOptions
243
243
  signal?: AbortSignal
244
244
  libraries?: Record<string, string>
245
- lazyDistribution?: boolean
245
+ optimize?: boolean
246
246
  staticClangTargets?: string[]
247
247
  nativeTargets?: SwiftNativeTarget[]
248
248
  headerAliases?: SwiftHeaderAliases
@@ -2067,7 +2067,7 @@ export function sourceStamp(
2067
2067
  hash.update(JSON.stringify(xcodeProjects().get(packagePath)?.behavior ?? {}))
2068
2068
  const libraries = projects().get(packagePath)?.libraries
2069
2069
  if (libraries) hash.update(JSON.stringify(libraries))
2070
- if (projects().get(packagePath)?.lazyDistribution) hash.update('lazy-distribution')
2070
+ if (projects().get(packagePath)?.optimize) hash.update('optimize')
2071
2071
  hash.update(JSON.stringify(projects().get(packagePath)?.staticClangTargets ?? []))
2072
2072
  hash.update(JSON.stringify(projects().get(packagePath)?.oneModule ?? true))
2073
2073
  hash.update(JSON.stringify(projects().get(packagePath)?.nativeTargets ?? []))
@@ -2095,7 +2095,7 @@ export function sourceContentStamp(
2095
2095
  hash.update(JSON.stringify(xcodeProjects().get(packagePath)?.behavior ?? {}))
2096
2096
  const libraries = projects().get(packagePath)?.libraries
2097
2097
  if (libraries) hash.update(JSON.stringify(libraries))
2098
- if (projects().get(packagePath)?.lazyDistribution) hash.update('lazy-distribution')
2098
+ if (projects().get(packagePath)?.optimize) hash.update('optimize')
2099
2099
  hash.update(JSON.stringify(projects().get(packagePath)?.staticClangTargets ?? []))
2100
2100
  hash.update(JSON.stringify(projects().get(packagePath)?.oneModule ?? true))
2101
2101
  hash.update(JSON.stringify(projects().get(packagePath)?.nativeTargets ?? []))
@@ -2242,7 +2242,7 @@ interface SwiftPackageSnapshot {
2242
2242
  native: SwiftNativeModules | null
2243
2243
  glue?: string
2244
2244
  libraries?: Record<string, string>
2245
- lazyDistribution?: boolean
2245
+ optimize?: boolean
2246
2246
  staticClangTargets?: string[]
2247
2247
  }
2248
2248
 
@@ -2373,7 +2373,7 @@ function packageSnapshot(
2373
2373
  project.resourceBundles,
2374
2374
  ),
2375
2375
  native,
2376
- ...(project.lazyDistribution ? { lazyDistribution: true } : {}),
2376
+ ...(project.optimize ? { optimize: true } : {}),
2377
2377
  ...(project.staticClangTargets
2378
2378
  ? { staticClangTargets: project.staticClangTargets }
2379
2379
  : {}),
@@ -2425,7 +2425,7 @@ function snapshotCompileInput(snapshot: SwiftPackageSnapshot): SwiftCompileInput
2425
2425
  entry: snapshot.entry,
2426
2426
  oneModule: snapshot.oneModule,
2427
2427
  ...(snapshot.libraries ? { libraries: snapshot.libraries } : {}),
2428
- ...(snapshot.lazyDistribution ? { lazyDistribution: true } : {}),
2428
+ ...(snapshot.optimize ? { optimize: true } : {}),
2429
2429
  ...(snapshot.staticClangTargets
2430
2430
  ? { staticClangTargets: snapshot.staticClangTargets }
2431
2431
  : {}),
@@ -21,16 +21,19 @@ function resolveImport(fromDir: string, specifier: string): string | null {
21
21
  }
22
22
 
23
23
  /** the entrypoints' local import closure: every source file whose bytes can
24
- * change generated stand-ins or objc objects, sorted. a relative specifier
25
- * that resolves to no file cannot have affected the running program, so it
26
- * is skipped; a missing entrypoint is a partial set and throws. */
27
- export function standinDigestFiles(srcDir: string = import.meta.dirname): string[] {
28
- for (const entry of STANDIN_DIGEST_ENTRYPOINTS)
24
+ * change what they emit, sorted. a relative specifier that resolves to no
25
+ * file cannot have affected the running program, so it is skipped; a missing
26
+ * entrypoint is a partial set and throws. */
27
+ export function sourceClosureFiles(
28
+ srcDir: string,
29
+ entrypoints: readonly string[],
30
+ ): string[] {
31
+ for (const entry of entrypoints)
29
32
  if (!existsSync(path.join(srcDir, entry)))
30
- throw new Error(`stand-in digest entrypoint is missing: ${entry}`)
33
+ throw new Error(`digest entrypoint is missing: ${entry}`)
31
34
  const files: string[] = []
32
35
  const seen = new Set<string>()
33
- const queue = STANDIN_DIGEST_ENTRYPOINTS.map((file) => path.join(srcDir, file))
36
+ const queue = entrypoints.map((file) => path.join(srcDir, file))
34
37
  while (queue.length > 0) {
35
38
  const file = queue.pop()!
36
39
  if (seen.has(file)) continue
@@ -46,12 +49,12 @@ export function standinDigestFiles(srcDir: string = import.meta.dirname): string
46
49
  return files.sort()
47
50
  }
48
51
 
49
- /** a digest of the stand-in entrypoints' local import closure: any edit to
50
- * the emitter, the importer, or anything they reach rebuilds without a
51
- * manual bump. */
52
- export function standinSourceDigest(srcDir: string = import.meta.dirname): string {
52
+ export function sourceClosureDigest(
53
+ srcDir: string,
54
+ entrypoints: readonly string[],
55
+ ): string {
53
56
  const hash = createHash('sha256')
54
- for (const file of standinDigestFiles(srcDir)) {
57
+ for (const file of sourceClosureFiles(srcDir, entrypoints)) {
55
58
  const key = path.relative(srcDir, file)
56
59
  const bytes = readFileSync(file)
57
60
  hash.update(`${Buffer.byteLength(key)}:${key}${bytes.length}:`).update(bytes)
@@ -59,6 +62,15 @@ export function standinSourceDigest(srcDir: string = import.meta.dirname): strin
59
62
  return hash.digest('hex')
60
63
  }
61
64
 
65
+ export const standinDigestFiles = (srcDir: string = import.meta.dirname): string[] =>
66
+ sourceClosureFiles(srcDir, STANDIN_DIGEST_ENTRYPOINTS)
67
+
68
+ /** a digest of the stand-in entrypoints' local import closure: any edit to
69
+ * the emitter, the importer, or anything they reach rebuilds without a
70
+ * manual bump. */
71
+ export const standinSourceDigest = (srcDir: string = import.meta.dirname): string =>
72
+ sourceClosureDigest(srcDir, STANDIN_DIGEST_ENTRYPOINTS)
73
+
62
74
  // build-cli replaces this in every bundle with the digest of the sources it
63
75
  // bundles, so a bundled caller and a builder running those sources agree;
64
76
  // source runs read the files directly.
@@ -851,6 +851,9 @@ export function pruneSwiftWasmLink(
851
851
  toolchainBin: string,
852
852
  moduleRoot: string,
853
853
  staticClangTargets: readonly string[] = [],
854
+ // a sandboxed build wrote the response file as this user: its link runs as
855
+ // that user, so no token it chose can make the host write outside the build.
856
+ owner?: { uid: number; gid: number; env: NodeJS.ProcessEnv },
854
857
  ): void {
855
858
  const rspPath = path.join(directory, '.peach-link.rsp')
856
859
  if (!fs.existsSync(rspPath)) return
@@ -861,8 +864,11 @@ export function pruneSwiftWasmLink(
861
864
  const sdkFlag = tokens.find(
862
865
  (t) => t.startsWith('-L') && t.endsWith('/swift_static/wasi'),
863
866
  )
864
- if (!sdkFlag) return
865
- const sdkWasiDir = sdkFlag.slice(2)
867
+ if (!sdkFlag)
868
+ throw new Error(`swift-wasm-prune: ${rspPath} names no sdk library directory`)
869
+ const sdkWasiDir = fs.realpathSync(sdkFlag.slice(2))
870
+ if (owner && fs.statSync(sdkWasiDir).uid === owner.uid)
871
+ throw new Error(`swift-wasm-prune: the build owns its sdk directory ${sdkWasiDir}`)
866
872
  const sdkObjsDir = ensureUnpackedSdkObjects(sdkWasiDir)
867
873
  const distDir = path.join(moduleRoot, 'lib')
868
874
 
@@ -888,7 +894,7 @@ export function pruneSwiftWasmLink(
888
894
  continue
889
895
  }
890
896
  if (t.endsWith('.o')) {
891
- if (t.startsWith(distDir)) {
897
+ if (path.resolve(t).startsWith(distDir + path.sep)) {
892
898
  if (
893
899
  !foundationCategoryObjects.some(
894
900
  (name) => path.basename(t) === `Foundation-${name}.o`,
@@ -1261,12 +1267,11 @@ export function pruneSwiftWasmLink(
1261
1267
  }
1262
1268
 
1263
1269
  let hasClangObjCEager = false
1264
- const eagerBuildPrunable: ParsedObject[] = []
1265
1270
  for (const f of eagerFiles) {
1266
1271
  const isDist = f.startsWith(distDir)
1267
- const isBuildSwift = !isDist && f.endsWith('.swift.o')
1268
- const obj = distObjs.get(f) ?? parseWasmObjectCached(f, isDist || isBuildSwift, false)
1269
- if (isBuildSwift) eagerBuildPrunable.push(obj)
1272
+ // the app's own objects link whole, as ld64 keeps every swift type record:
1273
+ // storyboards, data models and NSClassFromString name app classes by string.
1274
+ const obj = distObjs.get(f) ?? parseWasmObjectCached(f, isDist, false)
1270
1275
  extractObject(obj)
1271
1276
  if (!isDist && !hasClangObjCEager && obj.symNames.includes('__objc_load')) {
1272
1277
  hasClangObjCEager = true
@@ -1742,15 +1747,6 @@ export function pruneSwiftWasmLink(
1742
1747
  prunedMap.set(o.file, outPath)
1743
1748
  }
1744
1749
 
1745
- for (const o of eagerBuildPrunable) {
1746
- const outPath = path.join(
1747
- prunedObjsDir,
1748
- `build-${path.basename(path.dirname(o.file))}-${path.basename(o.file)}`,
1749
- )
1750
- writePrunedObject(o, outPath)
1751
- prunedMap.set(o.file, outPath)
1752
- }
1753
-
1754
1750
  const extraSdkObjs = allSdkObjFiles
1755
1751
  .filter(
1756
1752
  (f) =>
@@ -1822,6 +1818,7 @@ export function pruneSwiftWasmLink(
1822
1818
  execFileSync(path.join(toolchainBin, 'wasm-ld'), [`@${prunedRspPath}`], {
1823
1819
  stdio: 'pipe',
1824
1820
  maxBuffer: Infinity,
1821
+ ...owner,
1825
1822
  })
1826
1823
  fs.rmSync(rspPath, { force: true })
1827
1824
  }
@@ -1,5 +1,6 @@
1
1
  import { createRequire } from 'node:module'
2
2
  import path from 'node:path'
3
+ import { prebuiltExpoNative } from './expo-native-prebuilt'
3
4
  import { prepareNativeAppRoot } from './expo-native-workspace'
4
5
  import { installedNativeLibraries } from './installed-native-libraries'
5
6
  import {
@@ -39,7 +40,10 @@ export async function compileTurboApp(
39
40
  origin: string,
40
41
  moduleRoot?: string,
41
42
  iosTarget?: string,
42
- ): Promise<{ metadata: TurboCompiledModule; artifact: SwiftArtifact } | null> {
43
+ ): Promise<{ metadata: TurboCompiledModule; artifact: SwiftArtifact | null } | null> {
44
+ // a standard Expo app's published build needs no prepared workspace
45
+ const prebuilt = moduleRoot ? null : await prebuiltExpoNative(appRoot, iosTarget)
46
+ if (prebuilt) return prebuilt.turbo && { metadata: prebuilt.turbo, artifact: null }
43
47
  // the app's own committed ios directory has no installed pods: discovery and
44
48
  // the compile read the prepared workspace, as the Nitro compile does
45
49
  const projectRoot = await prepareNativeAppRoot(appRoot, undefined, iosTarget)
@@ -96,7 +100,10 @@ export async function buildTurboBundle(
96
100
  ): Promise<{ metadata: TurboCompiledModule; assets: CompiledModuleAsset[] } | null> {
97
101
  const compiled = await compileTurboApp(appRoot, '', moduleRoot)
98
102
  if (!compiled) return null
99
- return { metadata: compiled.metadata, assets: compiledModuleAssets(compiled.artifact) }
103
+ return {
104
+ metadata: compiled.metadata,
105
+ assets: compiled.artifact ? compiledModuleAssets(compiled.artifact) : [],
106
+ }
100
107
  }
101
108
 
102
109
  export const handleTurboRequest = compiledModuleRequestHandler(
@@ -153,7 +153,7 @@ export function collectTurboCompileInput(
153
153
  ...collection.libraries,
154
154
  [TURBO_CORE_TARGET]: runtime.base64,
155
155
  },
156
- lazyDistribution: true,
156
+ optimize: true,
157
157
  staticClangTargets: targets.map((target) => target.name),
158
158
  nativeTargets: [
159
159
  ...(dependencies?.nativeTargets ?? []).filter(
@@ -404,7 +404,7 @@ export async function compileTurboModule(options: {
404
404
  const project = projectFor(packagePath)
405
405
  project.oneModule = false
406
406
  project.libraries = input.libraries
407
- project.lazyDistribution = input.lazyDistribution
407
+ project.optimize = input.optimize
408
408
  project.staticClangTargets = input.staticClangTargets
409
409
  project.nativeTargets = input.nativeTargets
410
410
  project.headerAliases = input.headerAliases