peachsim 0.1.1667 → 0.1.1674

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 (204) hide show
  1. package/README.md +1 -1
  2. package/cli/bridge-flow-runner.ts +4 -1
  3. package/cli/commands/coverage-swift.ts +291 -0
  4. package/cli/commands/coverage.ts +168 -24
  5. package/cli/commands/diagnose.ts +1 -19
  6. package/cli/commands/inspect/settling.ts +37 -4
  7. package/cli/commands/react.ts +3 -18
  8. package/cli/commands/screenshot.ts +1 -1
  9. package/cli/commands/screenshots-capture.ts +1 -1
  10. package/cli/drivers/playwright-provisioning.ts +1 -4
  11. package/cli/drivers/playwright.ts +15 -1
  12. package/cli/scene-video.ts +1 -1
  13. package/cli/ui.ts +20 -0
  14. package/cli/ws-bridge.ts +7 -36
  15. package/detox/frame-identity.cjs +21 -0
  16. package/detox/frame-identity.d.cts +6 -0
  17. package/detox/index.ts +39 -33
  18. package/detox/jest-environment.cjs +4 -1
  19. package/detox/jest-setup-after-env.cjs +0 -4
  20. package/detox/navigation-lifecycle.ts +2 -2
  21. package/detox/proof-observer.ts +126 -0
  22. package/dist-lib/agent-daemon-client.cjs +29 -1
  23. package/dist-lib/agent-events.cjs +1 -1
  24. package/dist-lib/attached-projects.cjs +10 -1
  25. package/dist-lib/auth/shared-session.cjs +1 -1
  26. package/dist-lib/backend-origin.cjs +1 -1
  27. package/dist-lib/beta.cjs +1 -1
  28. package/dist-lib/beta.mjs +1 -1
  29. package/dist-lib/bridge-constants.cjs +1 -1
  30. package/dist-lib/bridge-contract-input.cjs +1 -1
  31. package/dist-lib/bridge-contract-input.mjs +1 -1
  32. package/dist-lib/bridge-contract.cjs +1 -1
  33. package/dist-lib/bridge-contract.mjs +1 -1
  34. package/dist-lib/bundle-channel.cjs +557 -158
  35. package/dist-lib/capture-contract.cjs +1 -1
  36. package/dist-lib/capture-contract.mjs +1 -1
  37. package/dist-lib/cloud-contract.cjs +1 -1
  38. package/dist-lib/cloud-contract.mjs +1 -1
  39. package/dist-lib/cloud-test-args.cjs +1 -1
  40. package/dist-lib/cloud-test-args.mjs +1 -1
  41. package/dist-lib/cloud.cjs +1 -1
  42. package/dist-lib/cloud.mjs +1 -1
  43. package/dist-lib/config.cjs +1 -1
  44. package/dist-lib/config.mjs +1 -1
  45. package/dist-lib/detox/index.cjs +5098 -7344
  46. package/dist-lib/detox/jest-environment.cjs +4 -1
  47. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  48. package/dist-lib/expo-swift-bundle.cjs +602 -152
  49. package/dist-lib/expo-swift-metadata.cjs +1 -1
  50. package/dist-lib/expo-swift-metadata.mjs +1 -1
  51. package/dist-lib/home-paths.cjs +1 -1
  52. package/dist-lib/host/bridge-host.cjs +688 -194
  53. package/dist-lib/host/fetch-proxy-handler.cjs +6 -3
  54. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  55. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  56. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  57. package/dist-lib/host/websocket-proxy.cjs +1 -1
  58. package/dist-lib/index.cjs +247 -11
  59. package/dist-lib/jump-to-source-babel.cjs +1 -1
  60. package/dist-lib/jump-to-source-native.cjs +1 -1
  61. package/dist-lib/kotlin-host.cjs +1 -1
  62. package/dist-lib/menu.cjs +1 -1
  63. package/dist-lib/menu.mjs +1 -1
  64. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  65. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  66. package/dist-lib/metro-production-bundle.cjs +10 -1
  67. package/dist-lib/metro-production-bundle.mjs +12 -1
  68. package/dist-lib/metro.cjs +155 -5
  69. package/dist-lib/native-app-identity-project.cjs +43 -5
  70. package/dist-lib/native-app-identity-project.mjs +43 -5
  71. package/dist-lib/native-app-identity.cjs +1 -1
  72. package/dist-lib/native-app-identity.mjs +1 -1
  73. package/dist-lib/native-firebase-metadata.cjs +1 -1
  74. package/dist-lib/native-firebase-metadata.mjs +1 -1
  75. package/dist-lib/plist.cjs +1 -1
  76. package/dist-lib/plist.mjs +1 -1
  77. package/dist-lib/profiles.cjs +21 -1
  78. package/dist-lib/public-brand.cjs +1 -1
  79. package/dist-lib/public-origins-lib-esm.json +73 -27
  80. package/dist-lib/public-origins-lib-static.json +1 -1
  81. package/dist-lib/public-origins-lib.json +563 -183
  82. package/dist-lib/react-native-host-modules.cjs +1 -1
  83. package/dist-lib/react-native-host-modules.mjs +1 -1
  84. package/dist-lib/reap-browser.cjs +964 -0
  85. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  86. package/dist-lib/sdk.cjs +38 -5
  87. package/dist-lib/sdk.mjs +38 -5
  88. package/dist-lib/skills.cjs +1031 -530
  89. package/dist-lib/swift-compile.cjs +298 -86
  90. package/dist-lib/swift-compile.mjs +298 -86
  91. package/dist-lib/swift-package.cjs +53 -4
  92. package/dist-lib/swift-package.mjs +52 -4
  93. package/dist-lib/swift-submit.cjs +2 -2
  94. package/dist-lib/swift-submit.mjs +2 -2
  95. package/dist-lib/swift-toolchain.cjs +25 -44
  96. package/dist-lib/swift.cjs +1 -1
  97. package/dist-lib/vite-swift.cjs +603 -114
  98. package/dist-lib/vite.cjs +65 -3
  99. package/dist-lib/worklet-executable.cjs +1 -1
  100. package/dist-lib/worklet-executable.mjs +1 -1
  101. package/dist-types/packages/peach-engine/src/engine/clipboardContract.d.ts +7 -0
  102. package/dist-types/packages/peach-engine/src/engine/glass-material.d.ts +1 -1
  103. package/dist-types/packages/peach-engine/src/engine/image-loader.d.ts +2 -0
  104. package/dist-types/packages/peach-engine/src/engine/inspect-outline.d.ts +2 -1
  105. package/dist-types/packages/peach-engine/src/engine/liquid-glass.d.ts +1 -0
  106. package/dist-types/packages/peach-engine/src/engine/paint-boundary.d.ts +4 -1
  107. package/dist-types/packages/peach-engine/src/render-worker/host-service-protocol.d.ts +7 -0
  108. package/dist-types/packages/peach-engine/src/render-worker/worklet-runtime-kind.d.ts +24 -0
  109. package/dist-types/packages/peach-engine/src/render-worker/worklet-runtime.d.ts +4 -2
  110. package/dist-types/packages/peach-engine/src/rolldown-bundle-inventory.d.ts +1 -1
  111. package/dist-types/packages/peach-engine/src/settings/devices.d.ts +1 -0
  112. package/dist-types/packages/peach-globals/src/clipboardBridgeContract.d.ts +18 -0
  113. package/dist-types/packages/peach-globals/src/compositorBridgeContract.d.ts +10 -1
  114. package/dist-types/packages/peach-globals/src/index.d.ts +2 -2
  115. package/dist-types/packages/peach-globals/src/nodeContract.d.ts +1 -0
  116. package/dist-types/packages/peach-kit/src/capabilities.d.ts +1 -0
  117. package/package.json +1 -1
  118. package/runtime-companion.json +1 -1
  119. package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFString.h +2 -0
  120. package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h +54 -0
  121. package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h +23 -4
  122. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCDynamicStore.h +439 -0
  123. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCDynamicStoreCopySpecific.h +216 -0
  124. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCDynamicStoreKey.h +267 -0
  125. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCNetwork.h +204 -0
  126. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCNetworkConfiguration.h +1393 -0
  127. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCNetworkConnection.h +568 -0
  128. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCNetworkReachability.h +369 -0
  129. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCPreferences.h +473 -0
  130. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCPreferencesPath.h +179 -0
  131. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCPreferencesSetSpecific.h +95 -0
  132. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCSchemaDefinitions.h +2395 -0
  133. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SystemConfiguration.h +184 -0
  134. package/sdk/ios/usr/include/_ctype.h +388 -0
  135. package/sdk/ios/usr/include/_inttypes.h +296 -0
  136. package/sdk/ios/usr/include/_locale.h +83 -0
  137. package/sdk/ios/usr/include/_locale_posix2008.h +65 -0
  138. package/sdk/ios/usr/include/_time.h +207 -0
  139. package/sdk/ios/usr/include/ctype.h +70 -0
  140. package/sdk/ios/usr/include/dispatch/dispatch.h +69 -6
  141. package/sdk/ios/usr/include/inttypes.h +35 -0
  142. package/sdk/ios/usr/include/libkern/OSByteOrder.h +315 -0
  143. package/sdk/ios/usr/include/libkern/machine/OSByteOrder.h +147 -0
  144. package/sdk/ios/usr/include/locale.h +59 -0
  145. package/sdk/ios/usr/include/runetype.h +118 -0
  146. package/sdk/ios/usr/include/setjmp.h +99 -0
  147. package/sdk/ios/usr/include/sys/_types/_clock_t.h +32 -0
  148. package/sdk/ios/usr/include/sys/_types/_ct_rune_t.h +33 -0
  149. package/sdk/ios/usr/include/sys/_types/_rune_t.h +32 -0
  150. package/sdk/ios/usr/include/sys/_types/_time_t.h +32 -0
  151. package/sdk/ios/usr/include/sys/_types/_wint_t.h +33 -0
  152. package/sdk/ios/usr/include/sys/cdefs.h +2 -0
  153. package/sdk/ios/usr/include/time.h +67 -2
  154. package/src/bridge-contract.ts +42 -0
  155. package/src/chromium-admission.ts +196 -0
  156. package/src/host/bridge-host.ts +6 -43
  157. package/src/host/rolldown-bundle-forward.ts +4 -1
  158. package/src/launch-deadline.ts +74 -0
  159. package/src/nitro-adapter.lock.json +3 -3
  160. package/src/profiles.ts +21 -0
  161. package/src/react-native-coverage/capability-reference-resolution.ts +402 -0
  162. package/src/react-native-coverage/capability-source-references.ts +1296 -0
  163. package/src/react-native-coverage/native-typescript-parser.ts +74 -0
  164. package/src/react-native-coverage/project-aliases.ts +207 -0
  165. package/src/react-native-coverage/verified-reach.ts +47 -0
  166. package/src/reap-browser.ts +1019 -0
  167. package/src/skills/builtin/a11y-review.ts +1 -1
  168. package/src/skills/builtin/perf-profile.ts +1 -1
  169. package/src/skills/builtin/screenshot-all.ts +1 -1
  170. package/src/skills/builtin/visual-diff.ts +1 -1
  171. package/src/swift-compile.ts +109 -57
  172. package/src/swift-coverage/indexdump.ts +80 -0
  173. package/src/swift-coverage/indexing.ts +147 -0
  174. package/src/swift-coverage/package.ts +230 -0
  175. package/src/swift-coverage/provenance.ts +47 -0
  176. package/src/swift-coverage/reader.ts +81 -0
  177. package/src/swift-coverage/source.ts +252 -0
  178. package/src/swift-coverage/types.ts +58 -0
  179. package/src/swift-coverage/xcode-assets.ts +175 -0
  180. package/src/swift-coverage/xcode-bridging.ts +160 -0
  181. package/src/swift-coverage/xcode-packages.ts +251 -0
  182. package/src/swift-coverage/xcode-strings.ts +78 -0
  183. package/src/swift-coverage/xcode.ts +656 -0
  184. package/src/swift-distribution.lock.json +8 -8
  185. package/src/swift-host.ts +21 -1
  186. package/src/swift-objc-compile.ts +7 -3
  187. package/src/swift-objc-import.ts +191 -27
  188. package/src/swift-objc-metadata.ts +2 -2
  189. package/src/swift-objc-standin.ts +9 -2
  190. package/src/swift-package-manifest.ts +134 -13
  191. package/src/swift-package.ts +69 -4
  192. package/src/swift-standins.ts +4 -1
  193. package/src/swift-submit.ts +2 -1
  194. package/src/swift-toolchain.ts +36 -61
  195. package/src/worker-system-chunks.ts +3 -10
  196. package/src/xcode-project.ts +5 -5
  197. package/detox/attempt-events.cjs +0 -914
  198. package/detox/attempt-events.d.cts +0 -113
  199. package/detox/motion-change.cjs +0 -524
  200. package/detox/motion-change.d.cts +0 -140
  201. package/detox/motion-leg-starts.cjs +0 -20
  202. package/detox/motion-leg-starts.d.cts +0 -8
  203. package/detox/proof-frame.cjs +0 -190
  204. package/detox/record-block-execution.cjs +0 -78
