Skip to content

Commit

Permalink
Merge pull request #307 from tayloraswift/multiple-toolchains
Browse files Browse the repository at this point in the history
Multiple toolchains
  • Loading branch information
tayloraswift authored Jul 18, 2024
2 parents 42648f1 + 9e9b3b4 commit 45b94b7
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 76 deletions.
1 change: 1 addition & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ let package:Package = .init(
.library(name: "Symbols", targets: ["Symbols"]),

.library(name: "System", targets: ["System"]),
.library(name: "System_ArgumentParser", targets: ["System_ArgumentParser"]),

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

Expand Down
8 changes: 8 additions & 0 deletions Sources/SymbolGraphBuilder/Toolchains/SSGC.Toolchain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,14 @@ extension SSGC.Toolchain
compiler; see https://github.com/apple/swift/issues/68767.
""")
}
catch SystemProcessError.exit(134, _)
{
print("""
Failed to dump symbols for module '\(id)' due to SIGABRT \
from 'swift symbolgraph-extract'. This is a known bug in the Apple Swift \
compiler; see https://github.com/swiftlang/swift/issues/75318.
""")
}
catch SystemProcessError.exit(let code, let invocation)
{
throw SSGC.PackageBuildError.swift_symbolgraph_extract(code, invocation)
Expand Down
74 changes: 36 additions & 38 deletions Sources/UnidocClient/Unidoc.Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,9 @@ extension Unidoc
let executablePath:String?

public
let swiftRuntime:String?
public
let swiftPath:String?
public
let swiftSDK:SSGC.AppleSDK?
let authorization:String?
public
let pretty:Bool
public
let authorization:String?

public
let http:Protocol
Expand All @@ -36,11 +30,8 @@ extension Unidoc

@inlinable public
init(
swiftRuntime:String?,
swiftPath:String?,
swiftSDK:SSGC.AppleSDK?,
pretty:Bool,
authorization:String?,
pretty:Bool,
http:Protocol,
port:Int)
{
Expand All @@ -56,11 +47,8 @@ extension Unidoc
self.executablePath = nil
#endif

self.swiftRuntime = swiftRuntime
self.swiftPath = swiftPath
self.swiftSDK = swiftSDK
self.pretty = pretty
self.authorization = authorization
self.pretty = pretty
self.http = http
self.port = port
}
Expand Down Expand Up @@ -144,6 +132,7 @@ extension Unidoc.Client<HTTP.Client2>
labels:Unidoc.BuildLabels,
action:Unidoc.LinkerAction,
remove:Bool = false,
with toolchain:Unidoc.Toolchain,
cache:FilePath? = nil) async throws -> Bool
{
if let cache:FilePath, remove
Expand Down Expand Up @@ -218,17 +207,19 @@ extension Unidoc.Client<HTTP.Client2>
{
arguments.append("--pretty")
}
if let path:String = self.swiftRuntime
if let usr:FilePath.Directory = toolchain.usr
{
let lib:FilePath.Directory = usr / "lib"

arguments.append("--swift-runtime")
arguments.append("\(path)")
}
if let path:String = self.swiftPath
{
arguments.append("\(lib)")

let swift:FilePath.Directory = usr / "bin" / "swift"

arguments.append("--swift")
arguments.append("\(path)")
arguments.append("\(swift)")
}
if let sdk:SSGC.AppleSDK = self.swiftSDK
if let sdk:SSGC.AppleSDK = toolchain.sdk
{
arguments.append("--sdk")
arguments.append("\(sdk)")
Expand Down Expand Up @@ -293,12 +284,14 @@ extension Unidoc.Client<HTTP.Client2>

public
func buildAndUpload(local symbol:Symbol.Package,
search:FilePath?,
type:SSGC.ProjectType) async throws
search:FilePath.Directory?,
type:SSGC.ProjectType,
with toolchain:Unidoc.Toolchain) async throws
{
let object:SymbolGraphObject<Void> = try await self.build(local: symbol,
search: search,
type: type)
type: type,
with: toolchain)

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

Expand All @@ -312,12 +305,14 @@ extension Unidoc.Client<HTTP.Client1>
{
public
func buildAndUpload(local symbol:Symbol.Package,
search:FilePath?,
type:SSGC.ProjectType) async throws
search:FilePath.Directory?,
type:SSGC.ProjectType,
with toolchain:Unidoc.Toolchain) async throws
{
let object:SymbolGraphObject<Void> = try await self.build(local: symbol,
search: search,
type: type)
type: type,
with: toolchain)

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

Expand All @@ -331,8 +326,9 @@ extension Unidoc.Client
{
private
func build(local symbol:Symbol.Package,
search:FilePath?,
type:SSGC.ProjectType) async throws -> SymbolGraphObject<Void>
search:FilePath.Directory?,
type:SSGC.ProjectType,
with toolchain:Unidoc.Toolchain) async throws -> SymbolGraphObject<Void>
{
let workspace:SSGC.Workspace = try .create(at: ".ssgc")
let docs:FilePath = workspace.location / "docs.bson"
Expand All @@ -349,22 +345,24 @@ extension Unidoc.Client
{
arguments.append("--pretty")
}
if let path:String = self.swiftRuntime
if let usr:FilePath.Directory = toolchain.usr
{
let lib:FilePath.Directory = usr / "lib"

arguments.append("--swift-runtime")
arguments.append("\(path)")
}
if let path:String = self.swiftPath
{
arguments.append("\(lib)")

let swift:FilePath.Directory = usr / "bin" / "swift"

arguments.append("--swift")
arguments.append("\(path)")
arguments.append("\(swift)")
}
if let sdk:SSGC.AppleSDK = self.swiftSDK
if let sdk:SSGC.AppleSDK = toolchain.sdk
{
arguments.append("--sdk")
arguments.append("\(sdk)")
}
if let search:FilePath = search
if let search:FilePath.Directory
{
arguments.append("--search-path")
arguments.append("\(search)")
Expand Down
21 changes: 21 additions & 0 deletions Sources/UnidocClient/Unidoc.Toolchain.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import SymbolGraphBuilder
import System

extension Unidoc
{
@frozen public
struct Toolchain:Equatable, Sendable
{
public
let usr:FilePath.Directory?
public
let sdk:SSGC.AppleSDK?

@inlinable public
init(usr:FilePath.Directory?, sdk:SSGC.AppleSDK? = nil)
{
self.usr = usr
self.sdk = sdk
}
}
}
41 changes: 25 additions & 16 deletions Sources/unidoc-build/Main.Local.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import ArgumentParser
import HTTP
import NIOPosix
import SymbolGraphCompiler
import Symbols
import System
import UnidocClient

extension Main
{
Expand All @@ -22,27 +24,21 @@ extension Main
var port:Int = 8080

@Option(
name: [.customLong("swift-runtime"), .customShort("r")],
help: "The path to the Swift runtime directory, usually ending in /usr/lib",
name: [.customLong("swift-toolchain"), .customShort("u")],
help: "The path to a Swift toolchain directory, usually ending in 'usr'",
completion: .directory)
var swiftRuntime:String?

@Option(
name: [.customLong("swift"), .customShort("s")],
help: "The path to the Swift toolchain",
completion: .file(extensions: []))
var swiftPath:String?
var toolchain:FilePath.Directory?

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

@Option(
name: [.customLong("input"), .customShort("I")],
help: "The path to a directory containing the project to build",
completion: .directory)
var input:String?
var input:FilePath.Directory?


@Flag(
Expand All @@ -63,16 +59,29 @@ extension Main.Local:AsyncParsableCommand
mutating
func run() async throws
{
let threads:MultiThreadedEventLoopGroup = .init(numberOfThreads: 2)

#if os(macOS)

// Guess the SDK if not specified.
self.swiftSDK = self.swiftSDK ?? .macOS
self.sdk = self.sdk ?? .macOS

#endif

let search:FilePath? = self.input.map(FilePath.init(_:))
let type:SSGC.ProjectType = self.book ? .book : .package
let unidoc:Unidoc.Client<HTTP.Client1> = try .init(from: self)
try await unidoc.buildAndUpload(local: self.project, search: search, type: type)
let toolchain:Unidoc.Toolchain = .init(
usr: self.toolchain,
sdk: self.sdk)

let unidoc:Unidoc.Client<HTTP.Client1> = .init(authorization: nil,
pretty: self.pretty,
http: .init(threads: threads, niossl: nil, remote: self.host),
port: self.port)

print("Connecting to \(self.host):\(self.port)...")

try await unidoc.buildAndUpload(local: self.project,
search: self.input,
type: self.book ? .book : .package,
with: toolchain)
}
}
22 changes: 0 additions & 22 deletions Sources/unidoc-build/Unidoc.Client (ext).swift

This file was deleted.

0 comments on commit 45b94b7

Please sign in to comment.