Skip to content

Commit 38c9387

Browse files
authored
Merge pull request swiftlang#1278 from compnerd/critical-condition
SwiftDriver: avoid use of `fatalError` in the driver
2 parents d8b266c + 0b8e706 commit 38c9387

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

Sources/SwiftDriver/Jobs/WebAssemblyToolchain+LinkerSupport.swift

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,13 @@ extension WebAssemblyToolchain {
115115
commandLine.appendPath(path)
116116
}
117117

118-
// Link the standard library.
119-
let linkFilePath: VirtualPath = VirtualPath.lookup(targetInfo.runtimeResourcePath.path)
120-
.appending(
121-
components: targetTriple.platformName() ?? "",
122-
"static-executable-args.lnk"
123-
)
124-
118+
// Link the standard library and dependencies.
119+
let linkFilePath: VirtualPath =
120+
VirtualPath.lookup(targetInfo.runtimeResourcePath.path)
121+
.appending(components: targetTriple.platformName() ?? "",
122+
"static-executable-args.lnk")
125123
guard try fileSystem.exists(linkFilePath) else {
126-
fatalError("\(linkFilePath) not found")
124+
throw Error.missingExternalDependency(linkFilePath.name)
127125
}
128126
commandLine.append(.responseFilePath(linkFilePath))
129127

@@ -133,7 +131,7 @@ extension WebAssemblyToolchain {
133131
// Delegate to Clang for sanitizers. It will figure out the correct linker
134132
// options.
135133
guard sanitizers.isEmpty else {
136-
fatalError("WebAssembly does not support sanitizers, but a runtime library was found")
134+
throw Error.sanitizersUnsupportedForTarget(targetTriple.triple)
137135
}
138136

139137
guard !parsedOptions.hasArgument(.profileGenerate) else {

Sources/SwiftDriver/Toolchains/WebAssemblyToolchain.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public final class WebAssemblyToolchain: Toolchain {
2424
case dynamicLibrariesUnsupportedForTarget(String)
2525
case sanitizersUnsupportedForTarget(String)
2626
case profilingUnsupportedForTarget(String)
27+
case missingExternalDependency(String)
2728

2829
public var description: String {
2930
switch self {
@@ -35,6 +36,8 @@ public final class WebAssemblyToolchain: Toolchain {
3536
return "sanitizers are unsupported for target '\(triple)'"
3637
case .profilingUnsupportedForTarget(let triple):
3738
return "profiling is unsupported for target '\(triple)'"
39+
case .missingExternalDependency(let dependency):
40+
return "missing external dependency '\(dependency)'"
3841
}
3942
}
4043
}

0 commit comments

Comments
 (0)