Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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.1
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
87 changes: 54 additions & 33 deletions Sources/SwiftBuildSupport/SwiftBuildSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -702,36 +702,50 @@ 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

if self.buildParameters.triple.isAndroid() {
// Android triples are identified by the environment part of the triple
platformName = "android"
sdkName = platformName
// FIXME remove this case
} else if self.buildParameters.triple.isWasm {

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.

I think you can just remove this now, it's unreachable code.

// Swift Build uses webassembly instead of wasi as the platform name
platformName = "webassembly"
sdkName = platformName
} else {
platformName = self.buildParameters.triple.darwinPlatform?.platformName ?? self.buildParameters.triple.osNameUnversioned
sdkName = platformName
}

let sdkVariant: String?
if self.buildParameters.triple.environment == .macabi {
sdkVariant = "iosmac"
} else {
sdkVariant = nil
}
let sdkVariant: String?
if self.buildParameters.triple.environment == .macabi {
sdkVariant = "iosmac"
} else {
sdkVariant = nil
}

return SwiftBuild.SWBRunDestinationInfo(
platform: platformName,
sdk: sdkName,
sdkVariant: sdkVariant,
targetArchitecture: buildParameters.triple.archName,
supportedArchitectures: [],
disableOnlyActiveArch: (buildParameters.architectures?.count ?? 1) > 1
)
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 @@ -866,12 +880,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
Loading