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
  let __sootsim_import_meta_url = '', __sootsim_import_meta_dirname = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; __sootsim_import_meta_dirname = __dirname; } catch {}
3
3
  "use strict";
4
4
  var __create = Object.create;
@@ -7511,7 +7511,17 @@ function sourceSwiftCheckout() {
7511
7511
  }
7512
7512
  function swiftSdkOptions() {
7513
7513
  const directory = process.env.PEACH_SWIFT_SDKS_PATH;
7514
- return directory ? ["--swift-sdks-path", import_node_path4.default.resolve(directory)] : [];
7514
+ if (directory) return ["--swift-sdks-path", import_node_path4.default.resolve(directory)];
7515
+ if (scratch && process.platform === "linux") {
7516
+ const config = process.env.XDG_CONFIG_HOME;
7517
+ if (config !== void 0 && !import_node_path4.default.isAbsolute(config))
7518
+ throw new Error("XDG_CONFIG_HOME must be an absolute path");
7519
+ return [
7520
+ "--swift-sdks-path",
7521
+ config === void 0 ? import_node_path4.default.join(import_node_os3.default.userInfo().homedir, ".swiftpm", "swift-sdks") : import_node_path4.default.join(config, "swiftpm", "swift-sdks")
7522
+ ];
7523
+ }
7524
+ return [];
7515
7525
  }
7516
7526
  var SWIFT_HOST_COMPILER_RELEASE = "swift-6.4.0-RELEASE-custom-0d775d32d7c74eae";
7517
7527
  var SWIFT_HOST_COMPILER_ID = "0d775d32d7c74eae";
@@ -7570,10 +7580,16 @@ function peachHome() {
7570
7580
  return override ? import_node_path4.default.resolve(override) : import_node_path4.default.join(import_node_os3.default.homedir(), ".peach");
7571
7581
  }
7572
7582
  var scratch;
7573
- var swiftHome;
7574
7583
  function swiftEnvironment(base = process.env) {
7575
7584
  if (!scratch) return base;
7576
- return swiftHome ? { ...base, TMPDIR: scratch, HOME: swiftHome } : { ...base, TMPDIR: scratch };
7585
+ return {
7586
+ ...base,
7587
+ TMPDIR: scratch.directory,
7588
+ XDG_CONFIG_HOME: import_node_path4.default.join(scratch.home, ".config"),
7589
+ XDG_CACHE_HOME: import_node_path4.default.join(scratch.home, ".cache"),
7590
+ XDG_DATA_HOME: import_node_path4.default.join(scratch.home, ".local", "share"),
7591
+ ...process.platform === "linux" ? { HOME: scratch.home } : {}
7592
+ };
7577
7593
  }
