peachsim 0.1.2439 → 0.1.2441

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 (143) hide show
  1. package/dist-lib/agent-daemon-client.cjs +1 -1
  2. package/dist-lib/agent-events.cjs +1 -1
  3. package/dist-lib/attached-projects.cjs +1 -1
  4. package/dist-lib/auth/shared-session.cjs +1 -1
  5. package/dist-lib/backend-origin.cjs +1 -1
  6. package/dist-lib/beta.cjs +1 -1
  7. package/dist-lib/beta.mjs +2 -2
  8. package/dist-lib/bridge-constants.cjs +1 -1
  9. package/dist-lib/bridge-contract-input.cjs +1 -1
  10. package/dist-lib/bridge-contract-input.mjs +5 -5
  11. package/dist-lib/bridge-contract.cjs +1 -1
  12. package/dist-lib/bridge-contract.mjs +3 -3
  13. package/dist-lib/bundle-channel.cjs +8180 -8397
  14. package/dist-lib/capture-contract.cjs +1 -1
  15. package/dist-lib/capture-contract.mjs +3 -3
  16. package/dist-lib/cloud-contract.cjs +1 -1
  17. package/dist-lib/cloud-contract.mjs +3 -3
  18. package/dist-lib/cloud-test-args.cjs +1 -1
  19. package/dist-lib/cloud-test-args.mjs +2 -2
  20. package/dist-lib/cloud.cjs +1 -1
  21. package/dist-lib/cloud.mjs +7 -7
  22. package/dist-lib/config.cjs +1 -1
  23. package/dist-lib/config.mjs +5 -5
  24. package/dist-lib/detox/index.cjs +2 -2
  25. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  26. package/dist-lib/esm-chunks/{acorn-FGE4PYDJ.mjs → acorn-FRQNHKFC.mjs} +3 -3
  27. package/dist-lib/esm-chunks/{chunk-HIDNO3RP.mjs → chunk-4BZ3Z3IQ.mjs} +18 -18
  28. package/dist-lib/esm-chunks/{chunk-5T4XBUJP.mjs → chunk-4HEUXQGM.mjs} +4 -4
  29. package/dist-lib/esm-chunks/{chunk-7HANEMO4.mjs → chunk-4ZRMJ5YO.mjs} +1 -1
  30. package/dist-lib/esm-chunks/{chunk-4ZFNH7TU.mjs → chunk-6A6JEVIF.mjs} +1 -1
  31. package/dist-lib/esm-chunks/{chunk-KVTIDLBK.mjs → chunk-ABMB3G7I.mjs} +3 -3
  32. package/dist-lib/esm-chunks/{chunk-C3WBGYP6.mjs → chunk-BAYRN7ZL.mjs} +1 -1
  33. package/dist-lib/esm-chunks/{chunk-KSQ5KM5Y.mjs → chunk-DJMWTW2B.mjs} +1 -1
  34. package/dist-lib/esm-chunks/{chunk-DADGQELM.mjs → chunk-IRMC5BCX.mjs} +1 -1
  35. package/dist-lib/esm-chunks/{chunk-YB27R6JG.mjs → chunk-NPLEBOWJ.mjs} +1 -1
  36. package/dist-lib/esm-chunks/{chunk-HSADZOVN.mjs → chunk-O4EOBXAP.mjs} +1 -1
  37. package/dist-lib/esm-chunks/{chunk-JCKI3VZ6.mjs → chunk-ORYS5CC4.mjs} +1 -1
  38. package/dist-lib/esm-chunks/{chunk-2NPABFPN.mjs → chunk-PMGJ7FLI.mjs} +1 -1
  39. package/dist-lib/esm-chunks/{chunk-6VY6HTJC.mjs → chunk-QUBR7LHU.mjs} +2036 -1918
  40. package/dist-lib/esm-chunks/{chunk-IWJUYJQO.mjs → chunk-QYYJESMK.mjs} +1 -1
  41. package/dist-lib/esm-chunks/{chunk-CVGDRROP.mjs → chunk-VAQJQDWI.mjs} +1 -1
  42. package/dist-lib/esm-chunks/{chunk-DEGYKHN7.mjs → chunk-VCAJFWZD.mjs} +1 -1
  43. package/dist-lib/esm-chunks/{chunk-2EUHEBIJ.mjs → chunk-XO5GX4PI.mjs} +1 -1
  44. package/dist-lib/esm-chunks/{chunk-MIQSRBVU.mjs → chunk-ZCMAKWHN.mjs} +1 -1
  45. package/dist-lib/esm-chunks/{metro-layout-parser-MVUAXRUJ.mjs → metro-layout-parser-AUAVE5VL.mjs} +3 -3
  46. package/dist-lib/expo-swift-bundle.cjs +5580 -5768
  47. package/dist-lib/expo-swift-metadata.cjs +1 -1
  48. package/dist-lib/expo-swift-metadata.mjs +7 -7
  49. package/dist-lib/home-paths.cjs +1 -1
  50. package/dist-lib/host/bridge-host.cjs +6332 -6500
  51. package/dist-lib/host/fetch-proxy-handler.cjs +13891 -13919
  52. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  53. package/dist-lib/host/fetch-proxy-overrides.mjs +2 -2
  54. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  55. package/dist-lib/host/websocket-proxy.cjs +1 -1
  56. package/dist-lib/index.cjs +1 -1
  57. package/dist-lib/jump-to-source-babel.cjs +1 -1
  58. package/dist-lib/jump-to-source-native.cjs +1 -1
  59. package/dist-lib/kotlin-host.cjs +1 -1
  60. package/dist-lib/menu.cjs +1 -1
  61. package/dist-lib/menu.mjs +3 -3
  62. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  63. package/dist-lib/metro-fingerprint-registry.mjs +3 -3
  64. package/dist-lib/metro-production-bundle.cjs +1 -1
  65. package/dist-lib/metro-production-bundle.mjs +4 -4
  66. package/dist-lib/native-app-identity-project.cjs +784 -536
  67. package/dist-lib/native-app-identity-project.mjs +543 -408
  68. package/dist-lib/native-app-identity.cjs +1 -1
  69. package/dist-lib/native-app-identity.mjs +6 -6
  70. package/dist-lib/native-firebase-metadata.cjs +1 -1
  71. package/dist-lib/native-firebase-metadata.mjs +3 -3
  72. package/dist-lib/pdfium-raster.cjs +1 -1
  73. package/dist-lib/pdfium-raster.mjs +2 -2
  74. package/dist-lib/plist.cjs +1 -1
  75. package/dist-lib/plist.mjs +3 -3
  76. package/dist-lib/profiles.cjs +1 -1
  77. package/dist-lib/public-brand.cjs +1 -1
  78. package/dist-lib/public-origins-lib-esm.json +81 -79
  79. package/dist-lib/public-origins-lib.json +185 -195
  80. package/dist-lib/react-native-host-modules.cjs +1 -1
  81. package/dist-lib/react-native-host-modules.mjs +2 -2
  82. package/dist-lib/reap-browser.cjs +1 -1
  83. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  84. package/dist-lib/sdk.cjs +1 -1
  85. package/dist-lib/sdk.mjs +7 -7
  86. package/dist-lib/skills.cjs +7579 -7758
  87. package/dist-lib/swift-compile.cjs +1978 -1922
  88. package/dist-lib/swift-compile.mjs +8 -8
  89. package/dist-lib/swift-package.cjs +1 -1
  90. package/dist-lib/swift-package.mjs +3 -3
  91. package/dist-lib/swift-submit.cjs +1 -1
  92. package/dist-lib/swift-submit.mjs +5 -5
  93. package/dist-lib/swift-toolchain.cjs +3 -1
  94. package/dist-lib/swift.cjs +1 -1
  95. package/dist-lib/vendor/@peculiar/x509.cjs +1 -1
  96. package/dist-lib/vendor/acorn.cjs +1 -1
  97. package/dist-lib/vendor/bplist-parser.cjs +1 -1
  98. package/dist-lib/vendor/ignore.cjs +1 -1
  99. package/dist-lib/vendor/magic-string.cjs +1 -1
  100. package/dist-lib/vendor/plist.cjs +17 -17
  101. package/dist-lib/vendor/smol-toml.cjs +1 -1
  102. package/dist-lib/vendor/stream-json.cjs +1 -1
  103. package/dist-lib/vendor/sucrase/dist/index.js.cjs +1 -1
  104. package/dist-lib/vendor/sucrase/dist/parser/index.js.cjs +1 -1
  105. package/dist-lib/vendor/sucrase/dist/parser/tokenizer/index.js.cjs +1 -1
  106. package/dist-lib/vendor/sucrase/dist/parser/tokenizer/types.js.cjs +1 -1
  107. package/dist-lib/vendor/sucrase.cjs +1 -1
  108. package/dist-lib/vendor/terser.cjs +1 -1
  109. package/dist-lib/vendor/valibot.cjs +1 -1
  110. package/dist-lib/vendor/zod.cjs +1 -1
  111. package/dist-lib/worklet-executable.cjs +1 -1
  112. package/dist-lib/worklet-executable.mjs +3 -3
  113. package/dist-types/packages/peach-compat/src/stubs/native-seams/react-native-cookies.d.ts +4 -0
  114. package/dist-types/packages/peach-engine/src/remote-stream/cloud-display.d.ts +2 -2
  115. package/dist-types/packages/peach-engine/src/render-worker/protocol.d.ts +9 -0
  116. package/package.json +1 -1
  117. package/runtime-companion.json +1 -1
  118. package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/NSDateComponentsFormatter.h +1 -1
  119. package/src/expo-discovery-cache.ts +9 -45
  120. package/src/expo-native-compiler-digest.ts +8 -0
  121. package/src/expo-native-prebuilt.ts +1 -10
  122. package/src/expo-native-workspace.ts +5 -120
  123. package/src/expo-pod-prebuilt.ts +1 -1
  124. package/src/expo-swift-host.ts +48 -35
  125. package/src/host/bridge-host.ts +2 -0
  126. package/src/installed-native-libraries.ts +10 -20
  127. package/src/native-slices.ts +1 -1
  128. package/src/pod-graph-specifications.ts +11 -0
  129. package/src/pods-install.ts +10 -7
  130. package/src/podspec-cocoapods.ts +8 -3
  131. package/src/podspec-sources.ts +19 -15
  132. package/src/swift-clang-type-ownership.ts +118 -0
  133. package/src/swift-compile.ts +20 -12
  134. package/src/swift-guest-image-ledger.ts +48 -0
  135. package/src/swift-guest-link.ts +11 -1
  136. package/src/swift-host.ts +7 -8
  137. package/src/swift-package-manifest.ts +13 -8
  138. package/src/swift-packages.ts +0 -5
  139. package/src/swift-toolchain.ts +1 -1
  140. package/src/xcode-project.ts +64 -46
  141. package/src/portable-expo-contract.ts +0 -108
  142. package/src/portable-expo-workspace.ts +0 -100
  143. package/src/prepared-xcode-phases.ts +0 -194