@@ -1,4 +1,4 @@
1
- /*! peach v0.1.1667 | (c) 2026 Tamagui LLC | Proprietary; see LICENSE */
1
+ /*! peach v0.1.1674 | (c) 2026 Tamagui LLC | Proprietary; see LICENSE */
2
2
  var __defProp = Object.defineProperty;
3
3
  var __export = (target, all) => {
4
4
  for (var name2 in all)
@@ -7478,7 +7478,17 @@ function sourceSwiftCheckout() {
7478
7478
  }
7479
7479
  function swiftSdkOptions() {
7480
7480
  const directory = process.env.PEACH_SWIFT_SDKS_PATH;
7481
- return directory ? ["--swift-sdks-path", path4.resolve(directory)] : [];
7481
+ if (directory) return ["--swift-sdks-path", path4.resolve(directory)];
7482
+ if (scratch && process.platform === "linux") {
7483
+ const config = process.env.XDG_CONFIG_HOME;
7484
+ if (config !== void 0 && !path4.isAbsolute(config))
7485
+ throw new Error("XDG_CONFIG_HOME must be an absolute path");
7486
+ return [
7487
+ "--swift-sdks-path",
7488
+ config === void 0 ? path4.join(os.userInfo().homedir, ".swiftpm", "swift-sdks") : path4.join(config, "swiftpm", "swift-sdks")
7489
+ ];
7490
+ }
7491
+ return [];
7482
7492
  }
7483
7493
  var SWIFT_HOST_COMPILER_RELEASE = "swift-6.4.0-RELEASE-custom-0d775d32d7c74eae";
7484
7494
  var SWIFT_HOST_COMPILER_ID = "0d775d32d7c74eae";
@@ -7537,10 +7547,16 @@ function peachHome() {
7537
7547
  return override ? path4.resolve(override) : path4.join(os.homedir(), ".peach");
7538
7548
  }
7539
7549
  var scratch;
7540
- var swiftHome;
7541
7550
  function swiftEnvironment(base = process.env) {
7542
7551
  if (!scratch) return base;
7543
- return swiftHome ? { ...base, TMPDIR: scratch, HOME: swiftHome } : { ...base, TMPDIR: scratch };
7552
+ return {
7553
+ ...base,
7554
+ TMPDIR: scratch.directory,
7555
+ XDG_CONFIG_HOME: path4.join(scratch.home, ".config"),
7556
+ XDG_CACHE_HOME: path4.join(scratch.home, ".cache"),
7557
+ XDG_DATA_HOME: path4.join(scratch.home, ".local", "share"),
7558
+ ...process.platform === "linux" ? { HOME: scratch.home } : {}
7559
+ };
7544
7560
  }
7545
7561
  function swiftSourceSdk(root) {
7546
7562
  const pin = JSON.parse(
@@ -8450,6 +8466,7 @@ function swiftObjCImports(graphs, options) {
8450
8466
  const categories = /* @__PURE__ */ new Map();
8451
8467
  const functions = /* @__PURE__ */ new Map();
8452
8468
  const typedefs = /* @__PURE__ */ new Map();
8469
+ const wrappedTypedefs = /* @__PURE__ */ new Map();
8453
8470
  const visit3 = (node) => {
8454
8471
  if (!record(node)) return;
8455
8472
  if (node.kind === "ObjCInterfaceDecl" && typeof node.name === "string" && selected.has(node.name)) {
@@ -8471,6 +8488,9 @@ function swiftObjCImports(graphs, options) {
8471
8488
  if (node.kind === "TypedefDecl" && typeof node.name === "string" && record(node.type)) {
8472
8489
  const canonical2 = node.type.desugaredQualType ?? node.type.qualType;
8473
8490
  if (typeof canonical2 === "string") typedefs.set(node.name, canonical2);
8491
+ if (nodes(node.inner).some((attribute) => attribute.kind === "SwiftNewTypeAttr")) {
8492
+ wrappedTypedefs.set(node.name, [...wrappedTypedefs.get(node.name) ?? [], node]);
8493
+ }
8474
8494
  }
8475
8495
  for (const child of nodes(node.inner)) visit3(child);
8476
8496
  };
@@ -8478,14 +8498,29 @@ function swiftObjCImports(graphs, options) {
8478
8498
  fail("declarations", "expected a complete Clang translation unit AST");
8479
8499
  visit3(options.clangAST);
8480
8500
  const symbols = /* @__PURE__ */ new Map();
8501
+ const seenSymbols = /* @__PURE__ */ new Set();
8481
8502
  for (const graph of graphs) {
8482
8503
  if (graph.module.name !== options.module)
8483
8504
  fail("declarations", `symbol graph belongs to ${graph.module.name}`);
8484
8505
  for (const symbol of graph.symbols) {
8485
- const previous = symbols.get(symbol.identifier.precise);
8486
- if (previous && JSON.stringify(previous) !== JSON.stringify(symbol))
8487
- fail(symbol.identifier.precise, "ambiguous imported declaration");
8488
- symbols.set(symbol.identifier.precise, symbol);
8506
+ if (symbol.availability?.some(
8507
+ (entry) => entry.isUnconditionallyUnavailable && (!entry.domain || entry.domain === "Swift" || entry.domain === "iOS")
8508
+ ))
8509
+ continue;
8510
+ const key = JSON.stringify([
8511
+ symbol.identifier.precise,
8512
+ symbol.kind.identifier,
8513
+ symbol.pathComponents,
8514
+ symbol.declarationFragments,
8515
+ symbol.functionSignature,
8516
+ symbol.accessLevel,
8517
+ symbol.availability
8518
+ ]);
8519
+ if (seenSymbols.has(key)) continue;
8520
+ seenSymbols.add(key);
8521
+ const overloads = symbols.get(symbol.identifier.precise) ?? [];
8522
+ overloads.push(symbol);
8523
+ symbols.set(symbol.identifier.precise, overloads);
8489
8524
  }
8490
8525
  }
8491
8526
  const classes = [];
@@ -8500,7 +8535,10 @@ function swiftObjCImports(graphs, options) {
8500
8535
  types.set(name2, nativeName);
8501
8536
  }
8502
8537
  for (const nativeName of [...selected].sort()) {
8503
- const symbol = symbols.get(`c:objc(cs)${nativeName}`);
8538
+ const candidates = symbols.get(`c:objc(cs)${nativeName}`);
8539
+ if (candidates && candidates.length !== 1)
8540
+ fail(nativeName, "ambiguous imported class declaration");
8541
+ const symbol = candidates?.[0];
8504
8542
  const name2 = symbol?.pathComponents[0];
8505
8543
  if (!symbol || symbol.kind.identifier !== "swift.class" || !name2 || !identifier(name2))
8506
8544
  fail(nativeName, "missing Swift-imported class declaration");
@@ -8515,6 +8553,70 @@ function swiftObjCImports(graphs, options) {
8515
8553
  types.set(name2, nativeName);
8516
8554
  classes.push({ name: name2, nativeName });
8517
8555
  }
8556
+ const wrapperMembers = /* @__PURE__ */ new Map();
8557
+ const wrapperConformances = /* @__PURE__ */ new Map();
8558
+ for (const graph of graphs)
8559
+ for (const edge of graph.relationships)
8560
+ if (edge.kind === "conformsTo" && edge.source.includes("@T@")) {
8561
+ const protocols = wrapperConformances.get(edge.source) ?? /* @__PURE__ */ new Set();
8562
+ protocols.add(edge.target);
8563
+ wrapperConformances.set(edge.source, protocols);
8564
+ }
8565
+ for (const candidates of symbols.values())
8566
+ for (const member of candidates)
8567
+ if (member.pathComponents.length === 2 && ["init(rawValue:)", "init(_:)"].includes(member.pathComponents[1])) {
8568
+ const owner = member.pathComponents[0];
8569
+ wrapperMembers.set(owner, [...wrapperMembers.get(owner) ?? [], member]);
8570
+ }
8571
+ const stringWrappers = /* @__PURE__ */ new Map();
8572
+ const wrapperSymbols = [...symbols].filter(
8573
+ ([usr, candidates]) => usr.includes("@T@") && candidates[0]?.kind.identifier === "swift.struct"
8574
+ ).sort(([left], [right]) => left.localeCompare(right));
8575
+ for (const [usr, candidates] of wrapperSymbols) {
8576
+ const nativeName = /^c:.*@T@([A-Za-z_]\w*)$/.exec(usr)?.[1];
8577
+ if (!nativeName) continue;
8578
+ const originals = wrappedTypedefs.get(nativeName);
8579
+ const declaration = originals?.[0];
8580
+ if (!declaration || !record(declaration.type)) continue;
8581
+ const original = declaration.type.desugaredQualType ?? declaration.type.qualType;
8582
+ if (typeof original !== "string" || original.replace(/\s/g, "") !== "NSString*")
8583
+ continue;
8584
+ const symbol = candidates[0];
8585
+ const name2 = symbol.pathComponents[0];
8586
+ if (candidates.length !== 1 || originals?.length !== 1 || symbol.pathComponents.length !== 1 || !name2 || !identifier(name2) || types.has(name2) || stringWrappers.has(name2) || symbol.accessLevel !== "public" || text2(symbol.declarationFragments ?? []).trim() !== `struct ${name2}` || symbol.availability?.length)
8587
+ fail(usr, "typed string wrapper identity is unqualified");
8588
+ if (!["s:SY", "s:SH", "s:SQ", "s:s8SendableP"].every(
8589
+ (protocol) => wrapperConformances.get(usr)?.has(protocol)
8590
+ ))
8591
+ fail(usr, "typed string wrapper conformances are unqualified");
8592
+ const members = wrapperMembers.get(name2) ?? [];
8593
+ const initializers = members.filter(
8594
+ (member) => member.pathComponents[1] === "init(rawValue:)"
8595
+ );
8596
+ if (initializers.length !== 1 || initializers[0].kind.identifier !== "swift.init" || initializers[0].accessLevel !== "public" || text2(initializers[0].declarationFragments ?? []).trim() !== "init(rawValue: String)" || !initializers[0].declarationFragments?.some(
8597
+ (part) => part.kind === "typeIdentifier" && part.preciseIdentifier === "s:SS"
8598
+ ))
8599
+ fail(usr, "typed string wrapper raw initializer is unqualified");
8600
+ const unlabelled = members.filter((member) => member.pathComponents[1] === "init(_:)");
8601
+ if (unlabelled.length > 1 || unlabelled.length === 1 && (unlabelled[0].kind.identifier !== "swift.init" || unlabelled[0].accessLevel !== "public" || text2(unlabelled[0].declarationFragments ?? []).trim() !== "init(_ rawValue: String)" || !unlabelled[0].declarationFragments?.some(
8602
+ (part) => part.kind === "typeIdentifier" && part.preciseIdentifier === "s:SS"
8603
+ )))
8604
+ fail(usr, "typed string wrapper unlabeled initializer is unqualified");
8605
+ stringWrappers.set(
8606
+ name2,
8607
+ [
8608
+ `public struct ${swiftName(name2)}: Swift.RawRepresentable, Swift.Hashable, Swift.Equatable, Swift._SwiftNewtypeWrapper, Swift._ObjectiveCBridgeable, Swift.Sendable {`,
8609
+ " public typealias RawValue = Swift.String",
8610
+ " public typealias _ObjectiveCType = Foundation.NSString",
8611
+ " private let _rawValue: Swift.String",
8612
+ " public var rawValue: Swift.String { _rawValue }",
8613
+ " public init(rawValue: Swift.String) { _rawValue = rawValue }",
8614
+ ...unlabelled.length ? [" public init(_ rawValue: Swift.String) { _rawValue = rawValue }"] : [],
8615
+ "}",
8616
+ ""
8617
+ ].join("\n")
8618
+ );
8619
+ }
8518
8620
  const type = (parts, where) => {
8519
8621
  const written = text2(parts).trim();
8520
8622
  const optional = /[?!]$/.test(written);
@@ -8537,7 +8639,7 @@ function swiftObjCImports(graphs, options) {
8537
8639
  Double: "double"
8538
8640
  };
8539
8641
  if (!optional && primitive[written] && !parts.some(
8540
- (part) => part.preciseIdentifier?.startsWith("c:") || part.preciseIdentifier && symbols.get(part.preciseIdentifier)?.kind.identifier === "swift.class"
8642
+ (part) => part.preciseIdentifier?.startsWith("c:") || part.preciseIdentifier && symbols.get(part.preciseIdentifier)?.[0]?.kind.identifier === "swift.class"
8541
8643
  ))
8542
8644
  return {
8543
8645
  swift: `Swift.${written === "()" ? "Void" : written}`,
@@ -8549,7 +8651,7 @@ function swiftObjCImports(graphs, options) {
8549
8651
  const identifiers = parts.filter((part) => part.kind === "typeIdentifier");
8550
8652
  const id = identifiers.length === 1 ? identifiers[0]?.preciseIdentifier : void 0;
8551
8653
  const native = id && nativeClass(id);
8552
- const swiftClass = id ? symbols.get(id) : void 0;
8654
+ const swiftClass = id ? symbols.get(id)?.[0] : void 0;
8553
8655
  const resolved = native ? names.get(native) : swiftClass?.kind.identifier === "swift.class" && swiftClass.pathComponents.length === 1 && swiftClass.pathComponents[0] === spelling && types.has(spelling) ? spelling : void 0;
8554
8656
  if (!resolved || identifiers[0]?.spelling !== spelling || spelling !== resolved && spelling !== native)
8555
8657
  return fail(
@@ -8610,7 +8712,8 @@ function swiftObjCImports(graphs, options) {
8610
8712
  );
8611
8713
  };
8612
8714
  const membersByClass = /* @__PURE__ */ new Map();
8613
- for (const symbol of symbols.values()) {
8715
+ const importedSymbols = [...symbols.values()].flat();
8716
+ for (const symbol of importedSymbols) {
8614
8717
  const owner = /^c:objc\(cs\)([A-Za-z_]\w*)\(/.exec(symbol.identifier.precise)?.[1];
8615
8718
  if (owner && selected.has(owner)) {
8616
8719
  const members = membersByClass.get(owner);
@@ -8737,27 +8840,40 @@ function swiftObjCImports(graphs, options) {
8737
8840
  (n) => nodes(n.inner)
8738
8841
  );
8739
8842
  for (const member of members) {
8740
- if (member.kind === "ObjCMethodDecl" && typeof member.name === "string" && (/^init(?:$|[^a-z])/.test(member.name.replace(/^_+/, "")) || nodes(member.inner).some(
8843
+ if (member.kind === "ObjCMethodDecl" && typeof member.name === "string" && member.name !== "init" && (/^init(?:$|[^a-z])/.test(member.name.replace(/^_+/, "")) || nodes(member.inner).some(
8741
8844
  (attribute) => attribute.kind === "NSConsumesSelfAttr" || attribute.kind === "ObjCDesignatedInitializerAttr"
8742
- )))
8845
+ )) && !nodes(member.inner).some((attribute) => attribute.kind === "UnavailableAttr"))
8743
8846
  fail(
8744
8847
  `${nativeName}.${member.name}`,
8745
8848
  "explicit or designated initialization is unqualified"
8746
8849
  );
8747
- if (member.variadic === true)
8748
- fail(`${nativeName}.${member.name}`, "variadic methods are unqualified");
8749
- }
8750
- const constructor = thunk(
8751
- `${nativeName}:new`,
8752
- raw2,
8753
- [],
8754
- null,
8755
- `[[${nativeName} alloc] init]`
8756
- );
8850
+ }
8757
8851
  const body = [
8758
- `public required init(_objcRetained: Swift.UnsafeMutableRawPointer) { precondition(Self.self == ${swiftName(name2)}.self, "Swift subclass construction is unqualified"); super.init(_objcRetained: _objcRetained) }`,
8759
- `public init() { precondition(Self.self == ${swiftName(name2)}.self, "Swift subclass construction is unqualified"); super.init(_objcRetained: ${constructor}()!) }`
8852
+ `public required init(_objcRetained: Swift.UnsafeMutableRawPointer) { precondition(Self.self == ${swiftName(name2)}.self, "Swift subclass construction is unqualified"); super.init(_objcRetained: _objcRetained) }`
8760
8853
  ];
8854
+ const defaultInitializer = members.find(
8855
+ (member) => member.kind === "ObjCMethodDecl" && member.instance === true && member.name === "init"
8856
+ );
8857
+ const importedInitializer = symbols.get(`c:objc(cs)${nativeName}(im)init`);
8858
+ const initializerSpelling = importedInitializer?.[0] ? text2(importedInitializer[0].declarationFragments ?? []).trim() : "init()";
8859
+ if (!/^init[?!]?\(\)$/.test(initializerSpelling))
8860
+ fail(`${nativeName}.init`, "default initializer signature is unqualified");
8861
+ if (!defaultInitializer || !nodes(defaultInitializer.inner).some(
8862
+ (attribute) => attribute.kind === "UnavailableAttr"
8863
+ )) {
8864
+ if (defaultInitializer && (importedInitializer?.length !== 1 || importedInitializer[0]?.kind.identifier !== "swift.init"))
8865
+ fail(`${nativeName}.init`, "missing Swift-imported default initializer");
8866
+ const constructor = thunk(
8867
+ `${nativeName}:new`,
8868
+ raw2,
8869
+ [],
8870
+ null,
8871
+ `[[${nativeName} alloc] init]`
8872
+ );
8873
+ body.push(
8874
+ `public ${initializerSpelling} { precondition(Self.self == ${swiftName(name2)}.self, "Swift subclass construction is unqualified"); ${/^init[?!]/.test(initializerSpelling) ? `guard let _peer = ${constructor}() else { return nil }; super.init(_objcRetained: _peer)` : `super.init(_objcRetained: ${constructor}()!)`} }`
8875
+ );
8876
+ }
8761
8877
  bodies.set(name2, body);
8762
8878
  const prefix = `c:objc(cs)${nativeName}`;
8763
8879
  for (const symbol of membersByClass.get(nativeName) ?? []) {
@@ -8775,16 +8891,19 @@ function swiftObjCImports(graphs, options) {
8775
8891
  (m) => m.kind === (property ? "ObjCPropertyDecl" : "ObjCMethodDecl") && m.name === selector && (property ? m.class !== true === instance : m.instance === instance)
8776
8892
  );
8777
8893
  if (!decl) fail(usr, "member absent from original Clang interface");
8894
+ if (decl.variadic === true)
8895
+ fail(`${nativeName}.${selector}`, "variadic methods are unqualified");
8778
8896
  const parts = symbol.declarationFragments ?? [];
8779
8897
  const written = text2(parts);
8780
8898
  if (symbol.availability?.length || /@|\b(?:optional|nonisolated|isolated|async|throws|rethrows)\b/.test(written))
8781
8899
  fail(usr, "availability and asynchronous or throwing imports are unqualified");
8782
8900
  if (nodes(decl.inner).some(
8783
- (a) => /^(?:Unavailable|SwiftPrivate|SwiftAsync|SwiftError|ObjCRequiresSuper|NSConsumesSelf)Attr$/.test(
8901
+ (a) => /^(?:Unavailable|SwiftPrivate|SwiftAsync|SwiftError|ObjCRequiresSuper)Attr$/.test(
8784
8902
  String(a.kind)
8785
- )
8903
+ ) || a.kind === "NSConsumesSelfAttr" && selector !== "init"
8786
8904
  ))
8787
8905
  fail(usr, "member attributes require a qualified importer path");
8906
+ if (selector === "init" && symbol.kind.identifier === "swift.init") continue;
8788
8907
  const receiver = instance ? "_object" : nativeName;
8789
8908
  const access = symbol.accessLevel === "open" ? "open" : "public";
8790
8909
  const memberName = parts.find((part) => part.kind === "identifier")?.spelling;
@@ -8863,7 +8982,7 @@ function swiftObjCImports(graphs, options) {
8863
8982
  }
8864
8983
  }
8865
8984
  const importedFunctions = [];
8866
- for (const symbol of symbols.values()) {
8985
+ for (const symbol of importedSymbols) {
8867
8986
  if (symbol.kind.identifier !== "swift.func") continue;
8868
8987
  const usr = symbol.identifier.precise;
8869
8988
  const native = /^c:@F@([A-Za-z_]\w*)$/.exec(usr)?.[1];
@@ -8904,7 +9023,7 @@ function swiftObjCImports(graphs, options) {
8904
9023
  `public func ${swiftName(name2)}(${argumentsSwift}) -> ${result.swift} { ${result.c === "void" ? "" : "return "}${local}(${parameters.map((p) => swiftName(p.name)).join(", ")}) }`
8905
9024
  );
8906
9025
  }
8907
- if (!classes.length && !importedFunctions.length)
9026
+ if (!classes.length && !importedFunctions.length && !stringWrappers.size)
8908
9027
  fail("declarations", "no represented original Objective-C classes or C functions");
8909
9028
  const registerFunction = `_peachRegisterObjCImports_${hash(options.module)}`;
8910
9029
  const registration = [
@@ -8917,12 +9036,14 @@ function swiftObjCImports(graphs, options) {
8917
9036
  ""
8918
9037
  ].join("\n");
8919
9038
  const swift = [
8920
- ...classes.length ? ["import Foundation", "import PeachObjC"] : [],
9039
+ ...classes.length || stringWrappers.size ? ["import Foundation"] : [],
9040
+ ...classes.length ? ["import PeachObjC"] : [],
8921
9041
  "",
8922
9042
  ...external,
8923
9043
  "",
8924
9044
  ...importedFunctions,
8925
9045
  "",
9046
+ ...stringWrappers.values(),
8926
9047
  ...classes.flatMap((c) => [
8927
9048
  `open class ${swiftName(c.name)}: PeachObjC._ObjCForeignObject {`,
8928
9049
  ...bodies.get(c.name).map((line) => ` ${line}`),
@@ -8973,6 +9094,8 @@ import { createHash as createHash6 } from "node:crypto";
8973
9094
  import fs3 from "node:fs";
8974
9095
  import path7 from "node:path";
8975
9096
  var NATIVE_GRAPH_SDK_VERSION = "27.1";
9097
+ var WASI_EMULATION = ["_WASI_EMULATED_SIGNAL", "_WASI_EMULATED_MMAN"];
9098
+ var WASI_EMULATION_FLAGS = WASI_EMULATION.map((name2) => `-D${name2}`);
8976
9099
  var NATIVE_GRAPH_INPUTS = {
8977
9100
  sdk: NATIVE_GRAPH_SDK_VERSION,
8978
9101
  settings: "e68503e5e534e9194af5efe8c636ca8b824e2d8237c5f38ec84aa4d155bc8418",
@@ -9189,7 +9312,9 @@ function objcView(surface, toolchainBin, stdlib, cacheDir2, work, original) {
9189
9312
  "-module-cache-path",
9190
9313
  path7.join(cacheDir2, "ios-module-cache"),
9191
9314
  "-minimum-access-level",
9192
- "public",
9315
+ // symbol graphs hide public underscored names at the public threshold.
9316
+ // original clang headers remain the declaration boundary.
9317
+ original ? "internal" : "public",
9193
9318
  "-skip-synthesized-members",
9194
9319
  "-omit-extension-block-symbols",
9195
9320
  "-output-dir",
@@ -9675,6 +9800,51 @@ function splitManifestArguments(source) {
9675
9800
  function swiftTargetModuleName(name2) {
9676
9801
  return name2.replace(/[^A-Za-z0-9_]/g, "_").replace(/^[0-9]/, "_");
9677
9802
  }
9803
+ function clangMacroSetting(macro) {
9804
+ const [name2, ...value] = macro.split("=");
9805
+ return value.length === 0 ? `.define(${JSON.stringify(name2)})` : `.define(${JSON.stringify(name2)}, to: ${JSON.stringify(value.join("="))})`;
9806
+ }
9807
+ var swiftEscapes = {
9808
+ "\\": "\\",
9809
+ '"': '"',
9810
+ "'": "'",
9811
+ n: "\n",
9812
+ r: "\r",
9813
+ t: " "
9814
+ };
9815
+ function settingDefines(call, tool) {
9816
+ const defines = [];
9817
+ for (const open of call.matchAll(new RegExp(`\\b${tool}Settings\\s*:\\s*\\[`, "g"))) {
9818
+ let depth = 1;
9819
+ let index = open.index + open[0].length;
9820
+ const start = index;
9821
+ for (; index < call.length && depth > 0; index++) {
9822
+ const char = call[index];
9823
+ if (char === '"') {
9824
+ for (index++; index < call.length && call[index] !== '"'; index++)
9825
+ if (call[index] === "\\") index++;
9826
+ } else if (char === "[") depth++;
9827
+ else if (char === "]") depth--;
9828
+ }
9829
+ const body = call.slice(start, index - 1);
9830
+ for (const match of body.matchAll(
9831
+ /\.define\(\s*"([A-Za-z_][A-Za-z0-9_]*)"\s*(?:,\s*to:\s*"((?:[^"\\]|\\.)*)"\s*)?\)/g
9832
+ )) {
9833
+ const name2 = match[1];
9834
+ defines.push(
9835
+ match[2] === void 0 ? name2 : `${name2}=${match[2].replace(/\\(.)/g, (_, escape) => {
9836
+ const value = swiftEscapes[escape];
9837
+ if (value === void 0)
9838
+ throw new Error(
9839
+ `Unsupported escape \\${escape} in the value of macro ${name2}`
9840
+ );
9841
+ return value;
9842
+ })}`
9843
+ );
9844
+ }
9845
+ }
9846
+ return defines;
9847
+ }
9678
9848
  function swiftManifestTargets(manifest, resourcePaths = []) {
9679
9849
  const implicitResources = swiftImplicitResourcePaths(resourcePaths);
9680
9850
  const targets = [];
@@ -9702,9 +9872,9 @@ function swiftManifestTargets(manifest, resourcePaths = []) {
9702
9872
  const cxxInterop = /\.interoperabilityMode\(\s*\.Cxx\s*\)/.test(
9703
9873
  call.replace(/"(?:\\.|[^"\\])*"/g, "")
9704
9874
  );
9705
- const defines = [
9706
- ...call.matchAll(/\.define\(\s*"([A-Za-z_][A-Za-z0-9_]*)"\s*\)/g)
9707
- ].map((match) => match[1]);
9875
+ const defines = settingDefines(call, "swift").map((define) => define.split("=")[0]);
9876
+ const cDefines = settingDefines(call, "c");
9877
+ const cxxDefines = settingDefines(call, "cxx");
9708
9878
  const linkedLibraries = [...call.matchAll(/\.linkedLibrary\(\s*"([^"]+)"\s*\)/g)].map(
9709
9879
  (match) => match[1]
9710
9880
  );
@@ -9747,6 +9917,8 @@ function swiftManifestTargets(manifest, resourcePaths = []) {
9747
9917
  mainActorIsolation,
9748
9918
  ...cxxInterop ? { cxxInterop: true } : {},
9749
9919
  ...defines.length === 0 ? {} : { defines },
9920
+ ...cDefines.length === 0 ? {} : { cDefines },
9921
+ ...cxxDefines.length === 0 ? {} : { cxxDefines },
9750
9922
  ...linkedLibraries.length === 0 ? {} : { linkedLibraries },
9751
9923
  resources,
9752
9924
  ...dependencies.length === 0 ? {} : { dependencies },
@@ -10665,7 +10837,7 @@ var EXECUTABLE_LINK_FLAGS = ` "-Xclang-linker", "-O0",
10665
10837
  `;
10666
10838
  var REACTOR_FLAG = '"-Xclang-linker", "-mexec-model=reactor",\n';
10667
10839
  var MULTI_MANIFEST_VERSION = 40;
10668
- var compilerSourceDigest = true ? "baf55512a114f4eec85d80685c9e0f04d08ac1ad34d8c18745c233b3d7827025" : swiftCompilerSourceDigest(import.meta.dirname);
10840
+ var compilerSourceDigest = true ? "9c8bf514e9d972c32ef441bda4effae79610e2c5add1faca769349803321528f" : swiftCompilerSourceDigest(import.meta.dirname);
10669
10841
  function swiftArtifactHash(input, release, moduleRoot) {
10670
10842
  const hash2 = createHash9("sha256");
10671
10843
  hash2.update(`swift-compile
@@ -10782,6 +10954,7 @@ function emitSwiftPackageManifest(args) {
10782
10954
  const linkedNativeModules = [...args.native?.entries() ?? []].flatMap(
10783
10955
  ([name2, value]) => value.clang ? [name2] : []
10784
10956
  );
10957
+ const macroSettings = (values) => (values ?? []).map((value) => ` ${clangMacroSetting(value)},`).join("");
10785
10958
  const stanza = (target) => {
10786
10959
  if (target.systemLibrary)
10787
10960
  return ` .systemLibrary(name: ${JSON.stringify(target.name)}, path: ${JSON.stringify(target.path)}),`;
@@ -10858,10 +11031,15 @@ function emitSwiftPackageManifest(args) {
10858
11031
  .unsafeFlags(["-Xlinker", "--strip-all"], .when(configuration: .release)),
10859
11032
  ]` : librarySettings.length > 0 ? `,
10860
11033
  linkerSettings: [${librarySettings.join(", ")}]` : "";
11034
+ const cDefines = macroSettings(target.cDefines);
11035
+ const cxxDefines = macroSettings(target.cxxDefines);
10861
11036
  const nativeSettings = native?.clang ? [
10862
- `cSettings: [.unsafeFlags(${JSON.stringify([...args.objcExports?.flags ?? args.nativeFlags ?? [], ...native.clang.flags])})]`,
10863
- `cxxSettings: [${defines} .unsafeFlags(${JSON.stringify(["-fno-cxx-modules", ...args.objcExports?.flags ?? args.nativeFlags ?? [], ...native.clang.cxxFlags])})]`
10864
- ].join(", ") : `${args.objcExports ? `cSettings: [.unsafeFlags(${JSON.stringify(args.objcExports.flags)})], ` : ""}cxxSettings: [${defines} .unsafeFlags(["-fno-cxx-modules"])]`;
11037
+ `cSettings: [${cDefines} .unsafeFlags(${JSON.stringify([...args.objcExports?.flags ?? args.nativeFlags ?? [], ...native.clang.flags])})]`,
11038
+ `cxxSettings: [${cxxDefines} .unsafeFlags(${JSON.stringify(["-fno-cxx-modules", ...args.objcExports?.flags ?? args.nativeFlags ?? [], ...native.clang.cxxFlags])})]`
11039
+ ].join(", ") : [
11040
+ `cSettings: [${cDefines} .unsafeFlags(${JSON.stringify([...args.objcExports?.flags ?? args.nativeFlags ?? [], ...native?.flags ?? []])})]`,
11041
+ `cxxSettings: [${cxxDefines} .unsafeFlags(${JSON.stringify(["-fno-cxx-modules", ...args.objcExports?.flags ?? args.nativeFlags ?? [], ...native?.cxxFlags ?? []])})]`
11042
+ ].join(", ");
10865
11043
  return [
10866
11044
  ` ${kind}(`,
10867
11045
  ` name: "${target.name}",`,
@@ -10871,7 +11049,7 @@ function emitSwiftPackageManifest(args) {
10871
11049
  ...native?.clang ? [
10872
11050
  ` sources: ${JSON.stringify(native.clang.sources.map((source) => path11.posix.join(native.path, source)))},`,
10873
11051
  ` publicHeadersPath: ${JSON.stringify(path11.posix.dirname(native.clang.modulemap))},`
10874
- ] : [],
11052
+ ] : native?.flags ? [` sources: ${JSON.stringify(native.sources)},`] : [],
10875
11053
  // the native backend supplies dependency module maps without their
10876
11054
  // compiled modules. textual c++ includes keep those dependencies usable.
10877
11055
  ` ${clang ? nativeSettings : swiftSettings}${link}`,
@@ -10897,24 +11075,26 @@ function emitSwiftPackageManifest(args) {
10897
11075
  ' publicHeadersPath: "include",',
10898
11076
  ` cSettings: [.unsafeFlags(${JSON.stringify([...args.objcExports.flags.filter((flag) => flag !== "-fobjc-arc"), "-fno-objc-arc", "-Xclang", "-disable-objc-default-synthesize-properties"])})]),`
10899
11077
  ] : [],
10900
- ...[...args.native?.entries() ?? []].flatMap(
10901
- ([name2, native]) => native.late ? (native.groups ?? [
11078
+ ...[...args.native?.entries() ?? []].flatMap(([name2, native]) => {
11079
+ const late = native.late;
11080
+ const owner = targets.find((target) => target.name === name2);
11081
+ return late ? (native.groups ?? [
10902
11082
  {
10903
- name: native.late.name,
11083
+ name: late.name,
10904
11084
  sources: native.lateSources,
10905
11085
  flags: [],
10906
11086
  cxxFlags: []
10907
11087
  }
10908
11088
  ]).flatMap((group) => [
10909
11089
  ` .target(name: ${JSON.stringify(group.name)},`,
10910
- ` dependencies: ${JSON.stringify(args.native?.get(name2)?.mixed ? [] : [name2])},`,
11090
+ ` dependencies: ${JSON.stringify(native.mixed ? [] : [name2, ...late.producers])},`,
10911
11091
  ` path: ${JSON.stringify(native.clang ? "." : native.path)},`,
10912
11092
  ` sources: ${JSON.stringify(native.clang ? group.sources.map((source) => path11.posix.join(native.path, source)) : group.sources)},`,
10913
11093
  ` publicHeadersPath: ${JSON.stringify(native.clang ? path11.posix.dirname(native.clang.modulemap) : "include")},`,
10914
- ` cSettings: [.unsafeFlags(${JSON.stringify([...args.objcExports?.flags ?? args.nativeFlags ?? [], ...group.flags])})],`,
10915
- ` cxxSettings: [.unsafeFlags(${JSON.stringify(["-fno-cxx-modules", "-I", native.includeDirectory, "-I", args.headerDirectory, ...group.cxxFlags])})]),`
10916
- ]) : []
10917
- ),
11094
+ ` cSettings: [${macroSettings(owner?.cDefines)} .unsafeFlags(${JSON.stringify([...args.objcExports?.flags ?? args.nativeFlags ?? [], ...group.flags])})],`,
11095
+ ` cxxSettings: [${macroSettings(owner?.cxxDefines)} .unsafeFlags(${JSON.stringify(["-fno-cxx-modules", ...args.objcExports?.flags ?? args.nativeFlags ?? [], "-I", native.includeDirectory, "-I", args.headerDirectory, ...group.cxxFlags])})]),`
11096
+ ]) : [];
11097
+ }),
10918
11098
  args.cxxLanguageStandard ? ` ],
10919
11099
  cxxLanguageStandard: .${args.cxxLanguageStandard}` : " ]",
10920
11100
  ")",
@@ -14981,7 +15161,7 @@ function writeSwiftProject(layout, input, moduleRoot) {
14981
15161
  else files.set(file, prior);
14982
15162
  }
14983
15163
  targetStagedFiles.delete(target.name);
14984
- if (entries.some(([file]) => /\.(?:c|cc|cpp|cxx|m|mm)$/.test(file)) && (swift || input.nativeTargets?.some((value) => value.name === target.name) && entries.some(([file]) => /\.mm?$/.test(file)))) {
15164
+ if (entries.some(([file]) => /\.(?:c|cc|cpp|cxx|m|mm)$/.test(file)) && (swift || input.nativeTargets?.some((value) => value.name === target.name))) {
14985
15165
  if (!swift) {
14986
15166
  const unprepared = path11.join(
14987
15167
  layout.root,
@@ -15054,8 +15234,42 @@ function writeSwiftProject(layout, input, moduleRoot) {
15054
15234
  const entries = targetEntries(target);
15055
15235
  const units = entries.filter(([file]) => /\.(?:c|cc|cpp|cxx|m|mm)$/.test(file));
15056
15236
  if (units.length === 0) continue;
15237
+ const includes = `${prefix}include/`;
15238
+ const consumers = /* @__PURE__ */ new Map();
15239
+ const reverse = /* @__PURE__ */ new Map();
15240
+ for (const [file, contents] of entries) {
15241
+ const producers2 = /* @__PURE__ */ new Set();
15242
+ const source = contents.replace(/\/\*[\s\S]*?\*\//g, "");
15243
+ for (const match of source.matchAll(
15244
+ /^\s*#\s*(?:include|import)\s*[<"]([^>"]+)[>"]/gm
15245
+ )) {
15246
+ const include2 = match[1];
15247
+ const producer = /(?:^|\/)([^/]+)-Swift\.h$/.exec(include2)?.[1];
15248
+ if (producer && targets.some((value) => value.name === producer))
15249
+ producers2.add(producer);
15250
+ const local = [
15251
+ path11.posix.join(path11.posix.dirname(file), include2),
15252
+ `${includes}${include2}`
15253
+ ].find((candidate) => input.files[candidate] !== void 0);
15254
+ if (local) {
15255
+ reverse.set(local, [...reverse.get(local) ?? [], file]);
15256
+ }
15257
+ }
15258
+ consumers.set(file, producers2);
15259
+ }
15260
+ const queue = [...consumers.keys()].filter((file) => consumers.get(file).size > 0);
15261
+ for (let index = 0; index < queue.length; index++) {
15262
+ const file = queue[index];
15263
+ for (const parent of reverse.get(file) ?? []) {
15264
+ const inherited = consumers.get(parent);
15265
+ const before = inherited.size;
15266
+ for (const producer of consumers.get(file)) inherited.add(producer);
15267
+ if (before !== inherited.size) queue.push(parent);
15268
+ }
15269
+ }
15270
+ const late = units.filter(([file]) => consumers.get(file).size > 0);
15057
15271
  const settings = input.nativeTargets?.find((value) => value.name === target.name);
15058
- if (entries.some(([file]) => file.endsWith(".swift")) || settings && units.some(([file]) => /\.mm?$/.test(file))) {
15272
+ if (settings || entries.some(([file]) => file.endsWith(".swift"))) {
15059
15273
  try {
15060
15274
  if (!settings)
15061
15275
  throw new Error(
@@ -15123,7 +15337,7 @@ function writeSwiftProject(layout, input, moduleRoot) {
15123
15337
  return relative.split("/").some((part) => part.startsWith(".")) ? path11.posix.join(HIDDEN_UNITS, relative.replaceAll(/(^|\/)\./g, "$1%2E")) : relative;
15124
15338
  };
15125
15339
  const accessorFlags = accessor ? ["-include", accessorHeader] : [];
15126
- let nativeC = false;
15340
+ let nativeC = !roots2.length && !entries.some(([file]) => file.endsWith(".swift")) && !units.some(([file]) => /\.mm?$/.test(file));
15127
15341
  if (roots2.length) {
15128
15342
  const sourceHeaders = path11.join(
15129
15343
  layout.root,
@@ -15222,7 +15436,13 @@ export *
15222
15436
  )
15223
15437
  ];
15224
15438
  const cxx = /\.(?:cc|cpp|cxx|mm)$/.test(file);
15225
- const identity = createHash9("sha256").update(JSON.stringify([cxx, perFile])).digest("hex").slice(0, 12);
15439
+ const identity = createHash9("sha256").update(
15440
+ JSON.stringify([
15441
+ cxx,
15442
+ perFile,
15443
+ ...nativeC && !roots2.length ? [(consumers.get(file)?.size ?? 0) > 0] : []
15444
+ ])
15445
+ ).digest("hex").slice(0, 12);
15226
15446
  const group = groups.get(identity) ?? {
15227
15447
  name: `${target.name}${nativeC ? "Native" : "Swift"}Implementation_${identity}`,
15228
15448
  sources: [],
@@ -15257,6 +15477,31 @@ export *
15257
15477
  accessor.body
15258
15478
  );
15259
15479
  }
15480
+ if (nativeC && !roots2.length) {
15481
+ const lateSources = new Set(late.map(([file]) => unitSource(file)));
15482
+ const owner = [...groups.values()].find(
15483
+ (group) => group.sources.every((source) => !lateSources.has(source))
15484
+ );
15485
+ const implementations = [...groups.values()].filter((group) => group !== owner);
15486
+ native.set(target.name, {
15487
+ path: target.path,
15488
+ includeDirectory: include2,
15489
+ sources: owner?.sources ?? [],
15490
+ lateSources: implementations.flatMap((group) => group.sources),
15491
+ flags: owner?.flags ?? flags,
15492
+ cxxFlags: owner?.cxxFlags ?? flags,
15493
+ ...implementations.length ? {
15494
+ groups: implementations,
15495
+ late: {
15496
+ name: `${target.name}NativeImplementation`,
15497
+ producers: [
15498
+ ...new Set(late.flatMap(([file]) => [...consumers.get(file)]))
15499
+ ].sort()
15500
+ }
15501
+ } : {}
15502
+ });
15503
+ continue;
15504
+ }
15260
15505
  if (nativeC) {
15261
15506
  const modulemaps = Object.entries(settings.productHeaders).filter(
15262
15507
  ([product2]) => product2.endsWith("/Modules/module.modulemap")
@@ -15327,40 +15572,6 @@ export *
15327
15572
  }
15328
15573
  continue;
15329
15574
  }
15330
- const includes = `${prefix}include/`;
15331
- const consumers = /* @__PURE__ */ new Map();
15332
- const reverse = /* @__PURE__ */ new Map();
15333
- for (const [file, contents] of entries) {
15334
- const producers2 = /* @__PURE__ */ new Set();
15335
- const source = contents.replace(/\/\*[\s\S]*?\*\//g, "");
15336
- for (const match of source.matchAll(
15337
- /^\s*#\s*(?:include|import)\s*[<"]([^>"]+)[>"]/gm
15338
- )) {
15339
- const include2 = match[1];
15340
- const producer = /(?:^|\/)([^/]+)-Swift\.h$/.exec(include2)?.[1];
15341
- if (producer && targets.some((value) => value.name === producer))
15342
- producers2.add(producer);
15343
- const local = [
15344
- path11.posix.join(path11.posix.dirname(file), include2),
15345
- `${includes}${include2}`
15346
- ].find((candidate) => input.files[candidate] !== void 0);
15347
- if (local) {
15348
- reverse.set(local, [...reverse.get(local) ?? [], file]);
15349
- }
15350
- }
15351
- consumers.set(file, producers2);
15352
- }
15353
- const queue = [...consumers.keys()].filter((file) => consumers.get(file).size > 0);
15354
- for (let index = 0; index < queue.length; index++) {
15355
- const file = queue[index];
15356
- for (const parent of reverse.get(file) ?? []) {
15357
- const inherited = consumers.get(parent);
15358
- const before = inherited.size;
15359
- for (const producer of consumers.get(file)) inherited.add(producer);
15360
- if (before !== inherited.size) queue.push(parent);
15361
- }
15362
- }
15363
- const late = units.filter(([file]) => consumers.get(file).size > 0);
15364
15575
  native.set(target.name, {
15365
15576
  path: target.path,
15366
15577
  includeDirectory: path11.join(layout.root, includes),
@@ -15589,6 +15800,7 @@ ${[
15589
15800
  "-fobjc-exceptions",
15590
15801
  "-fexceptions",
15591
15802
  "-fwasm-exceptions",
15803
+ ...WASI_EMULATION_FLAGS,
15592
15804
  "-fobjc-arc",
15593
15805
  "-fblocks",
15594
15806
  "-F",