peachsim 0.1.679 → 0.1.681

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 (84) hide show
  1. package/cli/commands/daemon-mac-app.ts +11 -2
  2. package/cli/commands/daemon.ts +2 -3
  3. package/cli/commands/swift.ts +40 -19
  4. package/cli/outbound-endpoints.ts +8 -0
  5. package/dist-lib/agent-daemon-client.cjs +1 -1
  6. package/dist-lib/agent-events.cjs +1 -1
  7. package/dist-lib/agent-identity.cjs +1 -1
  8. package/dist-lib/agent-sessions.cjs +1 -1
  9. package/dist-lib/attached-projects.cjs +1 -1
  10. package/dist-lib/auth/shared-session.cjs +1 -1
  11. package/dist-lib/backend-origin.cjs +1 -1
  12. package/dist-lib/beta.cjs +1 -1
  13. package/dist-lib/beta.mjs +1 -1
  14. package/dist-lib/bridge-constants.cjs +1 -1
  15. package/dist-lib/bridge-contract-input.cjs +1 -1
  16. package/dist-lib/bridge-contract-input.mjs +1 -1
  17. package/dist-lib/bridge-contract.cjs +1 -1
  18. package/dist-lib/bridge-contract.mjs +1 -1
  19. package/dist-lib/capture-contract.cjs +1 -1
  20. package/dist-lib/capture-contract.mjs +1 -1
  21. package/dist-lib/cli-constants.cjs +1 -1
  22. package/dist-lib/cloud-contract.cjs +1 -1
  23. package/dist-lib/cloud-contract.mjs +1 -1
  24. package/dist-lib/cloud-test-args.cjs +1 -1
  25. package/dist-lib/cloud-test-args.mjs +1 -1
  26. package/dist-lib/cloud.cjs +1 -1
  27. package/dist-lib/cloud.mjs +1 -1
  28. package/dist-lib/config.cjs +1 -1
  29. package/dist-lib/detox/index.cjs +1 -1
  30. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  31. package/dist-lib/home-paths.cjs +1 -1
  32. package/dist-lib/host/bridge-host.cjs +2548 -2327
  33. package/dist-lib/host/fetch-proxy-handler.cjs +5 -13
  34. package/dist-lib/host/fetch-proxy-overrides.cjs +2 -6
  35. package/dist-lib/host/fetch-proxy-overrides.mjs +2 -6
  36. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  37. package/dist-lib/host/websocket-proxy.cjs +1 -1
  38. package/dist-lib/index.cjs +1 -1
  39. package/dist-lib/jump-to-source-babel.cjs +1 -1
  40. package/dist-lib/jump-to-source-native.cjs +1 -1
  41. package/dist-lib/kotlin-host.cjs +1 -1
  42. package/dist-lib/menu.cjs +1 -1
  43. package/dist-lib/menu.mjs +1 -1
  44. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  45. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  46. package/dist-lib/metro-production-bundle.cjs +1 -1
  47. package/dist-lib/metro-production-bundle.mjs +1 -1
  48. package/dist-lib/metro.cjs +1 -1
  49. package/dist-lib/native-app-identity.cjs +1 -1
  50. package/dist-lib/native-app-identity.mjs +1 -1
  51. package/dist-lib/native-firebase-metadata.cjs +1 -1
  52. package/dist-lib/native-firebase-metadata.mjs +1 -1
  53. package/dist-lib/plist.cjs +1 -1
  54. package/dist-lib/plist.mjs +1 -1
  55. package/dist-lib/profiles.cjs +1 -1
  56. package/dist-lib/public-brand.cjs +1 -1
  57. package/dist-lib/react-native-host-modules.cjs +1 -1
  58. package/dist-lib/react-native-host-modules.mjs +1 -1
  59. package/dist-lib/render-mode.cjs +1 -1
  60. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  61. package/dist-lib/sdk.cjs +1 -1
  62. package/dist-lib/sdk.mjs +1 -1
  63. package/dist-lib/skills.cjs +2296 -2053
  64. package/dist-lib/swift-compile.cjs +78 -12
  65. package/dist-lib/swift-compile.mjs +76 -12
  66. package/dist-lib/swift-package.cjs +1 -1
  67. package/dist-lib/swift-package.mjs +1 -1
  68. package/dist-lib/swift-submit.cjs +1 -1
  69. package/dist-lib/swift-submit.mjs +1 -1
  70. package/dist-lib/swift-toolchain.cjs +115 -0
  71. package/dist-lib/swift.cjs +1 -1
  72. package/dist-lib/vite-swift.cjs +470 -149
  73. package/dist-lib/vite.cjs +1 -1
  74. package/package.json +7 -1
  75. package/skills/contrast/SKILL.md +1 -1
  76. package/src/expo-swift-host.ts +9 -13
  77. package/src/host/fetch-proxy-handler.ts +11 -10
  78. package/src/host/fetch-proxy-overrides.ts +9 -10
  79. package/src/swift-compile.ts +76 -10
  80. package/src/swift-distribution-contract.ts +138 -0
  81. package/src/swift-distribution.lock.json +20 -0
  82. package/src/swift-distribution.ts +108 -0
  83. package/src/swift-host.ts +8 -30
  84. package/src/swift-toolchain.ts +102 -0