@@ -0,0 +1,118 @@
1
+ import { execFileSync } from 'node:child_process'
2
+ import { createHash } from 'node:crypto'
3
+ import fs from 'node:fs'
4
+ import path from 'node:path'
5
+ import { isRecord } from './is-record'
6
+ import { WASM_TRIPLE, swiftSdkPaths } from './swift-compile'
7
+ import { swiftModuleToolchain } from './swift-distribution'
8
+ import { swiftCacheDir, swiftEnvironment, withoutCoreDump } from './swift-toolchain'
9
+
10
+ const blockTypedef = /(^[ \t]*typedef\b[^\n]*?\^\s*)(\w+)([ \t]*\)[^;\n]*;)/gm
11
+ const enumTypedef = /(^[ \t]*typedef\s+enum\s+)(\w+)(\s*\{)([^}]*)(}\s*)(\w+)(\s*;)/gm
12
+ const enumConstant = /(^[ \t]*)(\w+)(?=[ \t]*(?:=|,|$))/gm
13
+ const swiftPrivate = ' __attribute__((swift_private))'
14
+
15
+ function exportedNames(moduleRoot: string, name: string): Set<string> {
16
+ const modules = path.join(moduleRoot, 'modules')
17
+ const module = path.join(modules, `${name}.swiftmodule`)
18
+ if (!fs.existsSync(module)) return new Set()
19
+ const key = createHash('sha256').update(fs.readFileSync(module)).digest('hex')
20
+ const directory = path.join(swiftCacheDir(), 'swift-public-names')
21
+ const receipt = path.join(directory, `${key}.json`)
22
+ if (fs.existsSync(receipt)) {
23
+ const names: unknown = JSON.parse(fs.readFileSync(receipt, 'utf8'))
24
+ if (Array.isArray(names) && names.every((value) => typeof value === 'string'))
25
+ return new Set(names)
26
+ }
27
+ const { toolchainBin } = swiftModuleToolchain(moduleRoot)
28
+ const { cFlags, darwin, resources, sysroot } = swiftSdkPaths(moduleRoot, toolchainBin)
29
+ fs.mkdirSync(directory, { recursive: true })
30
+ const scratch = fs.mkdtempSync(path.join(directory, '.extract-'))
31
+ try {
32
+ execFileSync(
33
+ ...withoutCoreDump(path.join(toolchainBin, 'swift-symbolgraph-extract'), [
34
+ '-module-name',
35
+ name,
36
+ '-target',
37
+ WASM_TRIPLE,
38
+ '-enable-objc-interop',
39
+ '-sdk',
40
+ sysroot,
41
+ '-resource-dir',
42
+ resources,
43
+ '-I',
44
+ modules,
45
+ '-I',
46
+ path.join(darwin, 'usr/include'),
47
+ ...cFlags.flatMap((flag) => ['-Xcc', flag]),
48
+ '-Xcc',
49
+ '-fobjc-runtime=gnustep-2.2',
50
+ '-Xcc',
51
+ '-Xclang',
52
+ '-Xcc',
53
+ '-fmodule-format=raw',
54
+ '-skip-synthesized-members',
55
+ '-output-dir',
56
+ scratch,
57
+ ]),
58
+ { env: swiftEnvironment(), stdio: ['ignore', 'pipe', 'pipe'] },
59
+ )
60
+ const graph: unknown = JSON.parse(
61
+ fs.readFileSync(path.join(scratch, `${name}.symbols.json`), 'utf8'),
62
+ )
63
+ if (!isRecord(graph) || !Array.isArray(graph.symbols))
64
+ throw new Error(`${name}: invalid Swift symbol graph`)
65
+ const names = new Set(
66
+ graph.symbols.flatMap((symbol: unknown) => {
67
+ if (!isRecord(symbol) || !Array.isArray(symbol.pathComponents)) return []
68
+ const [declaration] = symbol.pathComponents
69
+ return symbol.pathComponents.length === 1 && typeof declaration === 'string'
70
+ ? [declaration]
71
+ : []
72
+ }),
73
+ )
74
+ const temporary = path.join(scratch, 'names.json')
75
+ fs.writeFileSync(temporary, JSON.stringify([...names].sort()))
76
+ fs.renameSync(temporary, receipt)
77
+ return names
78
+ } finally {
79
+ fs.rmSync(scratch, { recursive: true, force: true })
80
+ }
81
+ }
82
+
83
+ export function clangTypeOwnership(moduleRoot: string, module: string) {
84
+ let names: Set<string> | undefined
85
+ const privateName = (name: string) => {
86
+ names ??= exportedNames(moduleRoot, module)
87
+ return names.has(name) ? swiftPrivate : ''
88
+ }
89
+ return (source: string) =>
90
+ source
91
+ .replace(
92
+ blockTypedef,
93
+ (_match, prefix: string, name: string, suffix: string) =>
94
+ `${prefix}${name}${suffix.slice(0, -1)}${privateName(name)};`,
95
+ )
96
+ .replace(
97
+ enumTypedef,
98
+ (
99
+ _match,
100
+ prefix: string,
101
+ tag: string,
102
+ open: string,
103
+ body: string,
104
+ close: string,
105
+ type: string,
106
+ suffix: string,
107
+ ) => {
108
+ const attribute = privateName(tag).trimStart()
109
+ const tagged = attribute ? `${attribute} ${tag}` : tag
110
+ const cases = body.replace(
111
+ enumConstant,
112
+ (_match, indent: string, name: string) =>
113
+ `${indent}${name}${privateName(name)}`,
114
+ )
115
+ return `${prefix}${tagged}${open}${cases}${close}${type}${privateName(type)}${suffix}`
116
+ },
117
+ )
118
+ }
@@ -50,9 +50,7 @@ import {
50
50
  } from './swift-distribution-contract'
