refactor(apple): give snapshot and fold one native-build owner
Summary
Moves the TS native-build cache, lock, toolchain-identity, and build-host code out of snapshot-source into a domain-neutral packages/platform-apple/src/native-build module group, so fold-helper-cache.ts no longer imports the snapshot bridge's deadlines, errors, host construction, or host types to compile a binary that needs none of them.
native-build/{cache,deadline,host,toolchain-identity,errors}.tscarry the one cache, one lock, and one toolchain-identity probe every runtime clang build in this package shares.NativeBuildHostexposes only file access, command execution, locking, and process identity — no bridge socket start/connect, no target-process inspection.NativeBuildErroris domain-neutral (cancelled/timeout/unsupported);snapshot-source/errors.tsanddeadline.tsmap it ontoSnapshotSourceErrorat the boundary, andfoldable/fold-helper-cache.tsmaps it onto its ownfold-helper-build-failedAppError, preserving both public error shapes byte for byte.fold-helper-cache.tsdrops constructing a fullSnapshotSourceHost(and overridingrun) forcreateNativeBuildHost(runAppleToolCommand), the narrow host the compile actually needs.snapshot-source/host.tsdrops its own copy of lock acquisition for the shared one;cache-identity.tskeeps only the bridge'ssimulatorRuntimeaddition, with retry/probe/cancellation logic moved tonative-build/toolchain-identity.tsalong with its tests.- No Swift changes; cache-key inputs, hash algorithm, manifest schema, and lock semantics are unchanged — only file/module ownership moved.
Closes #2970. 14 files touched.
Validation
Tested commit: baa48fa8ba5f10cff86a2aa69483bf5c399d3f0f.
pnpm check:affected --run: 277 test files / 1823 tests passed, including the Darwin conformance suites (native-runtime.test.ts, fold-helper's -Werror compile gate) that do genuine xcrun/clang compiles against the real toolchain.
Live device validation (production code path, no simulator needed — compilation targets the iphonesimulator SDK, not a booted device):
ensureSnapshotBridgeBinary: cache MISS build 1773ms, then cache HIT reuse 95ms, identical output path both times.ensureFoldHelperBinary: cache MISS build 297ms, then cache HIT reuse 102ms, identical output path both times.- Cancellation contract: a pre-aborted
ensureFoldHelperBinarycall rejects withisRequestCanceledError(error) === true(this is the fix in this commit: a fold or toolchain-probe cancellation now keepsreason: 'request_canceled'the way it did before the native-build split).
No simulator was created: the change doesn't alter when the native artifact is built or reused (cache-key inputs, hash algorithm, manifest schema, and lock semantics are preserved unchanged — only module ownership moved), confirmed by inspection and by the unit + real-compile tests above producing byte-identical cache behavior on both paths.
No unresolved risk.