7578
7594
  function swiftSourceSdk(root) {
7579
7595
  const pin = JSON.parse(
@@ -8483,6 +8499,7 @@ function swiftObjCImports(graphs, options) {
8483
8499
  const categories = /* @__PURE__ */ new Map();
8484
8500
  const functions = /* @__PURE__ */ new Map();
8485
8501
  const typedefs = /* @__PURE__ */ new Map();
8502
+ const wrappedTypedefs = /* @__PURE__ */ new Map();
8486
8503
  const visit3 = (node) => {
8487
8504
  if (!record(node)) return;
8488
8505
  if (node.kind === "ObjCInterfaceDecl" && typeof node.name === "string" && selected.has(node.name)) {
@@ -8504,6 +8521,9 @@ function swiftObjCImports(graphs, options) {
8504
8521
  if (node.kind === "TypedefDecl" && typeof node.name === "string" && record(node.type)) {
8505
8522
  const canonical2 = node.type.desugaredQualType ?? node.type.qualType;
8506
8523
  if (typeof canonical2 === "string") typedefs.set(node.name, canonical2);
8524
+ if (nodes(node.inner).some((attribute) => attribute.kind === "SwiftNewTypeAttr")) {
8525
+ wrappedTypedefs.set(node.name, [...wrappedTypedefs.get(node.name) ?? [], node]);
8526
+ }
8507
8527
  }
8508
8528
  for (const child of nodes(node.inner)) visit3(child);
8509
8529
  };
@@ -8511,14 +8531,29 @@ function swiftObjCImports(graphs, options) {
8511
8531
  fail("declarations", "expected a complete Clang translation unit AST");
8512
8532
  visit3(options.clangAST);
8513
8533
  const symbols = /* @__PURE__ */ new Map();
8534
+ const seenSymbols = /* @__PURE__ */ new Set();
8514
8535
  for (const graph of graphs) {
8515
8536
  if (graph.module.name !== options.module)
8516
8537
  fail("declarations", `symbol graph belongs to ${graph.module.name}`);
8517
8538
  for (const symbol of graph.symbols) {
8518
- const previous = symbols.get(symbol.identifier.precise);
8519
- if (previous && JSON.stringify(previous) !== JSON.stringify(symbol))
8520
- fail(symbol.identifier.precise, "ambiguous imported declaration");
8521
- symbols.set(symbol.identifier.precise, symbol);
8539
+ if (symbol.availability?.some(
8540
+ (entry) => entry.isUnconditionallyUnavailable && (!entry.domain || entry.domain === "Swift" || entry.domain === "iOS")
8541
+ ))
8542
+ continue;
8543
+ const key = JSON.stringify([
8544
+ symbol.identifier.precise,
8545
+ symbol.kind.identifier,
8546
+ symbol.pathComponents,
8547
+ symbol.declarationFragments,
8548
+ symbol.functionSignature,
8549
+ symbol.accessLevel,
8550
+ symbol.availability
8551
+ ]);
8552
+ if (seenSymbols.has(key)) continue;
8553
+ seenSymbols.add(key);
8554
+ const overloads = symbols.get(symbol.identifier.precise) ?? [];
8555
+ overloads.push(symbol);
8556
+ symbols.set(symbol.identifier.precise, overloads);
8522
8557
  }
8523
8558
  }
8524
8559
  const classes = [];
@@ -8533,7 +8568,10 @@ function swiftObjCImports(graphs, options) {
8533
8568
  types.set(name2, nativeName);
8534
8569
  }
8535
8570
  for (const nativeName of [...selected].sort()) {
8536
- const symbol = symbols.get(`c:objc(cs)${nativeName}`);
8571
+ const candidates = symbols.get(`c:objc(cs)${nativeName}`);
8572
+ if (candidates && candidates.length !== 1)
8573
+ fail(nativeName, "ambiguous imported class declaration");
8574
+ const symbol = candidates?.[0];
8537
8575
  const name2 = symbol?.pathComponents[0];
8538
8576
  if (!symbol || symbol.kind.identifier !== "swift.class" || !name2 || !identifier(name2))
8539
8577
  fail(nativeName, "missing Swift-imported class declaration");
@@ -8548,6 +8586,70 @@ function swiftObjCImports(graphs, options) {
8548
8586
  types.set(name2, nativeName);
8549
8587
  classes.push({ name: name2, nativeName });
8550
8588
  }
8589
+ const wrapperMembers = /* @__PURE__ */ new Map();
8590
+ const wrapperConformances = /* @__PURE__ */ new Map();
8591
+ for (const graph of graphs)
8592
+ for (const edge of graph.relationships)
8593
+ if (edge.kind === "conformsTo" && edge.source.includes("@T@")) {
8594
+ const protocols = wrapperConformances.get(edge.source) ?? /* @__PURE__ */ new Set();
8595
+ protocols.add(edge.target);
8596
+ wrapperConformances.set(edge.source, protocols);
8597
+ }
8598
+ for (const candidates of symbols.values())
8599
+ for (const member of candidates)
8600
+ if (member.pathComponents.length === 2 && ["init(rawValue:)", "init(_:)"].includes(member.pathComponents[1])) {
8601
+ const owner = member.pathComponents[0];
8602
+ wrapperMembers.set(owner, [...wrapperMembers.get(owner) ?? [], member]);
8603
+ }
8604
+ const stringWrappers = /* @__PURE__ */ new Map();
8605
+ const wrapperSymbols = [...symbols].filter(
8606
+ ([usr, candidates]) => usr.includes("@T@") && candidates[0]?.kind.identifier === "swift.struct"
8607
+ ).sort(([left], [right]) => left.localeCompare(right));
8608
+ for (const [usr, candidates] of wrapperSymbols) {
8609
+ const nativeName = /^c:.*@T@([A-Za-z_]\w*)$/.exec(usr)?.[1];
8610
+ if (!nativeName) continue;
8611
+ const originals = wrappedTypedefs.get(nativeName);
8612
+ const declaration = originals?.[0];
8613
+ if (!declaration || !record(declaration.type)) continue;
8614
+ const original = declaration.type.desugaredQualType ?? declaration.type.qualType;
8615
+ if (typeof original !== "string" || original.replace(/\s/g, "") !== "NSString*")
8616
+ continue;
8617
+ const symbol = candidates[0];
8618
+ const name2 = symbol.pathComponents[0];
8619
+ 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)
8620
+ fail(usr, "typed string wrapper identity is unqualified");
8621
+ if (!["s:SY", "s:SH", "s:SQ", "s:s8SendableP"].every(
8622
+ (protocol) => wrapperConformances.get(usr)?.has(protocol)
8623
+ ))
8624
+ fail(usr, "typed string wrapper conformances are unqualified");
8625
+ const members = wrapperMembers.get(name2) ?? [];
8626
+ const initializers = members.filter(
8627
+ (member) => member.pathComponents[1] === "init(rawValue:)"
8628
+ );
8629
+ 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(
8630
+ (part) => part.kind === "typeIdentifier" && part.preciseIdentifier === "s:SS"
8631
+ ))
8632
+ fail(usr, "typed string wrapper raw initializer is unqualified");
8633
+ const unlabelled = members.filter((member) => member.pathComponents[1] === "init(_:)");
8634
+ 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(
8635
+ (part) => part.kind === "typeIdentifier" && part.preciseIdentifier === "s:SS"
8636
+ )))
8637
+ fail(usr, "typed string wrapper unlabeled initializer is unqualified");
8638
+ stringWrappers.set(
8639
+ name2,
8640
+ [
8641
+ `public struct ${swiftName(name2)}: Swift.RawRepresentable, Swift.Hashable, Swift.Equatable, Swift._SwiftNewtypeWrapper, Swift._ObjectiveCBridgeable, Swift.Sendable {`,
8642
+ " public typealias RawValue = Swift.String",
8643
+ " public typealias _ObjectiveCType = Foundation.NSString",
8644
+ " private let _rawValue: Swift.String",
8645
+ " public var rawValue: Swift.String { _rawValue }",
8646
+ " public init(rawValue: Swift.String) { _rawValue = rawValue }",
8647
+ ...unlabelled.length ? [" public init(_ rawValue: Swift.String) { _rawValue = rawValue }"] : [],
8648
+ "}",
8649
+ ""
8650
+ ].join("\n")
8651
+ );
8652
+ }
8551
8653
  const type = (parts, where) => {
8552
8654
  const written = text2(parts).trim();
8553
8655
  const optional = /[?!]$/.test(written);
@@ -8570,7 +8672,7 @@ function swiftObjCImports(graphs, options) {
8570
8672
  Double: "double"
8571
8673
  };
8572
8674
  if (!optional && primitive[written] && !parts.some(
8573
- (part) => part.preciseIdentifier?.startsWith("c:") || part.preciseIdentifier && symbols.get(part.preciseIdentifier)?.kind.identifier === "swift.class"
8675
+ (part) => part.preciseIdentifier?.startsWith("c:") || part.preciseIdentifier && symbols.get(part.preciseIdentifier)?.[0]?.kind.identifier === "swift.class"
8574
8676
  ))
8575
8677
  return {
8576
8678
  swift: `Swift.${written === "()" ? "Void" : written}`,
@@ -8582,7 +8684,7 @@ function swiftObjCImports(graphs, options) {
8582
8684
  const identifiers = parts.filter((part) => part.kind === "typeIdentifier");
8583
8685
  const id = identifiers.length === 1 ? identifiers[0]?.preciseIdentifier : void 0;
8584
8686
  const native = id && nativeClass(id);
8585
- const swiftClass = id ? symbols.get(id) : void 0;
8687
+ const swiftClass = id ? symbols.get(id)?.[0] : void 0;
8586
8688
  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;
8587
8689
  if (!resolved || identifiers[0]?.spelling !== spelling || spelling !== resolved && spelling !== native)
8588
8690
  return fail(
@@ -8643,7 +8745,8 @@ function swiftObjCImports(graphs, options) {
8643
8745
  );
8644
8746
  };
8645
8747
  const membersByClass = /* @__PURE__ */ new Map();
8646
- for (const symbol of symbols.values()) {
8748
+ const importedSymbols = [...symbols.values()].flat();
8749
+ for (const symbol of importedSymbols) {
8647
8750
  const owner = /^c:objc\(cs\)([A-Za-z_]\w*)\(/.exec(symbol.identifier.precise)?.[1];
8648
8751
  if (owner && selected.has(owner)) {
8649
8752
  const members = membersByClass.get(owner);
@@ -8770,27 +8873,40 @@ function swiftObjCImports(graphs, options) {
8770
8873
  (n) => nodes(n.inner)
8771
8874
  );
8772
8875
  for (const member of members) {
8773
- if (member.kind === "ObjCMethodDecl" && typeof member.name === "string" && (/^init(?:$|[^a-z])/.test(member.name.replace(/^_+/, "")) || nodes(member.inner).some(
8876
+ if (member.kind === "ObjCMethodDecl" && typeof member.name === "string" && member.name !== "init" && (/^init(?:$|[^a-z])/.test(member.name.replace(/^_+/, "")) || nodes(member.inner).some(
8774
8877
  (attribute) => attribute.kind === "NSConsumesSelfAttr" || attribute.kind === "ObjCDesignatedInitializerAttr"
8775
- )))
8878
+ )) && !nodes(member.inner).some((attribute) => attribute.kind === "UnavailableAttr"))
8776
8879
  fail(
8777
8880
  `${nativeName}.${member.name}`,
8778
8881
  "explicit or designated initialization is unqualified"
8779
8882
  );
8780
- if (member.variadic === true)
8781
- fail(`${nativeName}.${member.name}`, "variadic methods are unqualified");
8782
- }
8783
- const constructor = thunk(
8784
- `${nativeName}:new`,
8785
- raw2,
8786
- [],
8787
- null,
8788
- `[[${nativeName} alloc] init]`
8789
- );
8883
+ }
8790
8884
  const body = [
8791
- `public required init(_objcRetained: Swift.UnsafeMutableRawPointer) { precondition(Self.self == ${swiftName(name2)}.self, "Swift subclass construction is unqualified"); super.init(_objcRetained: _objcRetained) }`,
8792
- `public init() { precondition(Self.self == ${swiftName(name2)}.self, "Swift subclass construction is unqualified"); super.init(_objcRetained: ${constructor}()!) }`
8885
+ `public required init(_objcRetained: Swift.UnsafeMutableRawPointer) { precondition(Self.self == ${swiftName(name2)}.self, "Swift subclass construction is unqualified"); super.init(_objcRetained: _objcRetained) }`
8793
8886
  ];
8887
+ const defaultInitializer = members.find(
8888
+ (member) => member.kind === "ObjCMethodDecl" && member.instance === true && member.name === "init"
8889
+ );
8890
+ const importedInitializer = symbols.get(`c:objc(cs)${nativeName}(im)init`);
8891
+ const initializerSpelling = importedInitializer?.[0] ? text2(importedInitializer[0].declarationFragments ?? []).trim() : "init()";
8892
+ if (!/^init[?!]?\(\)$/.test(initializerSpelling))
8893
+ fail(`${nativeName}.init`, "default initializer signature is unqualified");
8894
+ if (!defaultInitializer || !nodes(defaultInitializer.inner).some(
8895
+ (attribute) => attribute.kind === "UnavailableAttr"
8896
+ )) {
8897
+ if (defaultInitializer && (importedInitializer?.length !== 1 || importedInitializer[0]?.kind.identifier !== "swift.init"))
8898
+ fail(`${nativeName}.init`, "missing Swift-imported default initializer");
8899
+ const constructor = thunk(
8900
+ `${nativeName}:new`,
8901
+ raw2,
8902
+ [],
8903
+ null,
8904
+ `[[${nativeName} alloc] init]`
8905
+ );
8906
+ body.push(
8907
+ `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}()!)`} }`
8908
+ );
8909
+ }
8794
8910
  bodies.set(name2, body);
8795
8911
  const prefix = `c:objc(cs)${nativeName}`;
8796
8912
  for (const symbol of membersByClass.get(nativeName) ?? []) {
@@ -8808,16 +8924,19 @@ function swiftObjCImports(graphs, options) {
8808
8924
  (m) => m.kind === (property ? "ObjCPropertyDecl" : "ObjCMethodDecl") && m.name === selector && (property ? m.class !== true === instance : m.instance === instance)
8809
8925
  );
8810
8926
  if (!decl) fail(usr, "member absent from original Clang interface");
8927
+ if (decl.variadic === true)
8928
+ fail(`${nativeName}.${selector}`, "variadic methods are unqualified");
8811
8929
  const parts = symbol.declarationFragments ?? [];
8812
8930
  const written = text2(parts);
8813
8931
  if (symbol.availability?.length || /@|\b(?:optional|nonisolated|isolated|async|throws|rethrows)\b/.test(written))
8814
8932
  fail(usr, "availability and asynchronous or throwing imports are unqualified");
8815
8933
  if (nodes(decl.inner).some(
8816
- (a) => /^(?:Unavailable|SwiftPrivate|SwiftAsync|SwiftError|ObjCRequiresSuper|NSConsumesSelf)Attr$/.test(
8934
+ (a) => /^(?:Unavailable|SwiftPrivate|SwiftAsync|SwiftError|ObjCRequiresSuper)Attr$/.test(
8817
8935
  String(a.kind)
8818
- )
8936
+ ) || a.kind === "NSConsumesSelfAttr" && selector !== "init"
8819
8937
  ))
8820
8938
  fail(usr, "member attributes require a qualified importer path");
8939
+ if (selector === "init" && symbol.kind.identifier === "swift.init") continue;
8821
8940
  const receiver = instance ? "_object" : nativeName;
8822
8941
  const access = symbol.accessLevel === "open" ? "open" : "public";
8823
8942
  const memberName = parts.find((part) => part.kind === "identifier")?.spelling;
@@ -8896,7 +9015,7 @@ function swiftObjCImports(graphs, options) {
8896
9015
  }
8897
9016
  }
8898
9017
  const importedFunctions = [];
8899
- for (const symbol of symbols.values()) {
9018
+ for (const symbol of importedSymbols) {
8900
9019
  if (symbol.kind.identifier !== "swift.func") continue;
8901
9020
  const usr = symbol.identifier.precise;
8902
9021
  const native = /^c:@F@([A-Za-z_]\w*)$/.exec(usr)?.[1];
@@ -8937,7 +9056,7 @@ function swiftObjCImports(graphs, options) {
8937
9056
  `public func ${swiftName(name2)}(${argumentsSwift}) -> ${result.swift} { ${result.c === "void" ? "" : "return "}${local}(${parameters.map((p) => swiftName(p.name)).join(", ")}) }`
8938
9057
  );
8939
9058
  }
8940
- if (!classes.length && !importedFunctions.length)
9059
+ if (!classes.length && !importedFunctions.length && !stringWrappers.size)
8941
9060
  fail("declarations", "no represented original Objective-C classes or C functions");
8942
9061
  const registerFunction = `_peachRegisterObjCImports_${hash(options.module)}`;
8943
9062
  const registration = [
@@ -8950,12 +9069,14 @@ function swiftObjCImports(graphs, options) {
8950
9069
  ""
8951
9070
  ].join("\n");
8952
9071
  const swift = [
8953
- ...classes.length ? ["import Foundation", "import PeachObjC"] : [],
9072
+ ...classes.length || stringWrappers.size ? ["import Foundation"] : [],
9073
+ ...classes.length ? ["import PeachObjC"] : [],
8954
9074
  "",
8955
9075
  ...external,
8956
9076
  "",
8957
9077
  ...importedFunctions,
8958
9078
  "",
9079
+ ...stringWrappers.values(),
8959
9080
  ...classes.flatMap((c) => [
8960
9081
  `open class ${swiftName(c.name)}: PeachObjC._ObjCForeignObject {`,
8961
9082
  ...bodies.get(c.name).map((line) => ` ${line}`),
@@ -9000,6 +9121,8 @@ var import_node_crypto5 = require("node:crypto");
9000
9121
  var import_node_fs5 = __toESM(require("node:fs"), 1);
9001
9122
  var import_node_path7 = __toESM(require("node:path"), 1);
9002
9123
  var NATIVE_GRAPH_SDK_VERSION = "27.1";
9124
+ var WASI_EMULATION = ["_WASI_EMULATED_SIGNAL", "_WASI_EMULATED_MMAN"];
9125
+ var WASI_EMULATION_FLAGS = WASI_EMULATION.map((name2) => `-D${name2}`);
9003
9126
  var NATIVE_GRAPH_INPUTS = {
9004
9127
  sdk: NATIVE_GRAPH_SDK_VERSION,
9005
9128
  settings: "e68503e5e534e9194af5efe8c636ca8b824e2d8237c5f38ec84aa4d155bc8418",
@@ -9216,7 +9339,9 @@ function objcView(surface, toolchainBin, stdlib, cacheDir2, work, original) {
9216
9339
  "-module-cache-path",
9217
9340
  import_node_path7.default.join(cacheDir2, "ios-module-cache"),
9218
9341
  "-minimum-access-level",
9219
- "public",
9342
+ // symbol graphs hide public underscored names at the public threshold.
9343
+ // original clang headers remain the declaration boundary.
9344
+ original ? "internal" : "public",
9220
9345
  "-skip-synthesized-members",
9221
9346
  "-omit-extension-block-symbols",
9222
9347
  "-output-dir",
@@ -9702,6 +9827,51 @@ function splitManifestArguments(source) {
9702
9827
  function swiftTargetModuleName(name2) {
9703
9828
  return name2.replace(/[^A-Za-z0-9_]/g, "_").replace(/^[0-9]/, "_");
9704
9829
  }
9830
+ function clangMacroSetting(macro) {
9831
+ const [name2, ...value] = macro.split("=");
9832
+ return value.length === 0 ? `.define(${JSON.stringify(name2)})` : `.define(${JSON.stringify(name2)}, to: ${JSON.stringify(value.join("="))})`;
9833
+ }
9834
+ var swiftEscapes = {
9835
+ "\\": "\\",
9836
+ '"': '"',
9837
+ "'": "'",
9838
+ n: "\n",
9839
+ r: "\r",
9840
+ t: " "
9841
+ };
9842
+ function settingDefines(call, tool) {
9843
+ const defines = [];
9844
+ for (const open of call.matchAll(new RegExp(`\\b${tool}Settings\\s*:\\s*\\[`, "g"))) {
9845
+ let depth = 1;
9846
+ let index = open.index + open[0].length;
9847
+ const start = index;
9848
+ for (; index < call.length && depth > 0; index++) {
9849
+ const char = call[index];
9850
+ if (char === '"') {
9851
+ for (index++; index < call.length && call[index] !== '"'; index++)
9852
+ if (call[index] === "\\") index++;
9853
+ } else if (char === "[") depth++;
9854
+ else if (char === "]") depth--;
9855
+ }
9856
+ const body = call.slice(start, index - 1);
9857
+ for (const match of body.matchAll(
9858
+ /\.define\(\s*"([A-Za-z_][A-Za-z0-9_]*)"\s*(?:,\s*to:\s*"((?:[^"\\]|\\.)*)"\s*)?\)/g
9859
+ )) {
9860
+ const name2 = match[1];
9861
+ defines.push(
9862
+ match[2] === void 0 ? name2 : `${name2}=${match[2].replace(/\\(.)/g, (_, escape) => {
9863
+ const value = swiftEscapes[escape];
9864
+ if (value === void 0)
9865
+ throw new Error(
9866
+ `Unsupported escape \\${escape} in the value of macro ${name2}`
9867
+ );
9868
+ return value;
9869
+ })}`
9870
+ );
9871
+ }
9872
+ }
9873
+ return defines;
9874
+ }
9705
9875
  function swiftManifestTargets(manifest, resourcePaths = []) {
9706
9876
  const implicitResources = swiftImplicitResourcePaths(resourcePaths);
9707
9877
  const targets = [];
@@ -9729,9 +9899,9 @@ function swiftManifestTargets(manifest, resourcePaths = []) {
9729
9899
  const cxxInterop = /\.interoperabilityMode\(\s*\.Cxx\s*\)/.test(
9730
9900
  call.replace(/"(?:\\.|[^"\\])*"/g, "")
9731
9901
  );
9732
- const defines = [
9733
- ...call.matchAll(/\.define\(\s*"([A-Za-z_][A-Za-z0-9_]*)"\s*\)/g)
9734
- ].map((match) => match[1]);
9902
+ const defines = settingDefines(call, "swift").map((define) => define.split("=")[0]);
9903
+ const cDefines = settingDefines(call, "c");
9904
+ const cxxDefines = settingDefines(call, "cxx");
9735
9905
  const linkedLibraries = [...call.matchAll(/\.linkedLibrary\(\s*"([^"]+)"\s*\)/g)].map(
9736
9906
  (match) => match[1]
9737
9907
  );
@@ -9774,6 +9944,8 @@ function swiftManifestTargets(manifest, resourcePaths = []) {
9774
9944
  mainActorIsolation,
9775
9945
  ...cxxInterop ? { cxxInterop: true } : {},
9776
9946
  ...defines.length === 0 ? {} : { defines },
9947
+ ...cDefines.length === 0 ? {} : { cDefines },
9948
+ ...cxxDefines.length === 0 ? {} : { cxxDefines },
9777
9949
  ...linkedLibraries.length === 0 ? {} : { linkedLibraries },
9778
9950
  resources,
9779
9951
  ...dependencies.length === 0 ? {} : { dependencies },
@@ -10682,7 +10854,7 @@ var EXECUTABLE_LINK_FLAGS = ` "-Xclang-linker", "-O0",
10682
10854
  `;
10683
10855
  var REACTOR_FLAG = '"-Xclang-linker", "-mexec-model=reactor",\n';
10684
10856
  var MULTI_MANIFEST_VERSION = 40;
10685
- var compilerSourceDigest = true ? "baf55512a114f4eec85d80685c9e0f04d08ac1ad34d8c18745c233b3d7827025" : swiftCompilerSourceDigest(__sootsim_import_meta_dirname);
10857
+ var compilerSourceDigest = true ? "9c8bf514e9d972c32ef441bda4effae79610e2c5add1faca769349803321528f" : swiftCompilerSourceDigest(__sootsim_import_meta_dirname);
10686
10858
  function swiftArtifactHash(input, release, moduleRoot) {
10687
10859
  const hash2 = (0, import_node_crypto7.createHash)("sha256");
10688
10860
  hash2.update(`swift-compile
@@ -10799,6 +10971,7 @@ function emitSwiftPackageManifest(args) {
10799
10971
  const linkedNativeModules = [...args.native?.entries() ?? []].flatMap(
10800
10972
  ([name2, value]) => value.clang ? [name2] : []
10801
10973
  );
10974
+ const macroSettings = (values) => (values ?? []).map((value) => ` ${clangMacroSetting(value)},`).join("");
10802
10975
  const stanza = (target) => {
10803
10976
  if (target.systemLibrary)
10804
10977
  return ` .systemLibrary(name: ${JSON.stringify(target.name)}, path: ${JSON.stringify(target.path)}),`;
@@ -10875,10 +11048,15 @@ function emitSwiftPackageManifest(args) {
10875
11048
  .unsafeFlags(["-Xlinker", "--strip-all"], .when(configuration: .release)),
10876
11049
  ]` : librarySettings.length > 0 ? `,
10877
11050
  linkerSettings: [${librarySettings.join(", ")}]` : "";
11051
+ const cDefines = macroSettings(target.cDefines);
11052
+ const cxxDefines = macroSettings(target.cxxDefines);
10878
11053
  const nativeSettings = native?.clang ? [
10879
- `cSettings: [.unsafeFlags(${JSON.stringify([...args.objcExports?.flags ?? args.nativeFlags ?? [], ...native.clang.flags])})]`,
10880
- `cxxSettings: [${defines} .unsafeFlags(${JSON.stringify(["-fno-cxx-modules", ...args.objcExports?.flags ?? args.nativeFlags ?? [], ...native.clang.cxxFlags])})]`
10881
- ].join(", ") : `${args.objcExports ? `cSettings: [.unsafeFlags(${JSON.stringify(args.objcExports.flags)})], ` : ""}cxxSettings: [${defines} .unsafeFlags(["-fno-cxx-modules"])]`;
11054
+ `cSettings: [${cDefines} .unsafeFlags(${JSON.stringify([...args.objcExports?.flags ?? args.nativeFlags ?? [], ...native.clang.flags])})]`,
11055
+ `cxxSettings: [${cxxDefines} .unsafeFlags(${JSON.stringify(["-fno-cxx-modules", ...args.objcExports?.flags ?? args.nativeFlags ?? [], ...native.clang.cxxFlags])})]`
11056
+ ].join(", ") : [
11057
+ `cSettings: [${cDefines} .unsafeFlags(${JSON.stringify([...args.objcExports?.flags ?? args.nativeFlags ?? [], ...native?.flags ?? []])})]`,
11058
+ `cxxSettings: [${cxxDefines} .unsafeFlags(${JSON.stringify(["-fno-cxx-modules", ...args.objcExports?.flags ?? args.nativeFlags ?? [], ...native?.cxxFlags ?? []])})]`
11059
+ ].join(", ");
10882
11060
  return [
10883
11061
  ` ${kind}(`,
10884
11062
  ` name: "${target.name}",`,
@@ -10888,7 +11066,7 @@ function emitSwiftPackageManifest(args) {
10888
11066
  ...native?.clang ? [
10889
11067
  ` sources: ${JSON.stringify(native.clang.sources.map((source) => import_node_path10.default.posix.join(native.path, source)))},`,
10890
11068
  ` publicHeadersPath: ${JSON.stringify(import_node_path10.default.posix.dirname(native.clang.modulemap))},`
10891
- ] : [],
11069
+ ] : native?.flags ? [` sources: ${JSON.stringify(native.sources)},`] : [],
10892
11070
  // the native backend supplies dependency module maps without their
10893
11071
  // compiled modules. textual c++ includes keep those dependencies usable.
10894
11072
  ` ${clang ? nativeSettings : swiftSettings}${link}`,
@@ -10914,24 +11092,26 @@ function emitSwiftPackageManifest(args) {
10914
11092
  ' publicHeadersPath: "include",',
10915
11093
  ` cSettings: [.unsafeFlags(${JSON.stringify([...args.objcExports.flags.filter((flag) => flag !== "-fobjc-arc"), "-fno-objc-arc", "-Xclang", "-disable-objc-default-synthesize-properties"])})]),`
10916
11094
  ] : [],
10917
- ...[...args.native?.entries() ?? []].flatMap(
10918
- ([name2, native]) => native.late ? (native.groups ?? [
11095
+ ...[...args.native?.entries() ?? []].flatMap(([name2, native]) => {
11096
+ const late = native.late;
11097
+ const owner = targets.find((target) => target.name === name2);
11098
+ return late ? (native.groups ?? [
10919
11099
  {
10920
- name: native.late.name,
11100
+ name: late.name,
10921
11101
  sources: native.lateSources,
10922
11102
  flags: [],
10923
11103
  cxxFlags: []
10924
11104
  }
10925
11105
  ]).flatMap((group) => [
10926
11106
  ` .target(name: ${JSON.stringify(group.name)},`,
10927
- ` dependencies: ${JSON.stringify(args.native?.get(name2)?.mixed ? [] : [name2])},`,
11107
+ ` dependencies: ${JSON.stringify(native.mixed ? [] : [name2, ...late.producers])},`,
10928
11108
  ` path: ${JSON.stringify(native.clang ? "." : native.path)},`,
10929
11109
  ` sources: ${JSON.stringify(native.clang ? group.sources.map((source) => import_node_path10.default.posix.join(native.path, source)) : group.sources)},`,
10930
11110
  ` publicHeadersPath: ${JSON.stringify(native.clang ? import_node_path10.default.posix.dirname(native.clang.modulemap) : "include")},`,
10931
- ` cSettings: [.unsafeFlags(${JSON.stringify([...args.objcExports?.flags ?? args.nativeFlags ?? [], ...group.flags])})],`,
10932
- ` cxxSettings: [.unsafeFlags(${JSON.stringify(["-fno-cxx-modules", "-I", native.includeDirectory, "-I", args.headerDirectory, ...group.cxxFlags])})]),`
10933
- ]) : []
10934
- ),
11111
+ ` cSettings: [${macroSettings(owner?.cDefines)} .unsafeFlags(${JSON.stringify([...args.objcExports?.flags ?? args.nativeFlags ?? [], ...group.flags])})],`,
11112
+ ` cxxSettings: [${macroSettings(owner?.cxxDefines)} .unsafeFlags(${JSON.stringify(["-fno-cxx-modules", ...args.objcExports?.flags ?? args.nativeFlags ?? [], "-I", native.includeDirectory, "-I", args.headerDirectory, ...group.cxxFlags])})]),`
11113
+ ]) : [];
11114
+ }),
10935
11115
  args.cxxLanguageStandard ? ` ],
10936
11116
  cxxLanguageStandard: .${args.cxxLanguageStandard}` : " ]",
10937
11117
  ")",
@@ -14998,7 +15178,7 @@ function writeSwiftProject(layout, input, moduleRoot) {
14998
15178
  else files.set(file, prior);
14999
15179
  }
15000
15180
  targetStagedFiles.delete(target.name);
15001
- 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)))) {
15181
+ if (entries.some(([file]) => /\.(?:c|cc|cpp|cxx|m|mm)$/.test(file)) && (swift || input.nativeTargets?.some((value) => value.name === target.name))) {
15002
15182
  if (!swift) {
15003
15183
  const unprepared = import_node_path10.default.join(
15004
15184
  layout.root,
@@ -15071,8 +15251,42 @@ function writeSwiftProject(layout, input, moduleRoot) {
15071
15251
  const entries = targetEntries(target);
15072
15252
  const units = entries.filter(([file]) => /\.(?:c|cc|cpp|cxx|m|mm)$/.test(file));
15073
15253
  if (units.length === 0) continue;
15254
+ const includes = `${prefix}include/`;
15255
+ const consumers = /* @__PURE__ */ new Map();
15256
+ const reverse = /* @__PURE__ */ new Map();
15257
+ for (const [file, contents] of entries) {
15258
+ const producers2 = /* @__PURE__ */ new Set();
15259
+ const source = contents.replace(/\/\*[\s\S]*?\*\//g, "");
15260
+ for (const match of source.matchAll(
15261
+ /^\s*#\s*(?:include|import)\s*[<"]([^>"]+)[>"]/gm
15262
+ )) {
15263
+ const include2 = match[1];
15264
+ const producer = /(?:^|\/)([^/]+)-Swift\.h$/.exec(include2)?.[1];
15265
+ if (producer && targets.some((value) => value.name === producer))
15266
+ producers2.add(producer);
15267
+ const local = [
15268
+ import_node_path10.default.posix.join(import_node_path10.default.posix.dirname(file), include2),
15269
+ `${includes}${include2}`
15270
+ ].find((candidate) => input.files[candidate] !== void 0);
15271
+ if (local) {
15272
+ reverse.set(local, [...reverse.get(local) ?? [], file]);
15273
+ }
15274
+ }
15275
+ consumers.set(file, producers2);
15276
+ }
15277
+ const queue = [...consumers.keys()].filter((file) => consumers.get(file).size > 0);
15278
+ for (let index = 0; index < queue.length; index++) {
15279
+ const file = queue[index];
15280
+ for (const parent of reverse.get(file) ?? []) {
15281
+ const inherited = consumers.get(parent);
15282
+ const before = inherited.size;
15283
+ for (const producer of consumers.get(file)) inherited.add(producer);
15284
+ if (before !== inherited.size) queue.push(parent);
15285
+ }
15286
+ }
15287
+ const late = units.filter(([file]) => consumers.get(file).size > 0);
15074
15288
  const settings = input.nativeTargets?.find((value) => value.name === target.name);
15075
- if (entries.some(([file]) => file.endsWith(".swift")) || settings && units.some(([file]) => /\.mm?$/.test(file))) {
15289
+ if (settings || entries.some(([file]) => file.endsWith(".swift"))) {
15076
15290
  try {
15077
15291
  if (!settings)
15078
15292
  throw new Error(
@@ -15140,7 +15354,7 @@ function writeSwiftProject(layout, input, moduleRoot) {
15140
15354
  return relative.split("/").some((part) => part.startsWith(".")) ? import_node_path10.default.posix.join(HIDDEN_UNITS, relative.replaceAll(/(^|\/)\./g, "$1%2E")) : relative;
15141
15355
  };
15142
15356
  const accessorFlags = accessor ? ["-include", accessorHeader] : [];
15143
- let nativeC = false;
15357
+ let nativeC = !roots2.length && !entries.some(([file]) => file.endsWith(".swift")) && !units.some(([file]) => /\.mm?$/.test(file));
15144
15358
  if (roots2.length) {
15145
15359
  const sourceHeaders = import_node_path10.default.join(
15146
15360
  layout.root,
@@ -15239,7 +15453,13 @@ export *
15239
15453
  )
15240
15454
  ];
15241
15455
  const cxx = /\.(?:cc|cpp|cxx|mm)$/.test(file);
15242
- const identity = (0, import_node_crypto7.createHash)("sha256").update(JSON.stringify([cxx, perFile])).digest("hex").slice(0, 12);
15456
+ const identity = (0, import_node_crypto7.createHash)("sha256").update(
15457
+ JSON.stringify([
15458
+ cxx,
15459
+ perFile,
15460
+ ...nativeC && !roots2.length ? [(consumers.get(file)?.size ?? 0) > 0] : []
15461
+ ])
15462
+ ).digest("hex").slice(0, 12);
15243
15463
  const group = groups.get(identity) ?? {
15244
15464
  name: `${target.name}${nativeC ? "Native" : "Swift"}Implementation_${identity}`,
15245
15465
  sources: [],
@@ -15274,6 +15494,31 @@ export *
15274
15494
  accessor.body
15275
15495
  );
15276
15496
  }
15497
+ if (nativeC && !roots2.length) {
15498
+ const lateSources = new Set(late.map(([file]) => unitSource(file)));
15499
+ const owner = [...groups.values()].find(
15500
+ (group) => group.sources.every((source) => !lateSources.has(source))
15501
+ );
15502
+ const implementations = [...groups.values()].filter((group) => group !== owner);
15503
+ native.set(target.name, {
15504
+ path: target.path,
15505
+ includeDirectory: include2,
15506
+ sources: owner?.sources ?? [],
15507
+ lateSources: implementations.flatMap((group) => group.sources),
15508
+ flags: owner?.flags ?? flags,
15509
+ cxxFlags: owner?.cxxFlags ?? flags,
15510
+ ...implementations.length ? {
15511
+ groups: implementations,
15512
+ late: {
15513
+ name: `${target.name}NativeImplementation`,
15514
+ producers: [
15515
+ ...new Set(late.flatMap(([file]) => [...consumers.get(file)]))
15516
+ ].sort()
15517
+ }
15518
+ } : {}
15519
+ });
15520
+ continue;
15521
+ }
15277
15522
  if (nativeC) {
15278
15523
  const modulemaps = Object.entries(settings.productHeaders).filter(
15279
15524
  ([product2]) => product2.endsWith("/Modules/module.modulemap")
@@ -15344,40 +15589,6 @@ export *
15344
15589
  }
15345
15590
  continue;
15346
15591
  }
15347
- const includes = `${prefix}include/`;
15348
- const consumers = /* @__PURE__ */ new Map();
15349
- const reverse = /* @__PURE__ */ new Map();
15350
- for (const [file, contents] of entries) {
15351
- const producers2 = /* @__PURE__ */ new Set();
15352
- const source = contents.replace(/\/\*[\s\S]*?\*\//g, "");
15353
- for (const match of source.matchAll(
15354
- /^\s*#\s*(?:include|import)\s*[<"]([^>"]+)[>"]/gm
15355
- )) {
15356
- const include2 = match[1];
15357
- const producer = /(?:^|\/)([^/]+)-Swift\.h$/.exec(include2)?.[1];
15358
- if (producer && targets.some((value) => value.name === producer))
15359
- producers2.add(producer);
15360
- const local = [
15361
- import_node_path10.default.posix.join(import_node_path10.default.posix.dirname(file), include2),
15362
- `${includes}${include2}`
15363
- ].find((candidate) => input.files[candidate] !== void 0);
15364
- if (local) {
15365
- reverse.set(local, [...reverse.get(local) ?? [], file]);
15366
- }
15367
- }
15368
- consumers.set(file, producers2);
15369
- }
15370
- const queue = [...consumers.keys()].filter((file) => consumers.get(file).size > 0);
15371
- for (let index = 0; index < queue.length; index++) {
15372
- const file = queue[index];
15373
- for (const parent of reverse.get(file) ?? []) {
15374
- const inherited = consumers.get(parent);
15375
- const before = inherited.size;
15376
- for (const producer of consumers.get(file)) inherited.add(producer);
15377
- if (before !== inherited.size) queue.push(parent);
15378
- }
15379
- }
15380
- const late = units.filter(([file]) => consumers.get(file).size > 0);
15381
15592
  native.set(target.name, {
15382
15593
  path: target.path,
15383
15594
  includeDirectory: import_node_path10.default.join(layout.root, includes),
@@ -15606,6 +15817,7 @@ ${[
15606
15817
  "-fobjc-exceptions",
15607
15818
  "-fexceptions",
15608
15819
  "-fwasm-exceptions",
15820
+ ...WASI_EMULATION_FLAGS,
15609
15821
  "-fobjc-arc",
15610
15822
  "-fblocks",
15611
15823
  "-F",