Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.2.0
6.2.3
18 changes: 14 additions & 4 deletions Sources/PackageModel/SwiftSDKs/SwiftSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ public struct SwiftSDK: Equatable {
/// deserialization.
public private(set) var toolset: Toolset

public private(set) var swiftSDKManifest: Basics.AbsolutePath?

/// The paths associated with a Swift SDK. The Path type can be a `String`
/// to encapsulate the arguments for the `SwiftSDKConfigurationStore.configure`
/// function, or can be a fully-realized `AbsolutePath` when deserialized from a configuration.
Expand Down Expand Up @@ -499,12 +501,14 @@ public struct SwiftSDK: Equatable {
hostTriple: Triple? = nil,
targetTriple: Triple? = nil,
toolset: Toolset,
swiftSDKManifest: Basics.AbsolutePath? = nil,
pathsConfiguration: PathsConfiguration<Basics.AbsolutePath>,
xctestSupport: XCTestSupport = .supported
) {
self.hostTriple = hostTriple
self.targetTriple = targetTriple
self.toolset = toolset
self.swiftSDKManifest = swiftSDKManifest
self.pathsConfiguration = pathsConfiguration
self.xctestSupport = xctestSupport
}
Expand Down Expand Up @@ -942,7 +946,8 @@ extension SwiftSDK {
targetTriple: triple,
properties: properties,
toolset: toolset,
swiftSDKDirectory: swiftSDKDirectory
swiftSDKDirectory: swiftSDKDirectory,
swiftSDKManifest: path,
)
}

Expand Down Expand Up @@ -973,7 +978,8 @@ extension SwiftSDK {
targetTriple: triple,
properties: properties,
toolset: toolset,
swiftSDKDirectory: swiftSDKDirectory
swiftSDKDirectory: swiftSDKDirectory,
swiftSDKManifest: path,
)
}
default:
Expand All @@ -991,11 +997,13 @@ extension SwiftSDK {
targetTriple: Triple,
properties: SwiftSDKMetadataV4.TripleProperties,
toolset: Toolset = .init(),
swiftSDKDirectory: Basics.AbsolutePath? = nil
swiftSDKDirectory: Basics.AbsolutePath? = nil,
swiftSDKManifest: Basics.AbsolutePath? = nil,
) throws {
self.init(
targetTriple: targetTriple,
toolset: toolset,
swiftSDKManifest: swiftSDKManifest,
pathsConfiguration: try .init(properties, swiftSDKDirectory: swiftSDKDirectory)
)
}
Expand All @@ -1010,11 +1018,13 @@ extension SwiftSDK {
targetTriple: Triple,
properties: SerializedDestinationV3.TripleProperties,
toolset: Toolset = .init(),
swiftSDKDirectory: Basics.AbsolutePath? = nil
swiftSDKDirectory: Basics.AbsolutePath? = nil,
swiftSDKManifest: Basics.AbsolutePath? = nil,
) throws {
self.init(
targetTriple: targetTriple,
toolset: toolset,
swiftSDKManifest: swiftSDKManifest,
pathsConfiguration: try .init(properties, swiftSDKDirectory: swiftSDKDirectory)
)
}
Expand Down
2 changes: 2 additions & 0 deletions Sources/PackageModel/Toolchain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public protocol Toolchain {
/// Additional flags to be passed to the C++ compiler.
@available(*, deprecated, message: "use extraFlags.cxxCompilerFlags instead")
var extraCPPFlags: [String] { get }

var swiftSDK: SwiftSDK { get }
}

