Skip to content

Commit ae9ba6d

Browse files
authored
Fix setting SPECIALIZATION_SDK_OPTIONS, .ARCHS (swiftlang#9379)
The code to build up the SPECIALIZATION_SDK_OPTIONS list was appending to the existing list, but the list is not guarenteed to be initialized. If it isn't initialized, the append never happens and the setting is dropped.
1 parent 4f5a634 commit ae9ba6d

File tree

5 files changed

+55
-2
lines changed

5 files changed

+55
-2
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// swift-tools-version: 6.2
2+
3+
import PackageDescription
4+
5+
let package = Package(
6+
name: "PackageWithSDKSpecialization",
7+
platforms: [ .macOS("10.15.foo") ],
8+
products: [
9+
.library(
10+
name: "PackageWithSDKSpecialization",
11+
targets: ["PackageWithSDKSpecialization"]),
12+
],
13+
targets: [
14+
.target(
15+
name: "PackageWithSDKSpecialization",
16+
dependencies: []
17+
),
18+
.target(
19+
name: "Executable",
20+
dependencies: ["PackageWithSDKSpecialization"]
21+
),
22+
]
23+
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print("Hello, world!")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
struct PackageWithSDKSpecialization {
2+
var text = "Hello, World!"
3+
}

Sources/SwiftBuildSupport/PackagePIFBuilder.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ public final class PackagePIFBuilder {
581581
log(.warning, "Ignoring options '\(platformOptions.joined(separator: " "))' specified for unknown platform \(platform.name)")
582582
continue
583583
}
584-
settings[.SPECIALIZATION_SDK_OPTIONS, pifPlatform]?.append(contentsOf: platformOptions)
584+
settings[.SPECIALIZATION_SDK_OPTIONS, pifPlatform] = (settings[.SPECIALIZATION_SDK_OPTIONS, pifPlatform] ?? []) + platformOptions
585585
}
586586

587587
let deviceFamilyIDs: Set<Int> = self.delegate.deviceFamilyIDs()
@@ -607,7 +607,7 @@ public final class PackagePIFBuilder {
607607
} catch {
608608
preconditionFailure("Unhandled arm64e platform: \(error)")
609609
}
610-
settings[.ARCHS, pifPlatform]?.append(contentsOf: ["arm64e"])
610+
settings[.ARCHS, pifPlatform] = (settings[.ARCHS, pifPlatform] ?? []) + ["arm64e"]
611611
}
612612
}
613613

Tests/SwiftBuildSupportTests/PIFBuilderTests.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,19 @@ extension SwiftBuildSupport.PIF.Project {
118118
throw StringError("Multiple targets named \(name) in PIF project")
119119
}
120120
}
121+
122+
fileprivate func buildConfig(named name: String) throws -> SwiftBuild.ProjectModel.BuildConfig {
123+
let matchingConfigs = underlying.buildConfigs.filter {
124+
$0.name == name
125+
}
126+
if matchingConfigs.isEmpty {
127+
throw StringError("No config named \(name) in PIF project")
128+
} else if matchingConfigs.count > 1 {
129+
throw StringError("Multiple configs named \(name) in PIF project")
130+
} else {
131+
return matchingConfigs[0]
132+
}
133+
}
121134
}
122135

123136
extension SwiftBuild.ProjectModel.BaseTarget {
@@ -177,6 +190,19 @@ struct PIFBuilderTests {
177190
}
178191
}
179192

193+
@Test func packageWithInternal() async throws {
194+
try await withGeneratedPIF(fromFixture: "PIFBuilder/PackageWithSDKSpecialization") { pif, observabilitySystem in
195+
let errors = observabilitySystem.diagnostics.filter { $0.severity == .error }
196+
#expect(errors.isEmpty, "Expected no errors during PIF generation, but got: \(errors)")
197+
198+
let releaseConfig = try pif.workspace
199+
.project(named: "PackageWithSDKSpecialization")
200+
.buildConfig(named: "Release")
201+
202+
#expect(releaseConfig.settings[.SPECIALIZATION_SDK_OPTIONS, .macOS] == ["foo"])
203+
}
204+
}
205+
180206
@Test func pluginWithBinaryTargetDependency() async throws {
181207
try await withGeneratedPIF(fromFixture: "Miscellaneous/Plugins/BinaryTargetExePlugin") { pif, observabilitySystem in
182208
// Verify that PIF generation succeeds for a package with a plugin that depends on a binary target

0 commit comments

Comments
 (0)