Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@available(macOS, obsoleted: 13.0)
func foo() {

}

func bar() {
foo()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// swift-tools-version:6.1
import PackageDescription

let package = Package(
name: "Foo",
platforms: [.macOS(.v12)],
products: [
.library(name: "Foo", targets: ["Foo"]),
],
targets: [
.target(name: "Foo", path: "./"),
]
)
13 changes: 11 additions & 2 deletions Sources/Basics/Triple+Basics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,16 @@ extension Triple {
}

/// Determine the versioned host triple using the Swift compiler.
public static func getHostTriple(usingSwiftCompiler swiftCompiler: AbsolutePath) throws -> Triple {
public static func getVersionedHostTriple(usingSwiftCompiler swiftCompiler: AbsolutePath) throws -> Triple {
try Self.getHostTriple(usingSwiftCompiler: swiftCompiler, versioned: true)
}

/// Determine the unversioned host triple using the Swift compiler.
public static func getUnversionedHostTriple(usingSwiftCompiler swiftCompiler: AbsolutePath) throws -> Triple {
try Self.getHostTriple(usingSwiftCompiler: swiftCompiler, versioned: false)
}

private static func getHostTriple(usingSwiftCompiler swiftCompiler: AbsolutePath, versioned: Bool) throws -> Triple {
// Call the compiler to get the target info JSON.
let compilerOutput: String
do {
Expand All @@ -106,7 +115,7 @@ extension Triple {
// Get the triple string from the parsed JSON.
let tripleString: String
do {
tripleString = try parsedTargetInfo.get("target").get("triple")
tripleString = try parsedTargetInfo.get("target").get(versioned ? "triple" : "unversionedTriple")
} catch {
throw InternalError(
"Target info does not contain a triple string (\(error.interpolationDescription)).\nTarget info: \(parsedTargetInfo)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct AuditBinaryArtifact: AsyncSwiftCommand {
let hostToolchain = try swiftCommandState.getHostToolchain()
let clang = try hostToolchain.getClangCompiler()
let objdump = try hostToolchain.getLLVMObjdump()
let hostTriple = try Triple.getHostTriple(
let hostTriple = try Triple.getVersionedHostTriple(
usingSwiftCompiler: hostToolchain.swiftCompilerPath)
let fileSystem = swiftCommandState.fileSystem

Expand Down
6 changes: 3 additions & 3 deletions Sources/PackageModel/UserToolchain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,11 @@ public final class UserToolchain: Toolchain {
}
}

private static func getHostTriple(targetInfo: JSON) throws -> Basics.Triple {
private static func getHostTriple(targetInfo: JSON, versioned: Bool) throws -> Basics.Triple {
// Get the triple string from the target info.
let tripleString: String
do {
tripleString = try targetInfo.get("target").get("triple")
tripleString = try targetInfo.get("target").get(versioned ? "triple" : "unversionedTriple")
} catch {
throw InternalError(
"Target info does not contain a triple string (\(error.interpolationDescription)).\nTarget info: \(targetInfo)"
Expand Down Expand Up @@ -741,7 +741,7 @@ public final class UserToolchain: Toolchain {
// targetInfo from the compiler
let targetInfo = try customTargetInfo ?? Self.getTargetInfo(swiftCompiler: swiftCompilers.compile)
self._targetInfo = targetInfo
triple = try swiftSDK.targetTriple ?? Self.getHostTriple(targetInfo: targetInfo)
triple = try swiftSDK.targetTriple ?? Self.getHostTriple(targetInfo: targetInfo, versioned: false)
}

// Change the triple to the specified arch if there's exactly one of them.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ public struct BuildParameters: Encodable {
testingParameters: Testing = .init(),
apiDigesterMode: APIDigesterMode? = nil
) throws {
let triple = try triple ?? .getHostTriple(usingSwiftCompiler: toolchain.swiftCompilerPath)
// Default to the unversioned triple if none is provided so that we defer to the package's requested deployment target.
let triple = try triple ?? .getUnversionedHostTriple(usingSwiftCompiler: toolchain.swiftCompilerPath)
self.debuggingParameters = debuggingParameters ?? .init(
triple: triple,
shouldEnableDebuggingEntitlement: configuration == .debug,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,12 +466,19 @@ public struct DefaultPluginScriptRunner: PluginScriptRunner, Cancellable {

var env = Environment.current

// FIXME: This is largely a workaround for improper rpath setup on Linux. It should be
// removed once the Swift Build backend switches to use swiftc as the linker driver
// for targets with Swift sources. For now, limit the scope to non-macOS, so that
// plugins do not inadvertently use the toolchain stdlib instead of the OS stdlib
// when built with a Swift.org toolchain.
#if !os(macOS)
// Update the environment for any runtime library paths that tools compiled
// for the command plugin might require after they have been built.
let runtimeLibPaths = self.toolchain.runtimeLibraryPaths
for libPath in runtimeLibPaths {
env.appendPath(key: .libraryPath, value: libPath.pathString)
}
#endif

#if os(Windows)
let pluginLibraryPath = self.toolchain.swiftPMLibrariesLocation.pluginLibraryPath.pathString
Expand Down
8 changes: 7 additions & 1 deletion Sources/SwiftBuildSupport/PIFBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -367,12 +367,18 @@ public final class PIFBuilder {
buildCommands: result.buildCommands.map( { buildCommand in
var newEnv: Environment = buildCommand.configuration.environment

// FIXME: This is largely a workaround for improper rpath setup on Linux. It should be
// removed once the Swift Build backend switches to use swiftc as the linker driver
// for targets with Swift sources. For now, limit the scope to non-macOS, so that
// plugins do not inadvertently use the toolchain stdlib instead of the OS stdlib
// when built with a Swift.org toolchain.
#if !os(macOS)
let runtimeLibPaths = buildParameters.toolchain.runtimeLibraryPaths

// Add paths to swift standard runtime libraries to the library path so that they can be found at runtime
for libPath in runtimeLibPaths {
newEnv.appendPath(key: .libraryPath, value: libPath.pathString)
}
#endif

// Append the system path at the end so that necessary system tool paths can be found
if let pathValue = Environment.current[EnvironmentKey.path] {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftSDKCommand/ConfigureSwiftSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ struct ConfigureSwiftSDK: AsyncParsableCommand {
let swiftSDKsDirectory = try self.getOrCreateSwiftSDKsDirectory()

let hostToolchain = try UserToolchain(swiftSDK: SwiftSDK.hostSwiftSDK())
let triple = try Triple.getHostTriple(usingSwiftCompiler: hostToolchain.swiftCompilerPath)
let triple = try Triple.getVersionedHostTriple(usingSwiftCompiler: hostToolchain.swiftCompilerPath)

var commandError: Error? = nil
do {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftSDKCommand/SwiftSDKSubcommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ extension SwiftSDKSubcommand {
),
environment: environment
)
let triple = try Triple.getHostTriple(usingSwiftCompiler: hostToolchain.swiftCompilerPath)
let triple = try Triple.getVersionedHostTriple(usingSwiftCompiler: hostToolchain.swiftCompilerPath)

var commandError: Error? = nil
do {
Expand Down
60 changes: 60 additions & 0 deletions Tests/CommandsTests/BuildCommandTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1396,6 +1396,66 @@ struct BuildCommandTestCases {
}
}
}

@Test(.requireHostOS(.macOS), arguments: SupportedBuildSystemOnPlatform)
func buildingPackageWhichRequiresOlderDeploymentTarget(buildSystem: BuildSystemProvider.Kind) async throws {
// This fixture specifies a deployment target of macOS 12, and uses API obsoleted in macOS 13. The goal
// of this test is to ensure that SwiftPM respects the deployment target specified in the package manifest
// when passed no triple of an unversioned triple, rather than using the latests deployment target.

// No triple - build should pass
try await fixture(name: "Miscellaneous/RequiresOlderDeploymentTarget") { path in
try await executeSwiftBuild(
path,
buildSystem: buildSystem,
throwIfCommandFails: true
)
}

let hostArch: String
#if arch(arm64)
hostArch = "arm64"
#elseif arch(x86_64)
hostArch = "x86_64"
#else
Issue.record("test is not supported on host arch")
return
#endif

// Unversioned triple - build should pass
try await fixture(name: "Miscellaneous/RequiresOlderDeploymentTarget") { path in
try await executeSwiftBuild(
path,
extraArgs: ["--triple", "\(hostArch)-apple-macosx"],
buildSystem: buildSystem,
throwIfCommandFails: true
)
}

// Versioned triple with supported deployment target - build should pass
try await fixture(name: "Miscellaneous/RequiresOlderDeploymentTarget") { path in
try await executeSwiftBuild(
path,
extraArgs: ["--triple", "\(hostArch)-apple-macosx12.0"],
buildSystem: buildSystem,
throwIfCommandFails: true
)
}

if buildSystem == .swiftbuild {
// Versioned triple with unsupported deployment target - build should fail
try await fixture(name: "Miscellaneous/RequiresOlderDeploymentTarget") { path in
await #expect(throws: Error.self) {
try await executeSwiftBuild(
path,
extraArgs: ["--triple", "\(hostArch)-apple-macosx14.0"],
buildSystem: buildSystem,
throwIfCommandFails: true
)
}
}
}
}
}

extension Triple {
Expand Down