Skip to content

Commit 45b94b7

Browse files
authored
Merge pull request #307 from tayloraswift/multiple-toolchains
Multiple toolchains
2 parents 42648f1 + 9e9b3b4 commit 45b94b7

File tree

6 files changed

+91
-76
lines changed

6 files changed

+91
-76
lines changed

Package.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ let package:Package = .init(
6464
.library(name: "Symbols", targets: ["Symbols"]),
6565

6666
.library(name: "System", targets: ["System"]),
67+
.library(name: "System_ArgumentParser", targets: ["System_ArgumentParser"]),
6768

6869
.library(name: "UA", targets: ["UA"]),
6970

Sources/SymbolGraphBuilder/Toolchains/SSGC.Toolchain.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,14 @@ extension SSGC.Toolchain
449449
compiler; see https://github.com/apple/swift/issues/68767.
450450
""")
451451
}
452+
catch SystemProcessError.exit(134, _)
453+
{
454+
print("""
455+
Failed to dump symbols for module '\(id)' due to SIGABRT \
456+
from 'swift symbolgraph-extract'. This is a known bug in the Apple Swift \
457+
compiler; see https://github.com/swiftlang/swift/issues/75318.
458+
""")
459+
}
452460
catch SystemProcessError.exit(let code, let invocation)
453461
{
454462
throw SSGC.PackageBuildError.swift_symbolgraph_extract(code, invocation)

Sources/UnidocClient/Unidoc.Client.swift

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,9 @@ extension Unidoc
1919
let executablePath:String?
2020

2121
public
22-
let swiftRuntime:String?
23-
public
24-
let swiftPath:String?
25-
public
26-
let swiftSDK:SSGC.AppleSDK?
22+
let authorization:String?
2723
public
2824
let pretty:Bool
29-
public
30-
let authorization:String?
3125

3226
public
3327
let http:Protocol
@@ -36,11 +30,8 @@ extension Unidoc
3630

3731
@inlinable public
3832
init(
39-
swiftRuntime:String?,
40-
swiftPath:String?,
41-
swiftSDK:SSGC.AppleSDK?,
42-
pretty:Bool,
4333
authorization:String?,
34+
pretty:Bool,
4435
http:Protocol,
4536
port:Int)
4637
{
@@ -56,11 +47,8 @@ extension Unidoc
5647
self.executablePath = nil
5748
#endif
5849

59-
self.swiftRuntime = swiftRuntime
60-
self.swiftPath = swiftPath
61-
self.swiftSDK = swiftSDK
62-
self.pretty = pretty
6350
self.authorization = authorization
51+
self.pretty = pretty
6452
self.http = http
6553
self.port = port
6654
}
@@ -144,6 +132,7 @@ extension Unidoc.Client<HTTP.Client2>
144132
labels:Unidoc.BuildLabels,
145133
action:Unidoc.LinkerAction,
146134
remove:Bool = false,
135+
with toolchain:Unidoc.Toolchain,
147136
cache:FilePath? = nil) async throws -> Bool
148137
{
149138
if let cache:FilePath, remove
@@ -218,17 +207,19 @@ extension Unidoc.Client<HTTP.Client2>
218207
{
219208
arguments.append("--pretty")
220209
}
221-
if let path:String = self.swiftRuntime
210+
if let usr:FilePath.Directory = toolchain.usr
222211
{
212+
let lib:FilePath.Directory = usr / "lib"
213+
223214
arguments.append("--swift-runtime")
224-
arguments.append("\(path)")
225-
}
226-
if let path:String = self.swiftPath
227-
{
215+
arguments.append("\(lib)")
216+
217+
let swift:FilePath.Directory = usr / "bin" / "swift"
218+
228219
arguments.append("--swift")
229-
arguments.append("\(path)")
220+
arguments.append("\(swift)")
230221
}
231-
if let sdk:SSGC.AppleSDK = self.swiftSDK
222+
if let sdk:SSGC.AppleSDK = toolchain.sdk
232223
{
233224
arguments.append("--sdk")
234225
arguments.append("\(sdk)")
@@ -293,12 +284,14 @@ extension Unidoc.Client<HTTP.Client2>
293284

294285
public
295286
func buildAndUpload(local symbol:Symbol.Package,
296-
search:FilePath?,
297-
type:SSGC.ProjectType) async throws
287+
search:FilePath.Directory?,
288+
type:SSGC.ProjectType,
289+
with toolchain:Unidoc.Toolchain) async throws
298290
{
299291
let object:SymbolGraphObject<Void> = try await self.build(local: symbol,
300292
search: search,
301-
type: type)
293+
type: type,
294+
with: toolchain)
302295

303296
try await self.connect { try await $0.upload(object) }
304297

@@ -312,12 +305,14 @@ extension Unidoc.Client<HTTP.Client1>
312305
{
313306
public
314307
func buildAndUpload(local symbol:Symbol.Package,
315-
search:FilePath?,
316-
type:SSGC.ProjectType) async throws
308+
search:FilePath.Directory?,
309+
type:SSGC.ProjectType,
310+
with toolchain:Unidoc.Toolchain) async throws
317311
{
318312
let object:SymbolGraphObject<Void> = try await self.build(local: symbol,
319313
search: search,
320-
type: type)
314+
type: type,
315+
with: toolchain)
321316

322317
try await self.connect { try await $0.upload(object) }
323318

@@ -331,8 +326,9 @@ extension Unidoc.Client
331326
{
332327
private
333328
func build(local symbol:Symbol.Package,
334-
search:FilePath?,
335-
type:SSGC.ProjectType) async throws -> SymbolGraphObject<Void>
329+
search:FilePath.Directory?,
330+
type:SSGC.ProjectType,
331+
with toolchain:Unidoc.Toolchain) async throws -> SymbolGraphObject<Void>
336332
{
337333
let workspace:SSGC.Workspace = try .create(at: ".ssgc")
338334
let docs:FilePath = workspace.location / "docs.bson"
@@ -349,22 +345,24 @@ extension Unidoc.Client
349345
{
350346
arguments.append("--pretty")
351347
}
352-
if let path:String = self.swiftRuntime
348+
if let usr:FilePath.Directory = toolchain.usr
353349
{
350+
let lib:FilePath.Directory = usr / "lib"
351+
354352
arguments.append("--swift-runtime")
355-
arguments.append("\(path)")
356-
}
357-
if let path:String = self.swiftPath
358-
{
353+
arguments.append("\(lib)")
354+
355+
let swift:FilePath.Directory = usr / "bin" / "swift"
356+
359357
arguments.append("--swift")
360-
arguments.append("\(path)")
358+
arguments.append("\(swift)")
361359
}
362-
if let sdk:SSGC.AppleSDK = self.swiftSDK
360+
if let sdk:SSGC.AppleSDK = toolchain.sdk
363361
{
364362
arguments.append("--sdk")
365363
arguments.append("\(sdk)")
366364
}
367-
if let search:FilePath = search
365+
if let search:FilePath.Directory
368366
{
369367
arguments.append("--search-path")
370368
arguments.append("\(search)")
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import SymbolGraphBuilder
2+
import System
3+
4+
extension Unidoc
5+
{
6+
@frozen public
7+
struct Toolchain:Equatable, Sendable
8+
{
9+
public
10+
let usr:FilePath.Directory?
11+
public
12+
let sdk:SSGC.AppleSDK?
13+
14+
@inlinable public
15+
init(usr:FilePath.Directory?, sdk:SSGC.AppleSDK? = nil)
16+
{
17+
self.usr = usr
18+
self.sdk = sdk
19+
}
20+
}
21+
}

Sources/unidoc-build/Main.Local.swift

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import ArgumentParser
22
import HTTP
3+
import NIOPosix
34
import SymbolGraphCompiler
45
import Symbols
56
import System
7+
import UnidocClient
68

79
extension Main
810
{
@@ -22,27 +24,21 @@ extension Main
2224
var port:Int = 8080
2325

2426
@Option(
25-
name: [.customLong("swift-runtime"), .customShort("r")],
26-
help: "The path to the Swift runtime directory, usually ending in /usr/lib",
27+
name: [.customLong("swift-toolchain"), .customShort("u")],
28+
help: "The path to a Swift toolchain directory, usually ending in 'usr'",
2729
completion: .directory)
28-
var swiftRuntime:String?
29-
30-
@Option(
31-
name: [.customLong("swift"), .customShort("s")],
32-
help: "The path to the Swift toolchain",
33-
completion: .file(extensions: []))
34-
var swiftPath:String?
30+
var toolchain:FilePath.Directory?
3531

3632
@Option(
3733
name: [.customLong("swift-sdk"), .customShort("k")],
3834
help: "The Swift SDK to use")
39-
var swiftSDK:SSGC.AppleSDK?
35+
var sdk:SSGC.AppleSDK?
4036

4137
@Option(
4238
name: [.customLong("input"), .customShort("I")],
4339
help: "The path to a directory containing the project to build",
4440
completion: .directory)
45-
var input:String?
41+
var input:FilePath.Directory?
4642

4743

4844
@Flag(
@@ -63,16 +59,29 @@ extension Main.Local:AsyncParsableCommand
6359
mutating
6460
func run() async throws
6561
{
62+
let threads:MultiThreadedEventLoopGroup = .init(numberOfThreads: 2)
63+
6664
#if os(macOS)
6765

6866
// Guess the SDK if not specified.
69-
self.swiftSDK = self.swiftSDK ?? .macOS
67+
self.sdk = self.sdk ?? .macOS
7068

7169
#endif
7270

73-
let search:FilePath? = self.input.map(FilePath.init(_:))
74-
let type:SSGC.ProjectType = self.book ? .book : .package
75-
let unidoc:Unidoc.Client<HTTP.Client1> = try .init(from: self)
76-
try await unidoc.buildAndUpload(local: self.project, search: search, type: type)
71+
let toolchain:Unidoc.Toolchain = .init(
72+
usr: self.toolchain,
73+
sdk: self.sdk)
74+
75+
let unidoc:Unidoc.Client<HTTP.Client1> = .init(authorization: nil,
76+
pretty: self.pretty,
77+
http: .init(threads: threads, niossl: nil, remote: self.host),
78+
port: self.port)
79+
80+
print("Connecting to \(self.host):\(self.port)...")
81+
82+
try await unidoc.buildAndUpload(local: self.project,
83+
search: self.input,
84+
type: self.book ? .book : .package,
85+
with: toolchain)
7786
}
7887
}

Sources/unidoc-build/Unidoc.Client (ext).swift

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)