51
51
  import { foundationCategoryObjects } from './swift-foundation'
52
52
  import { compileGuestLink } from './swift-guest-compile'
53
- import {
54
- CLANG_TARGET_MODULE_WRAPPER,
55
- } from './swift-guest-source-inputs'
53
+ import { CLANG_TARGET_MODULE_WRAPPER } from './swift-guest-source-inputs'
56
54
  import {
57
55
  SWIFT_HEADER_COMPILER_WRAPPER,
58
56
  withSwiftHeaderCompiler,
@@ -407,14 +405,10 @@ export const REACH_STAGED_FRAMEWORKS: ReadonlySet<string> = new Set(['React'])
407
405
  export function swiftModuleInterface(
408
406
  moduleRoot: string,
409
407
  name: string,
410
- interfaceRoot?: string,
411
408
  ): { declared: ReadonlySet<string>; header: string } | null {
412
409
  if (REACH_STAGED_FRAMEWORKS.has(name)) return null
413
410
  if (swiftDistributionAt(moduleRoot)) {
414
- const file = path.join(
415
- interfaceRoot ?? path.join(moduleRoot, 'modules'),
416
- `${name}-Swift.h`,
417
- )
411
+ const file = path.join(moduleRoot, 'modules', `${name}-Swift.h`)
418
412
  if (!existsSync(file)) return null
419
413
  const header = clangInterfaceHeader(readFileSync(file, 'utf8'))
420
414
  return { declared: swiftInterfaceDeclarations(header), header }
@@ -5499,6 +5493,12 @@ export function writeSwiftProject(
5499
5493
  includeDirectory: path.join(layout.root, includes),
5500
5494
  sources: units.map(([file]) => file.slice(prefix.length)),
5501
5495
  lateSources: late.map(([file]) => file.slice(prefix.length)),
5496
+ exclude: [
5497
+ ...late.map(([file]) => file.slice(prefix.length)),
5498
+ ...entries
5499
+ .filter(([file]) => /\.(?:inc|inl|ipp|def)$/.test(file))
5500
+ .map(([file]) => file.slice(prefix.length)),
5501
+ ],
5502
5502
  ...(late.length > 0
5503
5503
  ? {
5504
5504
  late: {
@@ -6214,6 +6214,7 @@ export function writeSwiftProject(
6214
6214
  'explicit=',
6215
6215
  'prev=',
6216
6216
  'cxx=',
6217
+ 'plainCxx=',
6217
6218
  'cxxModules=',
6218
6219
  'for arg in "$@"; do',
6219
6220
  ' case $arg in -fmodule-name=*) explicit=1 ;; esac',
@@ -6232,17 +6233,24 @@ export function writeSwiftProject(
6232
6233
  ' fi',
6233
6234
  ' prev=$arg',
6234
6235
  ' case $arg in',
6235
- ' *.mm|*.cpp|*.cc|*.cxx) cxx=1 ;;',
6236
+ ' *.mm) cxx=1 ;;',
6237
+ ' *.cpp|*.cc|*.cxx) cxx=1; plainCxx=1 ;;',
6236
6238
  ' -fno-cxx-modules) cxxModules=off ;;',
6237
6239
  ' -fcxx-modules) cxxModules=on ;;',
6238
6240
  ' esac',
6239
6241
  'done',
6240
6242
  // apple clang claims the toolset's cache path in a c++ unit whose modules
6241
- // are off; this clang reports it unused, which -Werror turns into a failure
6243
+ // are off; this clang reports it unused and can still import explicit
6244
+ // swiftpm umbrella maps from inside a namespace in plain c++.
6242
6245
  'if [ -n "$cxx" ] && [ "$cxxModules" = off ]; then',
6243
6246
  ' for arg in "$@"; do',
6244
6247
  ' shift',
6245
- ' case $arg in -fmodules-cache-path=*) ;; *) set -- "$@" "$arg" ;; esac',
6248
+ ' case $arg in',
6249
+ ' -fmodules-cache-path=*) ;;',
6250
+ ' -fmodule-map-file=*/.build/*/*.build/module.modulemap)',
6251
+ ' [ -n "$plainCxx" ] || set -- "$@" "$arg" ;;',
6252
+ ' *) set -- "$@" "$arg" ;;',
6253
+ ' esac',
6246
6254
  ' done',
6247
6255
  'fi',
6248
6256
  'if [ -n "$name" ] && [ -z "$explicit" ]; then',
@@ -8225,7 +8233,7 @@ function compileSwiftProjectOnce(
8225
8233
  toolchainBin: options.toolchainBin,
8226
8234
  swiftCompiler: preparation.headerCompiler
8227
8235
  ? path.join(root, SWIFT_HEADER_COMPILER_WRAPPER)
8228
- : compiler.SWIFT_EXEC ?? path.join(options.toolchainBin, 'swiftc'),
8236
+ : (compiler.SWIFT_EXEC ?? path.join(options.toolchainBin, 'swiftc')),
8229
8237
  sysroot: swiftSdkPaths(frameworkRoot, options.toolchainBin).sysroot,
8230
8238
  sdk: swiftModuleSdk(frameworkRoot),
8231
8239
  staticClangTargets: input.staticClangTargets ?? [],
@@ -779,3 +779,51 @@ export function createGuestImageLedger(input: GuestImageLedgerInput): GuestImage
779
779
  llvmIR: ir.join('\n') + '\n',
780
780
  }
781
781
  }
782
+
783
+ // a linked module that keeps its name section names each ledger alias by the
784
+ // symbol it stands for, so a trap stack reads as the original link would.
785
+ export function nameGuestImageAliases(
786
+ wasm: Uint8Array,
787
+ symbols: readonly string[],
788
+ ): Buffer {
789
+ const alias = /^__peach_image_\d+_symbol_(\d+)$/
790
+ const parts: Uint8Array[] = [wasm.subarray(0, 8)]
791
+ let position = 8
792
+ while (position < wasm.length) {
793
+ const [size, start] = readNumber(wasm, position + 1)
794
+ const end = start + size
795
+ const custom = wasm[position] === 0 ? readString(wasm, start) : undefined
796
+ if (custom?.[0] !== 'name') {
797
+ parts.push(wasm.subarray(position, end))
798
+ position = end
799
+ continue
800
+ }
801
+ const subsections: Uint8Array[] = [encodedString('name')]
802
+ let at = custom[1]
803
+ while (at < end) {
804
+ const [subSize, subStart] = readNumber(wasm, at + 1)
805
+ const subEnd = subStart + subSize
806
+ if (wasm[at] !== 1) {
807
+ subsections.push(wasm.subarray(at, subEnd))
808
+ at = subEnd
809
+ continue
810
+ }
811
+ let [count, cursor] = readNumber(wasm, subStart)
812
+ const entries: Buffer[] = [encodeNumber(count)]
813
+ for (; count > 0; count--) {
814
+ const [index, next] = readNumber(wasm, cursor)
815
+ const [name, after] = readString(wasm, next)
816
+ cursor = after
817
+ const symbol = symbols[Number(alias.exec(name)?.[1] ?? -1)]
818
+ entries.push(encodeNumber(index), encodedString(symbol ?? name))
819
+ }
820
+ const content = Buffer.concat(entries)
821
+ subsections.push(Buffer.from([1]), encodeNumber(content.length), content)
822
+ at = subEnd
823
+ }
824
+ const section = Buffer.concat(subsections)
825
+ parts.push(Buffer.from([0]), encodeNumber(section.length), section)
826
+ position = end
827
+ }
828
+ return Buffer.concat(parts)
829
+ }
@@ -11,7 +11,11 @@ import {
11
11
  originalGuestArchiveSelections,
12
12
  type AliasedGuestArchive,
13
13
  } from './swift-guest-archive'
14
- import { createGuestImageLedger, type GuestImageObject } from './swift-guest-image-ledger'
14
+ import {
15
+ createGuestImageLedger,
16
+ nameGuestImageAliases,
17
+ type GuestImageObject,
18
+ } from './swift-guest-image-ledger'
15
19
  import {
16
20
  selectedGuestInputImage,
17
21
  type GuestLinkArtifact,
@@ -41,6 +45,7 @@ import {
41
45
  guestWasmSymbols,
42
46
  type SwiftPrunedSdkInputs,
43
47
  } from './swift-wasm-prune'
48
+ import { KEEP_WASM_NAMES } from './wasm-optimize'
44
49
  import type { SwiftGuestImageManifest } from './swiftGuestImageContract'
45
50
  import type {
46
51
  SwiftFrameworkProduct,
@@ -613,6 +618,11 @@ export function linkGuestImages(
613
618
  `guest link selected different inputs after rewriting:\n${changed.join('\n')}`,
614
619
  )
615
620
  fs.renameSync(finalOutput, outputPath(args))
621
+ if (KEEP_WASM_NAMES)
622
+ fs.writeFileSync(
623
+ outputPath(args),
624
+ nameGuestImageAliases(fs.readFileSync(outputPath(args)), plan.symbols),
625
+ )
616
626
  if (projectionStorage && projectionObject)
617
627
  options.projection!.onReserved(projectionStorage, projectionObject)
618
628
  options.onLinkedOwners?.(linkedOwners)
package/src/swift-host.ts CHANGED
@@ -20,7 +20,6 @@ import iosSdk from './ios-sdk-frameworks.json' with { type: 'json' }
20
20
  import { type NativeAppIdentity } from './native-app-identity'
21
21
  import { readNativeAppIdentityFromXcodeTarget } from './native-app-identity-project'
22
22
  import { parsePlistSource } from './plist'
23
- import { preparedSwiftCheckouts } from './prepared-xcode-phases'
24
23
  import { swiftBinaryModules } from './swift-binary-modules'
25
24
  import { normalizeSwiftCatalogPng } from './swift-catalog-png'
26
25
  import {
@@ -433,9 +432,7 @@ function readXcodeAppTargetPrepared(
433
432
  deferPackageResolution: true,
434
433
  })
435
434
  const key = JSON.stringify([input, target, configuration, options.nativeModules])
436
- // a transported workspace consumes attested outputs and pinned checkouts
437
- // directly. readers must not relink its shared, already relocated tree.
438
- if (!preparedScriptInputs.has(key) && !preparedSwiftCheckouts(input)) {
435
+ if (!preparedScriptInputs.has(key)) {
439
436
  const probe = readXcodeAppTarget(input, target, configuration, {
440
437
  ...options,
441
438
  prepareGeneratedSources: false,
@@ -2065,6 +2062,8 @@ const RESOURCE_CONTENT_TYPES: Record<string, string> = {
2065
2062
  '.avif': 'image/avif',
2066
2063
  '.bmp': 'image/bmp',
2067
2064
  '.gif': 'image/gif',
2065
+ '.heic': 'image/heic',
2066
+ '.heif': 'image/heif',
2068
2067
  '.ico': 'image/x-icon',
2069
2068
  '.jpeg': 'image/jpeg',
2070
2069
  '.jpg': 'image/jpeg',
@@ -2460,10 +2459,10 @@ export function buildSwiftBundleFiles(
2460
2459
  for (const [name, bytes] of Object.entries(compileCoreDataModel(model)))
2461
2460
  addFile(`${prefix}${name}`, bytes)
2462
2461
  }
2463
- for (const { base, file } of enumerateBundleResources(
2464
- [...members.keys()],
2465
- bundlePath.endsWith('.bundle'),
2466
- )) {
2462
+ for (const { base, file } of enumerateBundleResources([...members.keys()], {
2463
+ copiedBundle: bundlePath.endsWith('.bundle'),
2464
+ copyLooseRasters: !hosted,
2465
+ })) {
2467
2466
  const disk = members.get(file)!
2468
2467
  watched.push(path.relative(packagePath, disk).split(path.sep).join('/'))
2469
2468
  const bytes = readPackageFile(packagePath, disk, limits.resourceBytes)
@@ -236,6 +236,8 @@ export class SwiftManifestPreparationRequired extends Error {
236
236
  }
237
237
 
238
238
  function dumpInputs(dir: string) {
239
+ const inheritedEnvironment = { ...process.env }
240
+ const env = swiftEnvironment(inheritedEnvironment)
239
241
  const manifests = fs
240
242
  .readdirSync(dir)
241
243
  .filter((name) => /^Package(@swift-[\d.]+)?\.swift$/.test(name))
@@ -251,13 +253,16 @@ function dumpInputs(dir: string) {
251
253
  sha256: createHash('sha256').update(fs.readFileSync(command)).digest('hex'),
252
254
  version: execFileSync(command, ['--version'], {
253
255
  encoding: 'utf8',
254
- env: swiftEnvironment(),
256
+ env,
255
257
  stdio: ['ignore', 'pipe', 'pipe'],
256
258
  }).trim(),
257
259
  }
258
260
  cachedToolchain = { fingerprint, value: toolchain }
261
+ const environment = Object.keys(inheritedEnvironment)
262
+ .sort()
263
+ .map((name) => [name, inheritedEnvironment[name]])
259
264
  const key = createHash('sha256')
260
- .update(JSON.stringify([toolchain, path.resolve(dir)]))
265
+ .update(JSON.stringify([toolchain, path.resolve(dir), environment]))
261
266
  .update(
262
267
  manifests
263
268
  .map((name) => `${name}\0${fs.readFileSync(path.join(dir, name), 'utf8')}`)
@@ -265,14 +270,14 @@ function dumpInputs(dir: string) {
265
270
  )
266
271
  .digest('hex')
267
272
  .slice(0, 32)
268
- return { command, key, toolchain, cached: path.join(cacheDir, `${key}.json`) }
273
+ return { command, env, key, toolchain, cached: path.join(cacheDir, `${key}.json`) }
269
274
  }
270
275
 
271
276
  const manifestPreparations = new Map<string, Promise<void>>()
272
277
 
273
278
  export async function prepareSwiftPackageManifest(dir: string): Promise<void> {
274
279
  await prepareSwiftManifestToolchain()
275
- const { command, key, cached } = dumpInputs(dir)
280
+ const { command, env, key, cached } = dumpInputs(dir)
276
281
  if (fs.existsSync(cached)) return
277
282
  const pending = manifestPreparations.get(key)
278
283
  if (pending) return pending
@@ -291,7 +296,7 @@ export async function prepareSwiftPackageManifest(dir: string): Promise<void> {
291
296
  scratch,
292
297
  'dump-package',
293
298
  ],
294
- { encoding: 'utf8', env: swiftEnvironment(), maxBuffer: 64 * 1024 * 1024 },
299
+ { encoding: 'utf8', env, maxBuffer: 64 * 1024 * 1024 },
295
300
  )
296
301
  const output = path.join(scratch, 'manifest.json')
297
302
  await fs.promises.writeFile(output, stdout)
@@ -326,7 +331,7 @@ function dump(
326
331
  cachedToolchain?.fingerprint !== toolchainFingerprint(swiftCommand())
327
332
  )
328
333
  throw new SwiftManifestPreparationRequired(dir)
329
- const { command, key, toolchain, cached } = dumpInputs(dir)
334
+ const { command, env, key, toolchain, cached } = dumpInputs(dir)
330
335
  if (fs.existsSync(cached))
331
336
  return { key, toolchain, raw: record(JSON.parse(fs.readFileSync(cached, 'utf8'))) }
332
337
  if (requirePrepared) throw new SwiftManifestPreparationRequired(dir)
@@ -346,7 +351,7 @@ function dump(
346
351
  ],
347
352
  {
348
353
  encoding: 'utf8',
349
- env: swiftEnvironment(),
354
+ env,
350
355
  stdio: ['ignore', 'pipe', 'pipe'],
351
356
  maxBuffer: 64 * 1024 * 1024,
352
357
  },
@@ -406,7 +411,7 @@ function linksOnPlatform(
406
411
  // exactly as the source branches it gates do.
407
412
  const GUEST_PLATFORMS = ['ios', 'wasi'] as const
408
413
 
409
- /** the manifest of the package at `dir`, evaluated once per manifest content.
414
+ /** the manifest of the package at `dir`, evaluated per content and caller environment.
410
415
  * conditions hold for the guest platforms unless told otherwise; host macro
411
416
  * evaluation passes its own. */
412
417
  export function swiftPackageManifest(
@@ -19,7 +19,6 @@ import { UNATTENDED_GIT_ENV, withoutGitRepositoryEnv } from './git-repo-env'
19
19
  import { cacheDir } from './home-paths'
20
20
  import { requireNativeGit } from './native-git'
21
21
  import { tryAcquireNumberedLock } from './numbered-lock'
22
- import { preparedSwiftCheckouts, preparedSwiftPin } from './prepared-xcode-phases'
23
22
  import { swiftCTakesReturnAddress } from './swift-compile'
24
23
  import {
25
24
  isSwiftNativeTranslationUnit,
@@ -220,8 +219,6 @@ const sourceFrameworkRecipes = new Map<
220
219
 
221
220
  /** dependency checkouts belong to peach, isolated by the canonical app root. */
222
221
  export function remoteSwiftCheckouts(root: string): string {
223
- const prepared = preparedSwiftCheckouts(root)
224
- if (prepared) return prepared
225
222
  const key = createHash('sha256')
226
223
  .update(fs.realpathSync(root))
227
224
  .digest('hex')
@@ -412,7 +409,6 @@ async function fetchCheckout(
412
409
  signal: AbortSignal | undefined,
413
410
  ): Promise<void> {
414
411
  const dir = path.join(checkouts, identity)
415
- if (preparedSwiftPin(checkouts, identity, pin.location, pin.revision)) return
416
412
  requireNativeGit()
417
413
  const key = checkoutKey(dir, pin)
418
414
  const gitEnv: NodeJS.ProcessEnv = {
@@ -544,7 +540,6 @@ const checkoutKey = (dir: string, pin: Pin) => `${dir}\0${pin.revision}`
544
540
  // `checkout FETCH_HEAD`) must still be the pin.
545
541
  function fetchedCheckout(checkouts: string, identity: string, pin: Pin): string {
546
542
  const dir = path.join(checkouts, identity)
547
- if (preparedSwiftPin(checkouts, identity, pin.location, pin.revision)) return dir
548
543
  const head = path.join(dir, '.git', 'HEAD')
549
544
  if (
550
545
  !verified.has(checkoutKey(dir, pin)) ||
@@ -153,7 +153,7 @@ export function privateSwiftCompilerRelease(): string | null {
153
153
  return process.env.PEACH_SWIFT_PRIVATE_COMPILER_RELEASE?.trim() || null
154
154
  }
155
155
 
156
- function privateSwiftRelease(): string | null {
156
+ export function privateSwiftRelease(): string | null {
157
157
  const compiler = privateSwiftCompilerRelease()
158
158
  if (compiler) return compiler
159
159
  const root = privateSwiftDistributionRoot()
@@ -16,14 +16,23 @@ import { isBazelPackage, readBazelAppTarget } from './bazel-project'
16
16
  import iosSdk from './ios-sdk-frameworks.json' with { type: 'json' }
17
17
  import { isRecord } from './is-record'
18
18
  import { readKeychainAccessGroups } from './native-app-identity'
19
- import { preparedXcodePhase } from './prepared-xcode-phases'
19
+ import {
20
+ POD_GRAPH_SPECIFICATIONS,
21
+ readPodGraphSpecifications,
22
+ } from './pod-graph-specifications'
20
23
  import { localSwiftBinaryModules } from './swift-binary-modules'
21
24
  import { assetSymbolSettingKeys } from './swift-coverage/xcode-assets'
25
+ import { swiftNativePin } from './swift-native-pin'
22
26
  import { isSwiftNativeTranslationUnit, moduleMapName } from './swift-package'
23
27
  import {
24
28
  resolveSwiftPackageRequirementsAsync,
25
29
  type SwiftRemoteRequirement,
26
30
  } from './swift-package-manifest'
31
+ import {
32
+ privateSwiftRelease,
33
+ swiftEnvironment,
34
+ swiftToolchainBin,
35
+ } from './swift-toolchain'
27
36
  import { readXcodeJsonProject } from './xcode-json-project'
28
37
  import {
29
38
  xcodeBuildFileBuildsForIos,
@@ -229,7 +238,8 @@ export interface XcodeAppTarget extends XcodeModuleTarget {
229
238
  /** each installed pod's specification checksum, as the lock records it. */
230
239
  specChecksums: Record<string, string>
231
240
  /** the specifications of pods installed from a local path or a repository. */
232
- localPodspecs: string[]
241
+ localPodspecs: ReadonlyMap<string, string>
242
+ specificationFiles: string[]
233
243
  } | null
234
244
  }
235
245
 
@@ -520,8 +530,7 @@ export function selectXcodeWorkspace(
520
530
  return named.length === 1 ? path.join(directory, named[0]!) : null
521
531
  }
522
532
 
523
- /** the CocoaPods workspace in a project's ios directory, or null while no pods
524
- * are installed: off a Mac, prebuild alone produces the Xcode project. */
533
+ /** the workspace in a project's ios directory, or null before pods are installed. */
525
534
  export function installedXcodeWorkspace(projectRoot: string): string | null {
526
535
  const ios = path.join(projectRoot, 'ios')
527
536
  if (!fs.existsSync(ios)) return null
@@ -531,8 +540,7 @@ export function installedXcodeWorkspace(projectRoot: string): string | null {
531
540
  )
532
541
  }
533
542
 
534
- /** the installed workspace for a compile step that cannot proceed from
535
- * podspecs alone, with the reason it is missing off a Mac. */
543
+ /** the installed workspace for a compile step that needs resolved pod targets. */
536
544
  export function requireInstalledXcodeWorkspace(
537
545
  projectRoot: string,
538
546
  needed: string,
@@ -540,7 +548,7 @@ export function requireInstalledXcodeWorkspace(
540
548
  const workspace = installedXcodeWorkspace(projectRoot)
541
549
  if (!workspace)
542
550
  throw new Error(
543
- `${needed} needs the installed CocoaPods workspace in ${path.join(projectRoot, 'ios')}, which only a Mac prepares or PEACH_PREPARED_NATIVE_WORKSPACES supplies`,
551
+ `${needed} needs an installed pod workspace in ${path.join(projectRoot, 'ios')}`,
544
552
  )
545
553
  return workspace
546
554
  }
@@ -1155,18 +1163,6 @@ function targetMembers(
1155
1163
  if (allOutputs.some((file) => file.endsWith('.swift') || file === infoPlistOutput))
1156
1164
  for (const file of inputFiles) if (fs.existsSync(file)) projectInputs.add(file)
1157
1165
  if (options.prepareGeneratedSources === true && allOutputs.some(isPreparedOutput)) {
1158
- const configuration = settings('CONFIGURATION')
1159
- if (
1160
- preparedXcodePhase(
1161
- project.projectFile,
1162
- targetId,
1163
- phaseId,
1164
- configuration,
1165
- allOutputs,
1166
- false,
1167
- )
1168
- )
1169
- continue
1170
1166
  const phaseDir = path.join(settings('TARGET_TEMP_DIR'), `Script-${phaseId}`)
1171
1167
  for (const lists of fileLists.values())
1172
1168
  for (const { file } of lists)
@@ -1212,18 +1208,26 @@ function targetMembers(
1212
1208
  if (
1213
1209
  preparedSourcePhases.get(key) === stamp &&
1214
1210
  allOutputs.every((file) => fs.existsSync(file))
1215
- ) {
1216
- preparedXcodePhase(
1217
- project.projectFile,
1218
- targetId,
1219
- phaseId,
1220
- configuration,
1221
- allOutputs,
1222
- true,
1223
- )
1211
+ )
1224
1212
  continue
1225
- }
1226
1213
  fs.mkdirSync(phaseDir, { recursive: true })
1214
+ if (process.platform === 'linux') {
1215
+ const bin = swiftToolchainBin(
1216
+ privateSwiftRelease() ?? swiftNativePin().distribution.release,
1217
+ )
1218
+ // Expo runs bash -l, whose login profile can replace the inherited PATH.
1219
+ const startup = path.join(phaseDir, 'peach-tools.sh')
1220
+ fs.writeFileSync(
1221
+ startup,
1222
+ 'if [[ -n "$PEACH_PHASE_BASH_ENV" ]]; then source "$PEACH_PHASE_BASH_ENV"; fi\nexport PATH="$PEACH_PHASE_TOOLCHAIN:$PATH"\n',
1223
+ )
1224
+ const { LD_LIBRARY_PATH } = swiftEnvironment(env)
1225
+ env.LD_LIBRARY_PATH = LD_LIBRARY_PATH
1226
+ env.PEACH_PHASE_TOOLCHAIN = bin
1227
+ env.PEACH_PHASE_BASH_ENV = env.BASH_ENV
1228
+ env.BASH_ENV = startup
1229
+ env.PATH = [bin, env.PATH].filter(Boolean).join(path.delimiter)
1230
+ }
1227
1231
  fs.mkdirSync(settings('BUILT_PRODUCTS_DIR'), { recursive: true })
1228
1232
  fs.mkdirSync(settings('DERIVED_FILE_DIR'), { recursive: true })
1229
1233
  // xcode creates declared output directories before executing the script.
@@ -1294,14 +1298,6 @@ function targetMembers(
1294
1298
  `${targetName}: Run Script "${script}" did not produce ${missing.join(', ')}`,
1295
1299
  )
1296
1300
  preparedSourcePhases.set(key, stamp)
1297
- preparedXcodePhase(
1298
- project.projectFile,
1299
- targetId,
1300
- phaseId,
1301
- configuration,
1302
- allOutputs,
1303
- true,
1304
- )
1305
1301
  }
1306
1302
  }
1307
1303
  project.visitMembers(
@@ -1548,17 +1544,33 @@ function installedPodsSandbox(pods: string): NonNullable<XcodeAppTarget['cocoapo
1548
1544
  specChecksums[entry[1]!] = entry[2]!
1549
1545
  }
1550
1546
  const specs = path.join(pods, 'Local Podspecs')
1547
+ const generated = path.join(pods, POD_GRAPH_SPECIFICATIONS)
1548
+ if (fs.existsSync(generated))
1549
+ return {
1550
+ podfileLock,
1551
+ manifestLock,
1552
+ specChecksums,
1553
+ localPodspecs: readPodGraphSpecifications(generated),
1554
+ specificationFiles: [generated],
1555
+ }
1556
+ const specificationFiles = isDirectory(specs)
1557
+ ? fs
1558
+ .readdirSync(specs)
1559
+ .filter((name) => name.endsWith('.podspec.json'))
1560
+ .sort()
1561
+ .map((name) => path.join(specs, name))
1562
+ : []
1551
1563
  return {
1552
1564
  podfileLock,
1553
1565
  manifestLock,
1554
1566
  specChecksums,
1555
- localPodspecs: isDirectory(specs)
1556
- ? fs
1557
- .readdirSync(specs)
1558
- .filter((name) => name.endsWith('.podspec.json'))
1559
- .sort()
1560
- .map((name) => path.join(specs, name))
1561
- : [],
1567
+ localPodspecs: new Map(
1568
+ specificationFiles.map((file) => [
1569
+ path.basename(file, '.podspec.json'),
1570
+ fs.readFileSync(file, 'utf8'),
1571
+ ]),
1572
+ ),
1573
+ specificationFiles,
1562
1574
  }
1563
1575
  }
1564
1576
 
@@ -2391,7 +2403,9 @@ export function readXcodeAppTarget(
2391
2403
  const { headers, allSources, ...members } = targetMembers(
2392
2404
  ref,
2393
2405
  settings,
2394
- options,
2406
+ ref === app && options.nativeModules
2407
+ ? { ...options, requireSources: false }
2408
+ : options,
2395
2409
  keys,
2396
2410
  xcconfigs,
2397
2411
  )
@@ -3453,7 +3467,11 @@ export function readXcodeAppTarget(
3453
3467
  ...xcconfigs,
3454
3468
  ...(entitlementsFile ? [entitlementsFile] : []),
3455
3469
  ...(cocoapods
3456
- ? [cocoapods.podfileLock, cocoapods.manifestLock, ...cocoapods.localPodspecs]
3470
+ ? [
3471
+ cocoapods.podfileLock,
3472
+ cocoapods.manifestLock,
3473
+ ...cocoapods.specificationFiles,
3474
+ ]
3457
3475
  : []),
3458
3476
  ]),
3459
3477
  ].sort(),