Files
xtool-mirror/Sources/XKit/Signer/Signer.swift
Brosseau Valentin a2875dd9ac build: fix compiler crash in release due to unimplemented() (#432)
## What does this PR do?

Fixes #431. Since #389, `swift build -c release` crashes the compiler on
Linux x86_64. The two `unimplemented()` calls in `UnimplementedSigner`
(`Sources/XKit/Signer/Signer.swift`) set it off:
- they pick the parameter-pack overload of `unimplemented`, with an
empty pack;
- that call, from an `async` function, hits a Swift compiler bug,
reported as swiftlang/swift#94055: `CoroSplitPass` emits an invalid GEP,
and LLVM's FunctionAttrs pass then crashes.

This PR replaces the two calls with what `unimplemented()` does when
called: `reportIssue(...)`, then `throw UnimplementedFailure(...)`. The
test dependency keeps the same behavior, and nothing changes outside it.

## How was it tested?

In upstream's own image (the `build-limd` stage of the `Dockerfile`, on
`swift:6.4.2-jammy`), x86_64:
- `swift build -c release --product xtool`: builds, and `xtool --help`
runs. Without this change it crashes, as described in #431.
- `swift test`: `Test run with 61 tests in 7 suites passed`.
- The bisect, the reduction to these two calls, and the minimal
reproducer are in #431 and swiftlang/swift#94055.

Not tested: macOS, arm64, signing on a device with this exact commit.
swiftlint was not run.

## AI tool usage

How much of the code in this PR was AI-assisted? (check one)

- [ ] **0** - No AI was used to write code
- [x] **1** - I was assisted by AI in writing code. I reviewed the
finished result.
- [ ] **2** - I set the AI going and left it to it; nobody has read the
result - no review, or AI review only
2026-11-07 20:21:34 -05:00

51 lines
1.4 KiB
Swift

import Foundation
import Dependencies
public enum SignerIdentity: Sendable {
case real(Certificate, PrivateKey)
case adhoc
}
public protocol Signer: Sendable {
// entitlementMapping is [bundle url] -> [plist data]
func sign(
app: URL,
identity: SignerIdentity,
entitlementMapping: [URL: Data],
deep: Bool,
progress: @escaping @Sendable (Double?) -> Void
) async throws
func analyze(executable: URL) async throws -> Data?
}
private enum SignerDependencyKey: DependencyKey {
static var liveValue: any Signer { RCodesignSigner() }
static var testValue: any Signer { UnimplementedSigner() }
}
extension DependencyValues {
public var signer: any Signer {
get { self[SignerDependencyKey.self] }
set { self[SignerDependencyKey.self] = newValue }
}
}
private struct UnimplementedSigner: Signer {
func sign(
app: URL,
identity: SignerIdentity,
entitlementMapping: [URL: Data],
deep: Bool,
progress: @escaping @Sendable (Double?) -> Void
) async throws {
reportIssue("Unimplemented: Signer.sign")
throw UnimplementedFailure(description: "Signer.sign")
}
func analyze(executable: URL) async throws -> Data? {
reportIssue("Unimplemented: Signer.analyze")
throw UnimplementedFailure(description: "Signer.analyze")
}
}