peachsim 0.1.1667 → 0.1.1673

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 (178) 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/react.ts +3 -18
  7. package/cli/commands/screenshot.ts +1 -1
  8. package/cli/commands/screenshots-capture.ts +1 -1
  9. package/cli/drivers/playwright-provisioning.ts +1 -4
  10. package/cli/drivers/playwright.ts +15 -1
  11. package/cli/scene-video.ts +1 -1
  12. package/cli/ui.ts +20 -0
  13. package/cli/ws-bridge.ts +7 -36
  14. package/detox/frame-identity.cjs +21 -0
  15. package/detox/frame-identity.d.cts +6 -0
  16. package/detox/index.ts +39 -33
  17. package/detox/jest-environment.cjs +4 -1
  18. package/detox/jest-setup-after-env.cjs +0 -4
  19. package/detox/navigation-lifecycle.ts +2 -2
  20. package/detox/proof-observer.ts +126 -0
  21. package/dist-lib/agent-daemon-client.cjs +29 -1
  22. package/dist-lib/agent-events.cjs +1 -1
  23. package/dist-lib/attached-projects.cjs +10 -1
  24. package/dist-lib/auth/shared-session.cjs +1 -1
  25. package/dist-lib/backend-origin.cjs +1 -1
  26. package/dist-lib/beta.cjs +1 -1
  27. package/dist-lib/beta.mjs +1 -1
  28. package/dist-lib/bridge-constants.cjs +1 -1
  29. package/dist-lib/bridge-contract-input.cjs +1 -1
  30. package/dist-lib/bridge-contract-input.mjs +1 -1
  31. package/dist-lib/bridge-contract.cjs +1 -1
  32. package/dist-lib/bridge-contract.mjs +1 -1
  33. package/dist-lib/bundle-channel.cjs +530 -154
  34. package/dist-lib/capture-contract.cjs +1 -1
  35. package/dist-lib/capture-contract.mjs +1 -1
  36. package/dist-lib/cloud-contract.cjs +1 -1
  37. package/dist-lib/cloud-contract.mjs +1 -1
  38. package/dist-lib/cloud-test-args.cjs +1 -1
  39. package/dist-lib/cloud-test-args.mjs +1 -1
  40. package/dist-lib/cloud.cjs +1 -1
  41. package/dist-lib/cloud.mjs +1 -1
  42. package/dist-lib/config.cjs +1 -1
  43. package/dist-lib/config.mjs +1 -1
  44. package/dist-lib/detox/index.cjs +5074 -7353
  45. package/dist-lib/detox/jest-environment.cjs +4 -1
  46. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  47. package/dist-lib/expo-swift-bundle.cjs +578 -151
  48. package/dist-lib/expo-swift-metadata.cjs +1 -1
  49. package/dist-lib/expo-swift-metadata.mjs +1 -1
  50. package/dist-lib/home-paths.cjs +1 -1
  51. package/dist-lib/host/bridge-host.cjs +660 -192
  52. package/dist-lib/host/fetch-proxy-handler.cjs +2 -2
  53. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  54. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  55. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  56. package/dist-lib/host/websocket-proxy.cjs +1 -1
  57. package/dist-lib/index.cjs +206 -6
  58. package/dist-lib/jump-to-source-babel.cjs +1 -1
  59. package/dist-lib/jump-to-source-native.cjs +1 -1
  60. package/dist-lib/kotlin-host.cjs +1 -1
  61. package/dist-lib/menu.cjs +1 -1
  62. package/dist-lib/menu.mjs +1 -1
  63. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  64. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  65. package/dist-lib/metro-production-bundle.cjs +10 -1
  66. package/dist-lib/metro-production-bundle.mjs +12 -1
  67. package/dist-lib/metro.cjs +155 -5
  68. package/dist-lib/native-app-identity-project.cjs +43 -5
  69. package/dist-lib/native-app-identity-project.mjs +43 -5
  70. package/dist-lib/native-app-identity.cjs +1 -1
  71. package/dist-lib/native-app-identity.mjs +1 -1
  72. package/dist-lib/native-firebase-metadata.cjs +1 -1
  73. package/dist-lib/native-firebase-metadata.mjs +1 -1
  74. package/dist-lib/plist.cjs +1 -1
  75. package/dist-lib/plist.mjs +1 -1
  76. package/dist-lib/profiles.cjs +21 -1
  77. package/dist-lib/public-brand.cjs +1 -1
  78. package/dist-lib/public-origins-lib-esm.json +73 -27
  79. package/dist-lib/public-origins-lib-static.json +1 -1
  80. package/dist-lib/public-origins-lib.json +563 -183
  81. package/dist-lib/react-native-host-modules.cjs +1 -1
  82. package/dist-lib/react-native-host-modules.mjs +1 -1
  83. package/dist-lib/reap-browser.cjs +964 -0
  84. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  85. package/dist-lib/sdk.cjs +1 -1
  86. package/dist-lib/sdk.mjs +1 -1
  87. package/dist-lib/skills.cjs +963 -521
  88. package/dist-lib/swift-compile.cjs +276 -86
  89. package/dist-lib/swift-compile.mjs +276 -86
  90. package/dist-lib/swift-package.cjs +34 -4
  91. package/dist-lib/swift-package.mjs +33 -4
  92. package/dist-lib/swift-submit.cjs +2 -2
  93. package/dist-lib/swift-submit.mjs +2 -2
  94. package/dist-lib/swift-toolchain.cjs +25 -44
  95. package/dist-lib/swift.cjs +1 -1
  96. package/dist-lib/vite-swift.cjs +579 -113
  97. package/dist-lib/vite.cjs +61 -2
  98. package/dist-lib/worklet-executable.cjs +1 -1
  99. package/dist-lib/worklet-executable.mjs +1 -1
  100. package/dist-types/packages/peach-engine/src/engine/clipboardContract.d.ts +7 -0
  101. package/dist-types/packages/peach-engine/src/engine/glass-material.d.ts +1 -1
  102. package/dist-types/packages/peach-engine/src/engine/image-loader.d.ts +2 -0
  103. package/dist-types/packages/peach-engine/src/engine/inspect-outline.d.ts +2 -1
  104. package/dist-types/packages/peach-engine/src/engine/liquid-glass.d.ts +1 -0
  105. package/dist-types/packages/peach-engine/src/engine/paint-boundary.d.ts +3 -1
  106. package/dist-types/packages/peach-engine/src/render-worker/host-service-protocol.d.ts +7 -0
  107. package/dist-types/packages/peach-engine/src/render-worker/worklet-runtime-kind.d.ts +24 -0
  108. package/dist-types/packages/peach-engine/src/render-worker/worklet-runtime.d.ts +4 -2
  109. package/dist-types/packages/peach-engine/src/settings/devices.d.ts +1 -0
  110. package/dist-types/packages/peach-globals/src/clipboardBridgeContract.d.ts +18 -0
  111. package/dist-types/packages/peach-globals/src/index.d.ts +1 -1
  112. package/dist-types/packages/peach-globals/src/nodeContract.d.ts +1 -0
  113. package/dist-types/packages/peach-kit/src/capabilities.d.ts +1 -0
  114. package/package.json +1 -1
  115. package/runtime-companion.json +1 -1
  116. package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFString.h +2 -0
  117. package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h +36 -0
  118. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCDynamicStore.h +439 -0
  119. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCDynamicStoreCopySpecific.h +216 -0
  120. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCDynamicStoreKey.h +267 -0
  121. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCNetwork.h +204 -0
  122. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCNetworkConfiguration.h +1393 -0
  123. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCNetworkConnection.h +568 -0
  124. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCNetworkReachability.h +369 -0
  125. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCPreferences.h +473 -0
  126. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCPreferencesPath.h +179 -0
  127. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCPreferencesSetSpecific.h +95 -0
  128. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCSchemaDefinitions.h +2395 -0
  129. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SystemConfiguration.h +184 -0
  130. package/sdk/ios/usr/include/libkern/OSByteOrder.h +315 -0
  131. package/sdk/ios/usr/include/libkern/machine/OSByteOrder.h +147 -0
  132. package/src/bridge-contract.ts +42 -0
  133. package/src/chromium-admission.ts +196 -0
  134. package/src/host/bridge-host.ts +6 -43
  135. package/src/launch-deadline.ts +74 -0
  136. package/src/nitro-adapter.lock.json +3 -3
  137. package/src/profiles.ts +21 -0
  138. package/src/react-native-coverage/capability-reference-resolution.ts +402 -0
  139. package/src/react-native-coverage/capability-source-references.ts +1296 -0
  140. package/src/react-native-coverage/native-typescript-parser.ts +74 -0
  141. package/src/react-native-coverage/project-aliases.ts +207 -0
  142. package/src/react-native-coverage/verified-reach.ts +47 -0
  143. package/src/reap-browser.ts +1019 -0
  144. package/src/skills/builtin/a11y-review.ts +1 -1
  145. package/src/skills/builtin/perf-profile.ts +1 -1
  146. package/src/skills/builtin/screenshot-all.ts +1 -1
  147. package/src/skills/builtin/visual-diff.ts +1 -1
  148. package/src/swift-compile.ts +107 -56
  149. package/src/swift-coverage/indexdump.ts +80 -0
  150. package/src/swift-coverage/indexing.ts +147 -0
  151. package/src/swift-coverage/package.ts +230 -0
  152. package/src/swift-coverage/provenance.ts +47 -0
  153. package/src/swift-coverage/reader.ts +81 -0
  154. package/src/swift-coverage/source.ts +252 -0
  155. package/src/swift-coverage/types.ts +58 -0
  156. package/src/swift-coverage/xcode-assets.ts +175 -0
  157. package/src/swift-coverage/xcode-bridging.ts +160 -0
  158. package/src/swift-coverage/xcode-packages.ts +251 -0
  159. package/src/swift-coverage/xcode-strings.ts +78 -0
  160. package/src/swift-coverage/xcode.ts +656 -0
  161. package/src/swift-distribution.lock.json +8 -8
  162. package/src/swift-host.ts +21 -1
  163. package/src/swift-objc-import.ts +191 -27
  164. package/src/swift-objc-standin.ts +4 -2
  165. package/src/swift-package-manifest.ts +134 -13
  166. package/src/swift-package.ts +46 -4
  167. package/src/swift-submit.ts +2 -1
  168. package/src/swift-toolchain.ts +36 -61
  169. package/src/worker-system-chunks.ts +3 -10
  170. package/src/xcode-project.ts +5 -5
  171. package/detox/attempt-events.cjs +0 -914
  172. package/detox/attempt-events.d.cts +0 -113
  173. package/detox/motion-change.cjs +0 -524
  174. package/detox/motion-change.d.cts +0 -140
  175. package/detox/motion-leg-starts.cjs +0 -20
  176. package/detox/motion-leg-starts.d.cts +0 -8
  177. package/detox/proof-frame.cjs +0 -190
  178. 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.1673 | (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}`),
@@ -9189,7 +9310,9 @@ function objcView(surface, toolchainBin, stdlib, cacheDir2, work, original) {
9189
9310
  "-module-cache-path",
9190
9311
  path7.join(cacheDir2, "ios-module-cache"),
9191
9312
  "-minimum-access-level",
9192
- "public",
9313
+ // symbol graphs hide public underscored names at the public threshold.
9314
+ // original clang headers remain the declaration boundary.
9315
+ original ? "internal" : "public",
9193
9316
  "-skip-synthesized-members",
9194
9317
  "-omit-extension-block-symbols",
9195
9318
  "-output-dir",
@@ -9675,6 +9798,32 @@ function splitManifestArguments(source) {
9675
9798
  function swiftTargetModuleName(name2) {
9676
9799
  return name2.replace(/[^A-Za-z0-9_]/g, "_").replace(/^[0-9]/, "_");
9677
9800
  }
9801
+ function clangMacroSetting(macro) {
9802
+ const [name2, ...value] = macro.split("=");
9803
+ return value.length === 0 ? `.define(${JSON.stringify(name2)})` : `.define(${JSON.stringify(name2)}, to: ${JSON.stringify(value.join("="))})`;
9804
+ }
9805
+ function settingDefines(call, tool) {
9806
+ const defines = [];
9807
+ for (const open of call.matchAll(new RegExp(`\\b${tool}Settings\\s*:\\s*\\[`, "g"))) {
9808
+ let depth = 1;
9809
+ let index = open.index + open[0].length;
9810
+ const start = index;
9811
+ for (; index < call.length && depth > 0; index++) {
9812
+ const char = call[index];
9813
+ if (char === '"') {
9814
+ for (index++; index < call.length && call[index] !== '"'; index++)
9815
+ if (call[index] === "\\") index++;
9816
+ } else if (char === "[") depth++;
9817
+ else if (char === "]") depth--;
9818
+ }
9819
+ const body = call.slice(start, index - 1);
9820
+ for (const match of body.matchAll(
9821
+ /\.define\(\s*"([A-Za-z_][A-Za-z0-9_]*)"\s*(?:,\s*to:\s*"([^"]*)"\s*)?\)/g
9822
+ ))
9823
+ defines.push(match[2] === void 0 ? match[1] : `${match[1]}=${match[2]}`);
9824
+ }
9825
+ return defines;
9826
+ }
9678
9827
  function swiftManifestTargets(manifest, resourcePaths = []) {
9679
9828
  const implicitResources = swiftImplicitResourcePaths(resourcePaths);
9680
9829
  const targets = [];
@@ -9702,9 +9851,9 @@ function swiftManifestTargets(manifest, resourcePaths = []) {
9702
9851
  const cxxInterop = /\.interoperabilityMode\(\s*\.Cxx\s*\)/.test(
9703
9852
  call.replace(/"(?:\\.|[^"\\])*"/g, "")
9704
9853
  );
9705
- const defines = [
9706
- ...call.matchAll(/\.define\(\s*"([A-Za-z_][A-Za-z0-9_]*)"\s*\)/g)
9707
- ].map((match) => match[1]);
9854
+ const defines = settingDefines(call, "swift").map((define) => define.split("=")[0]);
9855
+ const cDefines = settingDefines(call, "c");
9856
+ const cxxDefines = settingDefines(call, "cxx");
9708
9857
  const linkedLibraries = [...call.matchAll(/\.linkedLibrary\(\s*"([^"]+)"\s*\)/g)].map(
9709
9858
  (match) => match[1]
9710
9859
  );
@@ -9747,6 +9896,8 @@ function swiftManifestTargets(manifest, resourcePaths = []) {
9747
9896
  mainActorIsolation,
9748
9897
  ...cxxInterop ? { cxxInterop: true } : {},
9749
9898
  ...defines.length === 0 ? {} : { defines },
9899
+ ...cDefines.length === 0 ? {} : { cDefines },
9900
+ ...cxxDefines.length === 0 ? {} : { cxxDefines },
9750
9901
  ...linkedLibraries.length === 0 ? {} : { linkedLibraries },
9751
9902
  resources,
9752
9903
  ...dependencies.length === 0 ? {} : { dependencies },
@@ -10665,7 +10816,7 @@ var EXECUTABLE_LINK_FLAGS = ` "-Xclang-linker", "-O0",
10665
10816
  `;
10666
10817
  var REACTOR_FLAG = '"-Xclang-linker", "-mexec-model=reactor",\n';
10667
10818
  var MULTI_MANIFEST_VERSION = 40;
10668
- var compilerSourceDigest = true ? "baf55512a114f4eec85d80685c9e0f04d08ac1ad34d8c18745c233b3d7827025" : swiftCompilerSourceDigest(import.meta.dirname);
10819
+ var compilerSourceDigest = true ? "6ea8d8a06ae707693b5fbb43a21e9d705ee8a19779051d47b05c4bbaeb39fb6c" : swiftCompilerSourceDigest(import.meta.dirname);
10669
10820
  function swiftArtifactHash(input, release, moduleRoot) {
10670
10821
  const hash2 = createHash9("sha256");
10671
10822
  hash2.update(`swift-compile
@@ -10782,6 +10933,7 @@ function emitSwiftPackageManifest(args) {
10782
10933
  const linkedNativeModules = [...args.native?.entries() ?? []].flatMap(
10783
10934
  ([name2, value]) => value.clang ? [name2] : []
10784
10935
  );
10936
+ const macroSettings = (values) => (values ?? []).map((value) => ` ${clangMacroSetting(value)},`).join("");
10785
10937
  const stanza = (target) => {
10786
10938
  if (target.systemLibrary)
10787
10939
  return ` .systemLibrary(name: ${JSON.stringify(target.name)}, path: ${JSON.stringify(target.path)}),`;
@@ -10858,10 +11010,15 @@ function emitSwiftPackageManifest(args) {
10858
11010
  .unsafeFlags(["-Xlinker", "--strip-all"], .when(configuration: .release)),
10859
11011
  ]` : librarySettings.length > 0 ? `,
10860
11012
  linkerSettings: [${librarySettings.join(", ")}]` : "";
11013
+ const cDefines = macroSettings(target.cDefines);
11014
+ const cxxDefines = macroSettings(target.cxxDefines);
10861
11015
  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"])]`;
11016
+ `cSettings: [${cDefines} .unsafeFlags(${JSON.stringify([...args.objcExports?.flags ?? args.nativeFlags ?? [], ...native.clang.flags])})]`,
11017
+ `cxxSettings: [${cxxDefines} .unsafeFlags(${JSON.stringify(["-fno-cxx-modules", ...args.objcExports?.flags ?? args.nativeFlags ?? [], ...native.clang.cxxFlags])})]`
11018
+ ].join(", ") : [
11019
+ `cSettings: [${cDefines} .unsafeFlags(${JSON.stringify([...args.objcExports?.flags ?? args.nativeFlags ?? [], ...native?.flags ?? []])})]`,
11020
+ `cxxSettings: [${cxxDefines} .unsafeFlags(${JSON.stringify(["-fno-cxx-modules", ...args.objcExports?.flags ?? args.nativeFlags ?? [], ...native?.cxxFlags ?? []])})]`
11021
+ ].join(", ");
10865
11022
  return [
10866
11023
  ` ${kind}(`,
10867
11024
  ` name: "${target.name}",`,
@@ -10871,7 +11028,7 @@ function emitSwiftPackageManifest(args) {
10871
11028
  ...native?.clang ? [
10872
11029
  ` sources: ${JSON.stringify(native.clang.sources.map((source) => path11.posix.join(native.path, source)))},`,
10873
11030
  ` publicHeadersPath: ${JSON.stringify(path11.posix.dirname(native.clang.modulemap))},`
10874
- ] : [],
11031
+ ] : native?.flags ? [` sources: ${JSON.stringify(native.sources)},`] : [],
10875
11032
  // the native backend supplies dependency module maps without their
10876
11033
  // compiled modules. textual c++ includes keep those dependencies usable.
10877
11034
  ` ${clang ? nativeSettings : swiftSettings}${link}`,
@@ -10897,24 +11054,26 @@ function emitSwiftPackageManifest(args) {
10897
11054
  ' publicHeadersPath: "include",',
10898
11055
  ` cSettings: [.unsafeFlags(${JSON.stringify([...args.objcExports.flags.filter((flag) => flag !== "-fobjc-arc"), "-fno-objc-arc", "-Xclang", "-disable-objc-default-synthesize-properties"])})]),`
10899
11056
  ] : [],
10900
- ...[...args.native?.entries() ?? []].flatMap(
10901
- ([name2, native]) => native.late ? (native.groups ?? [
11057
+ ...[...args.native?.entries() ?? []].flatMap(([name2, native]) => {
11058
+ const late = native.late;
11059
+ const owner = targets.find((target) => target.name === name2);
11060
+ return late ? (native.groups ?? [
10902
11061
  {
10903
- name: native.late.name,
11062
+ name: late.name,
10904
11063
  sources: native.lateSources,
10905
11064
  flags: [],
10906
11065
  cxxFlags: []
10907
11066
  }
10908
11067
  ]).flatMap((group) => [
10909
11068
  ` .target(name: ${JSON.stringify(group.name)},`,
10910
- ` dependencies: ${JSON.stringify(args.native?.get(name2)?.mixed ? [] : [name2])},`,
11069
+ ` dependencies: ${JSON.stringify(native.mixed ? [] : [name2, ...late.producers])},`,
10911
11070
  ` path: ${JSON.stringify(native.clang ? "." : native.path)},`,
10912
11071
  ` sources: ${JSON.stringify(native.clang ? group.sources.map((source) => path11.posix.join(native.path, source)) : group.sources)},`,
10913
11072
  ` 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
- ),
11073
+ ` cSettings: [${macroSettings(owner?.cDefines)} .unsafeFlags(${JSON.stringify([...args.objcExports?.flags ?? args.nativeFlags ?? [], ...group.flags])})],`,
11074
+ ` cxxSettings: [${macroSettings(owner?.cxxDefines)} .unsafeFlags(${JSON.stringify(["-fno-cxx-modules", ...args.objcExports?.flags ?? args.nativeFlags ?? [], "-I", native.includeDirectory, "-I", args.headerDirectory, ...group.cxxFlags])})]),`
11075
+ ]) : [];
11076
+ }),
10918
11077
  args.cxxLanguageStandard ? ` ],
10919
11078
  cxxLanguageStandard: .${args.cxxLanguageStandard}` : " ]",
10920
11079
  ")",
@@ -14981,7 +15140,7 @@ function writeSwiftProject(layout, input, moduleRoot) {
14981
15140
  else files.set(file, prior);
14982
15141
  }
14983
15142
  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)))) {
15143
+ if (entries.some(([file]) => /\.(?:c|cc|cpp|cxx|m|mm)$/.test(file)) && (swift || input.nativeTargets?.some((value) => value.name === target.name))) {
14985
15144
  if (!swift) {
14986
15145
  const unprepared = path11.join(
14987
15146
  layout.root,
@@ -15054,8 +15213,42 @@ function writeSwiftProject(layout, input, moduleRoot) {
15054
15213
  const entries = targetEntries(target);
15055
15214
  const units = entries.filter(([file]) => /\.(?:c|cc|cpp|cxx|m|mm)$/.test(file));
15056
15215
  if (units.length === 0) continue;
15216
+ const includes = `${prefix}include/`;
15217
+ const consumers = /* @__PURE__ */ new Map();
15218
+ const reverse = /* @__PURE__ */ new Map();
15219
+ for (const [file, contents] of entries) {
15220
+ const producers2 = /* @__PURE__ */ new Set();
15221
+ const source = contents.replace(/\/\*[\s\S]*?\*\//g, "");
15222
+ for (const match of source.matchAll(
15223
+ /^\s*#\s*(?:include|import)\s*[<"]([^>"]+)[>"]/gm
15224
+ )) {
15225
+ const include2 = match[1];
15226
+ const producer = /(?:^|\/)([^/]+)-Swift\.h$/.exec(include2)?.[1];
15227
+ if (producer && targets.some((value) => value.name === producer))
15228
+ producers2.add(producer);
15229
+ const local = [
15230
+ path11.posix.join(path11.posix.dirname(file), include2),
15231
+ `${includes}${include2}`
15232
+ ].find((candidate) => input.files[candidate] !== void 0);
15233
+ if (local) {
15234
+ reverse.set(local, [...reverse.get(local) ?? [], file]);
15235
+ }
15236
+ }
15237
+ consumers.set(file, producers2);
15238
+ }
15239
+ const queue = [...consumers.keys()].filter((file) => consumers.get(file).size > 0);
15240
+ for (let index = 0; index < queue.length; index++) {
15241
+ const file = queue[index];
15242
+ for (const parent of reverse.get(file) ?? []) {
15243
+ const inherited = consumers.get(parent);
15244
+ const before = inherited.size;
15245
+ for (const producer of consumers.get(file)) inherited.add(producer);
15246
+ if (before !== inherited.size) queue.push(parent);
15247
+ }
15248
+ }
15249
+ const late = units.filter(([file]) => consumers.get(file).size > 0);
15057
15250
  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))) {
15251
+ if (settings || entries.some(([file]) => file.endsWith(".swift"))) {
15059
15252
  try {
15060
15253
  if (!settings)
15061
15254
  throw new Error(
@@ -15123,7 +15316,7 @@ function writeSwiftProject(layout, input, moduleRoot) {
15123
15316
  return relative.split("/").some((part) => part.startsWith(".")) ? path11.posix.join(HIDDEN_UNITS, relative.replaceAll(/(^|\/)\./g, "$1%2E")) : relative;
15124
15317
  };
15125
15318
  const accessorFlags = accessor ? ["-include", accessorHeader] : [];
15126
- let nativeC = false;
15319
+ let nativeC = !roots2.length && !entries.some(([file]) => file.endsWith(".swift")) && !units.some(([file]) => /\.mm?$/.test(file));
15127
15320
  if (roots2.length) {
15128
15321
  const sourceHeaders = path11.join(
15129
15322
  layout.root,
@@ -15222,7 +15415,13 @@ export *
15222
15415
  )
15223
15416
  ];
15224
15417
  const cxx = /\.(?:cc|cpp|cxx|mm)$/.test(file);
15225
- const identity = createHash9("sha256").update(JSON.stringify([cxx, perFile])).digest("hex").slice(0, 12);
15418
+ const identity = createHash9("sha256").update(
15419
+ JSON.stringify([
15420
+ cxx,
15421
+ perFile,
15422
+ ...nativeC && !roots2.length ? [(consumers.get(file)?.size ?? 0) > 0] : []
15423
+ ])
15424
+ ).digest("hex").slice(0, 12);
15226
15425
  const group = groups.get(identity) ?? {
15227
15426
  name: `${target.name}${nativeC ? "Native" : "Swift"}Implementation_${identity}`,
15228
15427
  sources: [],
@@ -15257,6 +15456,31 @@ export *
15257
15456
  accessor.body
15258
15457
  );
15259
15458
  }
15459
+ if (nativeC && !roots2.length) {
15460
+ const lateSources = new Set(late.map(([file]) => unitSource(file)));
15461
+ const owner = [...groups.values()].find(
15462
+ (group) => group.sources.every((source) => !lateSources.has(source))
15463
+ );
15464
+ const implementations = [...groups.values()].filter((group) => group !== owner);
15465
+ native.set(target.name, {
15466
+ path: target.path,
15467
+ includeDirectory: include2,
15468
+ sources: owner?.sources ?? [],
15469
+ lateSources: implementations.flatMap((group) => group.sources),
15470
+ flags: owner?.flags ?? flags,
15471
+ cxxFlags: owner?.cxxFlags ?? flags,
15472
+ ...implementations.length ? {
15473
+ groups: implementations,
15474
+ late: {
15475
+ name: `${target.name}NativeImplementation`,
15476
+ producers: [
15477
+ ...new Set(late.flatMap(([file]) => [...consumers.get(file)]))
15478
+ ].sort()
15479
+ }
15480
+ } : {}
15481
+ });
15482
+ continue;
15483
+ }
15260
15484
  if (nativeC) {
15261
15485
  const modulemaps = Object.entries(settings.productHeaders).filter(
15262
15486
  ([product2]) => product2.endsWith("/Modules/module.modulemap")
@@ -15327,40 +15551,6 @@ export *
15327
15551
  }
15328
15552
  continue;
15329
15553
  }
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
15554
  native.set(target.name, {
15365
15555
  path: target.path,
15366
15556
  includeDirectory: path11.join(layout.root, includes),