extension Toolchain {
Expand Down
82 changes: 49 additions & 33 deletions Sources/SwiftBuildSupport/SwiftBuildSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -703,36 +703,45 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem {
}

private func makeRunDestination() -> SwiftBuild.SWBRunDestinationInfo {
let platformName: String
let sdkName: String
if self.buildParameters.triple.isAndroid() {
// Android triples are identified by the environment part of the triple
platformName = "android"
sdkName = platformName
} else if self.buildParameters.triple.isWasm {
// Swift Build uses webassembly instead of wasi as the platform name
platformName = "webassembly"
sdkName = platformName
if let sdkManifestPath = self.buildParameters.toolchain.swiftSDK.swiftSDKManifest {
return SwiftBuild.SWBRunDestinationInfo(
buildTarget: .swiftSDK(sdkManifestPath: sdkManifestPath.pathString, triple: self.buildParameters.triple.tripleString),
targetArchitecture: buildParameters.triple.archName,
supportedArchitectures: [],
disableOnlyActiveArch: (buildParameters.architectures?.count ?? 1) > 1,
)
} else {
platformName = self.buildParameters.triple.darwinPlatform?.platformName ?? self.buildParameters.triple.osNameUnversioned
sdkName = platformName
}
let platformName: String
let sdkName: String

let sdkVariant: String?
if self.buildParameters.triple.environment == .macabi {
sdkVariant = "iosmac"
} else {
sdkVariant = nil
}
if self.buildParameters.triple.isAndroid() {
// Android triples are identified by the environment part of the triple
platformName = "android"
sdkName = platformName
} else {
platformName = self.buildParameters.triple.darwinPlatform?.platformName ?? self.buildParameters.triple.osNameUnversioned
sdkName = platformName
}

return SwiftBuild.SWBRunDestinationInfo(
platform: platformName,
sdk: sdkName,
sdkVariant: sdkVariant,
targetArchitecture: buildParameters.triple.archName,
supportedArchitectures: [],
disableOnlyActiveArch: (buildParameters.architectures?.count ?? 1) > 1
)
let sdkVariant: String?
if self.buildParameters.triple.environment == .macabi {
sdkVariant = "iosmac"
} else {
sdkVariant = nil
}

return SwiftBuild.SWBRunDestinationInfo(
buildTarget: .toolchainSDK(
platform: platformName,
sdk: sdkName,
sdkVariant: sdkVariant
),
targetArchitecture: buildParameters.triple.archName,
supportedArchitectures: [],
disableOnlyActiveArch: (buildParameters.architectures?.count ?? 1) > 1,
hostTargetedPlatform: nil
)
}
}

internal func makeBuildParameters(
Expand Down Expand Up @@ -867,12 +876,19 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem {
+ buildParameters.flags.swiftCompilerFlags.map { $0.shellEscaped() }
).joined(separator: " ")

settings["OTHER_LDFLAGS"] = (
verboseFlag + // clang will be invoked to link so the verbose flag is valid for it
["$(inherited)"]
+ buildParameters.toolchain.extraFlags.linkerFlags.asSwiftcLinkerFlags().map { $0.shellEscaped() }
+ buildParameters.flags.linkerFlags.asSwiftcLinkerFlags().map { $0.shellEscaped() }
).joined(separator: " ")
let inherited = ["$(inherited)"]

let buildParametersLinkFlags =
buildParameters.toolchain.extraFlags.linkerFlags.asSwiftcLinkerFlags().map { $0.shellEscaped() }
+ buildParameters.flags.linkerFlags.asSwiftcLinkerFlags().map { $0.shellEscaped() }

var otherLdFlags =
verboseFlag // clang will be invoked to link so the verbose flag is valid for it
+ inherited

otherLdFlags += buildParametersLinkFlags
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless there's a specific reason to order it this way we usually prefer to put $(inherited) at the end of the list

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do this in a follow-up PR.


settings["OTHER_LDFLAGS"] = otherLdFlags.joined(separator: " ")

// Optionally also set the list of architectures to build for.
if let architectures = buildParameters.architectures, !architectures.isEmpty {
Expand Down
4 changes: 2 additions & 2 deletions Sources/_InternalBuildTestSupport/MockBuildTestHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import Testing
public func mockBuildPlan(
buildPath: AbsolutePath? = nil,
environment: BuildEnvironment,
toolchain: PackageModel.Toolchain = MockToolchain(),
toolchain: PackageModel.Toolchain = try! MockToolchain(),
graph: ModulesGraph,
commonFlags: PackageModel.BuildFlags = .init(),
indexStoreMode: BuildParameters.IndexStoreMode = .off,
Expand Down Expand Up @@ -61,7 +61,7 @@ public func mockBuildPlan(
config: BuildConfiguration = .debug,
triple: Basics.Triple? = nil,
platform: PackageModel.Platform? = nil,
toolchain: PackageModel.Toolchain = MockToolchain(),
toolchain: PackageModel.Toolchain = try! MockToolchain(),
graph: ModulesGraph,
commonFlags: PackageModel.BuildFlags = .init(),
indexStoreMode: BuildParameters.IndexStoreMode = .off,
Expand Down
6 changes: 4 additions & 2 deletions Sources/_InternalTestSupport/MockBuildTestHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public struct MockToolchain: PackageModel.Toolchain {
public let swiftPMLibrariesLocation = ToolchainConfiguration.SwiftPMLibrariesLocation(
manifestLibraryPath: AbsolutePath("/fake/manifestLib/path"), pluginLibraryPath: AbsolutePath("/fake/pluginLibrary/path")
)
public var swiftSDK: PackageModel.SwiftSDK

public func getClangCompiler() throws -> AbsolutePath {
"/fake/path/to/clang"
Expand All @@ -54,10 +55,11 @@ public struct MockToolchain: PackageModel.Toolchain {
#endif
}

public init(swiftResourcesPath: AbsolutePath? = nil) {
public init(swiftResourcesPath: AbsolutePath? = nil) throws {
self.swiftResourcesPath = swiftResourcesPath
self.metalToolchainPath = nil
self.metalToolchainId = nil
self.swiftSDK = try .hostSwiftSDK()
}
}

Expand All @@ -84,7 +86,7 @@ public func mockBuildParameters(
destination: BuildParameters.Destination,
buildPath: AbsolutePath? = nil,
config: BuildConfiguration = .debug,
toolchain: PackageModel.Toolchain = MockToolchain(),
toolchain: PackageModel.Toolchain = try! MockToolchain(),
flags: PackageModel.BuildFlags = PackageModel.BuildFlags(),
buildSystemKind: BuildSystemProvider.Kind = .native,
shouldLinkStaticSwiftStdlib: Bool = false,
Expand Down
2 changes: 1 addition & 1 deletion Tests/BuildTests/ClangTargetBuildDescriptionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final class ClangTargetBuildDescriptionTests: XCTestCase {
}

func testSwiftCorelibsFoundationIncludeWorkaround() throws {
let toolchain = MockToolchain(swiftResourcesPath: AbsolutePath("/fake/path/lib/swift"))
let toolchain = try MockToolchain(swiftResourcesPath: AbsolutePath("/fake/path/lib/swift"))

let macosParameters = mockBuildParameters(destination: .target, toolchain: toolchain, triple: .macOS)
let linuxParameters = mockBuildParameters(destination: .target, toolchain: toolchain, triple: .arm64Linux)
Expand Down
43 changes: 41 additions & 2 deletions Tests/PackageModelTests/SwiftSDKTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ private let parsedToolsetNoRootDestination = SwiftSDK(
],
rootPaths: []
),
swiftSDKManifest: toolsetNoRootSwiftSDKv4.path,
pathsConfiguration: .init(
sdkRootPath: bundleRootPath.appending(sdkRootDir),
toolsetPaths: ["/tools/otherToolsNoRoot.json"]
Expand All @@ -359,6 +360,7 @@ private let parsedToolsetRootDestination = SwiftSDK(
],
rootPaths: [try! AbsolutePath(validating: "/custom")]
),
swiftSDKManifest: toolsetRootSwiftSDKv4.path,
pathsConfiguration: .init(
sdkRootPath: bundleRootPath.appending(sdkRootDir),
toolsetPaths: ["/tools/someToolsWithRoot.json", "/tools/otherToolsNoRoot.json"]
Expand All @@ -376,6 +378,7 @@ private let parsedToolsetNoSDKRootPathDestination = SwiftSDK(
],
rootPaths: []
),
swiftSDKManifest: androidWithoutSDKRootPathSwiftSDKv4.path,
pathsConfiguration: .init(
sdkRootPath: nil,
toolsetPaths: ["/tools/otherToolsNoRoot.json"]
Expand Down Expand Up @@ -455,7 +458,24 @@ final class SwiftSDKTests: XCTestCase {
observabilityScope: observability
)

XCTAssertEqual(toolsetNoRootDestinationV3Decoded, [parsedToolsetNoRootDestination])
let parsedToolsetNoRootDestinationV3 = SwiftSDK(
targetTriple: linuxGNUTargetTriple,
toolset: .init(
knownTools: [
.librarian: .init(path: try! AbsolutePath(validating: "\(usrBinTools[.librarian]!)")),
.linker: .init(path: try! AbsolutePath(validating: "\(usrBinTools[.linker]!)")),
.debugger: .init(path: try! AbsolutePath(validating: "\(usrBinTools[.debugger]!)")),
],
rootPaths: []
),
swiftSDKManifest: toolsetNoRootDestinationV3.path,
pathsConfiguration: .init(
sdkRootPath: bundleRootPath.appending(sdkRootDir),
toolsetPaths: ["/tools/otherToolsNoRoot.json"]
.map { try! AbsolutePath(validating: $0) }
)
)
XCTAssertEqual(toolsetNoRootDestinationV3Decoded, [parsedToolsetNoRootDestinationV3])

let toolsetRootDestinationV3Decoded = try SwiftSDK.decode(
fromFile: toolsetRootDestinationV3.path,
Expand All @@ -464,7 +484,26 @@ final class SwiftSDKTests: XCTestCase {
observabilityScope: observability
)

XCTAssertEqual(toolsetRootDestinationV3Decoded, [parsedToolsetRootDestination])
let parsedToolsetRootDestinationV3Decoded = SwiftSDK(
targetTriple: linuxGNUTargetTriple,
toolset: .init(
knownTools: [
.cCompiler: .init(extraCLIOptions: cCompilerOptions),
.librarian: .init(path: try! AbsolutePath(validating: "\(usrBinTools[.librarian]!)")),
.linker: .init(path: try! AbsolutePath(validating: "\(usrBinTools[.linker]!)")),
.debugger: .init(path: try! AbsolutePath(validating: "\(usrBinTools[.debugger]!)")),
],
rootPaths: [try! AbsolutePath(validating: "/custom")]
),
swiftSDKManifest: toolsetRootDestinationV3.path,
pathsConfiguration: .init(
sdkRootPath: bundleRootPath.appending(sdkRootDir),
toolsetPaths: ["/tools/someToolsWithRoot.json", "/tools/otherToolsNoRoot.json"]
.map { try! AbsolutePath(validating: $0) }
)
)

XCTAssertEqual(toolsetRootDestinationV3Decoded, [parsedToolsetRootDestinationV3Decoded])

XCTAssertThrowsError(try SwiftSDK.decode(
fromFile: missingToolsetDestinationV3.path,
Expand Down
Loading