package/src/swift-host.ts CHANGED
@@ -5,7 +5,6 @@ import { createHash } from 'node:crypto'
5
5
  import fs from 'node:fs'
6
6
  import os from 'node:os'
7
7
  import path from 'node:path'
8
- import { swiftToolchainBin } from '../../../src/compile/swiftToolchain'
9
8
  import {
10
9
  enumerateBundleColors,
11
10
  enumerateBundleSymbols,
@@ -19,6 +18,7 @@ import {
19
18
  withNativeSourceGlue,
20
19
  swiftModuleInputFiles,
21
20
  } from './swift-compile'
21
+ import { swiftDistributionRoot, swiftModuleToolchain } from './swift-distribution'
22
22
  import {
23
23
  MAX_SWIFT_COMPILE_FILES,
24
24
  MAX_SWIFT_COMPILE_SOURCE_BYTES,
@@ -590,22 +590,21 @@ async function compile(
590
590
  stamp,
591
591
  package: content,
592
592
  }
593
+ // a linked checkout, else the installed distribution; with neither, the
594
+ // package compiles on Contrast as before
593
595
  const moduleRoot =
594
596
  moduleRootOverride ??
595
597
  linkedModuleRoots(packagePath).find((root) =>
596
598
  fs.existsSync(path.join(root, 'toolchain.json')),
597
- )
599
+ ) ??
600
+ (await swiftDistributionRoot())
598
601
  if (!moduleRoot)
599
602
  return {
600
603
  ...(await compileRemote(packagePath, entry, snapshot)),
601
604
  stamp,
602
605
  package: content,
603
606
  }
604
- const toolchain = localSwiftToolchain(moduleRoot)
605
- if (!toolchain)
606
- throw new Error(
607
- `the Swift toolchain ${moduleRoot}/toolchain.json names is not installed under ~/Library/Developer/Toolchains`,
608
- )
607
+ const toolchain = swiftModuleToolchain(moduleRoot)
609
608
  const artifact = await compileSwiftProjectUnit(snapshotCompileInput(snapshot, entry), {
610
609
  // the compile rewrites Sources/App in its root before swiftpm builds, and
611
610
  // its lock orders one process only: two vites on one root (a lane's dev
@@ -628,29 +627,8 @@ async function compile(
628
627
  return { ...artifact, stamp, package: content }
629
628
  }
630
629
 
631
- // the release a SwiftUI module checkout builds with and its installed
632
- // toolchain; null when the checkout or the toolchain is missing.
633
- export function localSwiftToolchain(
634
- moduleRoot: string,
635
- ): { release: string; toolchainBin: string } | null {
636
- const manifest = path.join(moduleRoot, 'toolchain.json')
637
- if (!fs.existsSync(manifest)) return null
638
- const toolchain: unknown = JSON.parse(fs.readFileSync(manifest, 'utf8'))
639
- const release =
640
- toolchain && typeof toolchain === 'object'
641
- ? Reflect.get(toolchain, 'release')
642
- : undefined
643
- if (typeof release !== 'string') {
644
- throw new Error(`swift toolchain manifest at ${moduleRoot} has no release`)
645
- }
646
- const toolchainBin = swiftToolchainBin(release)
647
- return fs.existsSync(path.join(toolchainBin, 'swift'))
648
- ? { release, toolchainBin }
649
- : null
650
- }
651
-
652
- // an npm-installed peachsim ships neither the SwiftUI module nor a toolchain,
653
- // so the package compiles where a Contrast project's does: Contrast's compile
630
+ // a peachsim with neither a module checkout nor a distribution compiles the
631
+ // package where a Contrast project's compiles: Contrast's compile
654
632
  // route, authorized by `peach login` or PEACH_API_KEY. the service renders the
655
633
  // native dispatch glue itself under the package's id and answers the wasm at a
656
634
  // public content address, which is fetched once and served from this dev
@@ -0,0 +1,102 @@
1
+ // the one place that finds the swift.org toolchain app Swift compiles with.
2
+ // a binary .swiftmodule loads only in the compiler release that wrote it, so
3
+ // every caller names the release from packages/sootsim-swift/toolchain.json
4
+ // or the Swift distribution's lock (docs/swift-distribution.md).
5
+ //
6
+ // node builtins only: packages/sootsim-swift/scripts/build.sh imports this
7
+ // file straight from a checkout, with no install.
8
+ import { execFileSync } from 'node:child_process'
9
+ import fs from 'node:fs'
10
+ import os from 'node:os'
11
+ import path from 'node:path'
12
+
13
+ /**
14
+ * the bin directory of the toolchain for `release`, unverified. macOS: the
15
+ * Xcode Toolchains directory, the user's before the system's. Linux: a
16
+ * builder's `$CONTRAST_SWIFT_TOOLCHAINS/<release>`
17
+ * (packages/sootsim-swift/scripts/install-linux-toolchain.sh fills it), else
18
+ * the cf-build image's `/opt/swift/<release>`, else the `swift` first on PATH.
19
+ */
20
+ export function swiftToolchainBin(release: string): string {
21
+ if (process.platform === 'darwin') {
22
+ const dirs = [os.homedir(), '/'].map((base) =>
23
+ path.join(base, `Library/Developer/Toolchains/${release}.xctoolchain/usr/bin`),
24
+ )
25
+ return dirs.find((dir) => fs.existsSync(path.join(dir, 'swift'))) ?? dirs[0]!
26
+ }
27
+ if (process.env.CONTRAST_SWIFT_TOOLCHAINS) {
28
+ return path.join(process.env.CONTRAST_SWIFT_TOOLCHAINS, release, 'usr/bin')
29
+ }
30
+ const image = path.join('/opt/swift', release, 'usr/bin')
31
+ if (fs.existsSync(path.join(image, 'swift'))) return image
32
+ return (
33
+ (process.env.PATH ?? '')
34
+ .split(path.delimiter)
35
+ .find((dir) => dir && fs.existsSync(path.join(dir, 'swift'))) ?? image
36
+ )
37
+ }
38
+
39
+ const verified = new Map<string, string>()
40
+
41
+ /**
42
+ * swiftToolchainBin, checked: its swift is exactly `release` and has the
43
+ * `<release>_wasm` SDK. anything else fails with one message naming the
44
+ * release and the commands that install it.
45
+ */
46
+ export function swiftToolchain(release: string, wasmSdkChecksum: string): string {
47
+ const cached = verified.get(release)
48
+ if (cached) return cached
49
+ const bin = swiftToolchainBin(release)
50
+ const swift = path.join(bin, 'swift')
51
+ const version = fs.existsSync(swift)
52
+ ? execFileSync(swift, ['--version'], {
53
+ encoding: 'utf8',
54
+ stdio: ['ignore', 'pipe', 'pipe'],
55
+ })
56
+ : ''
57
+ if (!version.includes(`(${release})`)) {
58
+ const found = version
59
+ ? `found ${version.split('\n')[0]?.trim()} at ${swift}`
60
+ : process.platform === 'darwin'
61
+ ? `found no ${release}.xctoolchain in ~/Library/Developer/Toolchains or /Library/Developer/Toolchains`
62
+ : 'found no swift on PATH'
63
+ throw new Error(
64
+ `peach compiles Swift with the swift.org toolchain ${release} and its wasm SDK; ${found}.\n${swiftInstallSteps(release, wasmSdkChecksum)}`,
65
+ )
66
+ }
67
+ const sdks = execFileSync(swift, ['sdk', 'list'], {
68
+ encoding: 'utf8',
69
+ stdio: ['ignore', 'pipe', 'pipe'],
70
+ })
71
+ if (!sdks.split('\n').some((line) => line.trim() === `${release}_wasm`)) {
72
+ throw new Error(
73
+ `peach compiles Swift with the ${release}_wasm SDK, which ${swift} does not have.\n${swiftInstallSteps(release, wasmSdkChecksum)}`,
74
+ )
75
+ }
76
+ verified.set(release, bin)
77
+ return bin
78
+ }
79
+
80
+ /** the commands that install `release` and its wasm SDK on this host. */
81
+ export function swiftInstallSteps(release: string, wasmSdkChecksum: string): string {
82
+ const version = release.replace(/^swift-/, '').toLowerCase()
83
+ const downloads = `https://download.swift.org/swift-${version}`
84
+ const sdk = `swift sdk install ${downloads}/wasm-sdk/${release}/${release}_wasm.artifactbundle.tar.gz --checksum ${wasmSdkChecksum}`
85
+ if (process.platform === 'darwin') {
86
+ const swift = `~/Library/Developer/Toolchains/${release}.xctoolchain/usr/bin/swift`
87
+ return [
88
+ 'install it:',
89
+ ` curl -fsSLO ${downloads}/xcode/${release}/${release}-osx.pkg`,
90
+ ` installer -pkg ${release}-osx.pkg -target CurrentUserHomeDirectory`,
91
+ ` ${swift} ${sdk.replace(/^swift /, '')}`,
92
+ ].join('\n')
93
+ }
94
+ const platform = `debian12${process.arch === 'arm64' ? '-aarch64' : ''}`
95
+ const name = `${release}-${platform}`
96
+ return [
97
+ 'install it (Debian 12 shown; other distributions: https://www.swift.org/install/linux/):',
98
+ ` curl -fsSL ${downloads}/${platform}/${release}/${name}.tar.gz | tar -xz -C /opt`,
99
+ ` export PATH=/opt/${name}/usr/bin:$PATH`,
100
+ ` ${sdk}`,
101
+ ].join('\n')
102
+ }