Skip to content

Commit 15d47d8

Browse files
authored
Merge pull request swiftlang#325 from compnerd/extensions
SKCore: support executable extensions on different platforms
2 parents 6df9c68 + 3e32ce6 commit 15d47d8

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

Sources/SKCore/Toolchain.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,18 +127,20 @@ extension Toolchain {
127127

128128
var foundAny = false
129129

130-
let clangPath = binPath.appending(component: "clang")
130+
let execExt = Platform.currentPlatform?.executableExtension ?? ""
131+
132+
let clangPath = binPath.appending(component: "clang\(execExt)")
131133
if fs.isExecutableFile(clangPath) {
132134
self.clang = clangPath
133135
foundAny = true
134136
}
135-
let clangdPath = binPath.appending(component: "clangd")
137+
let clangdPath = binPath.appending(component: "clangd\(execExt)")
136138
if fs.isExecutableFile(clangdPath) {
137139
self.clangd = clangdPath
138140
foundAny = true
139141
}
140142

141-
let swiftcPath = binPath.appending(component: "swiftc")
143+
let swiftcPath = binPath.appending(component: "swiftc\(execExt)")
142144
if fs.isExecutableFile(swiftcPath) {
143145
self.swiftc = swiftcPath
144146
foundAny = true

Sources/SKSupport/Platform.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ extension Platform {
1919
switch self {
2020
case .darwin: return ".dylib"
2121
case .linux, .android: return ".so"
22+
case .windows: return ".dll"
23+
}
24+
}
25+
26+
public var executableExtension: String {
27+
switch self {
28+
case .windows: return ".exe"
29+
case .linux, .android, .darwin: return ""
2230
}
2331
}
2432
}

Tests/SKCoreTests/ToolchainRegistryTests.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -516,14 +516,16 @@ private func makeToolchain(
516516
}
517517
}
518518

519+
let execExt = Platform.currentPlatform?.executableExtension ?? ""
520+
519521
if clang {
520-
makeExec(binPath.appending(component: "clang"))
522+
makeExec(binPath.appending(component: "clang\(execExt)"))
521523
}
522524
if clangd {
523-
makeExec(binPath.appending(component: "clangd"))
525+
makeExec(binPath.appending(component: "clangd\(execExt)"))
524526
}
525527
if swiftc {
526-
makeExec(binPath.appending(component: "swiftc"))
528+
makeExec(binPath.appending(component: "swiftc\(execExt)"))
527529
}
528530

529531
let dylibExt = Platform.currentPlatform?.dynamicLibraryExtension ?? ".so"

0 commit comments

Comments
 (0)