Skip to content

Commit 36c3549

Browse files
authored
Use a switch instead of if/else if (#9267)
Cleanup from previous PR
1 parent c946f52 commit 36c3549

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

Sources/SwiftBuildSupport/PackagePIFProjectBuilder+Modules.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -498,10 +498,13 @@ extension PackagePIFProjectBuilder {
498498
if sourceModule.isCxx {
499499
for platform in ProjectModel.BuildSettings.Platform.allCases {
500500
// darwin & freebsd
501-
if [.macOS, .macCatalyst, .iOS, .watchOS, .tvOS, .xrOS, .driverKit, .freebsd].contains(platform) {
502-
settings[.OTHER_LDFLAGS, platform] = ["-lc++", "$(inherited)"]
503-
} else if [.android, .linux, .wasi, .openbsd].contains(platform) {
504-
settings[.OTHER_LDFLAGS, platform] = ["-lstdc++", "$(inherited)"]
501+
switch platform {
502+
case .macOS, .macCatalyst, .iOS, .watchOS, .tvOS, .xrOS, .driverKit, .freebsd:
503+
settings[.OTHER_LDFLAGS, platform] = ["-lc++", "$(inherited)"]
504+
case .android, .linux, .wasi, .openbsd:
505+
settings[.OTHER_LDFLAGS, platform] = ["-lstdc++", "$(inherited)"]
506+
case .windows, ._iOSDevice:
507+
break
505508
}
506509
}
507510
}

Tests/SwiftBuildSupportTests/PIFBuilderTests.swift

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,13 @@ struct PIFBuilderTests {
164164

165165
for platform in ProjectModel.BuildSettings.Platform.allCases {
166166
let ld_flags = releaseConfig.settings[.OTHER_LDFLAGS, platform]
167-
if [.macOS, .macCatalyst, .iOS, .watchOS, .tvOS, .xrOS, .driverKit, .freebsd].contains(platform) {
168-
#expect(ld_flags == ["-lc++", "$(inherited)"], "for platform \(platform)")
169-
} else if [.android, .linux, .wasi, .openbsd].contains(platform) {
170-
#expect(ld_flags == ["-lstdc++", "$(inherited)"], "for platform \(platform)")
171-
} else if [.windows, ._iOSDevice].contains(platform) {
172-
#expect(ld_flags == nil, "for platform \(platform)")
173-
} else {
174-
Issue.record("Unexpected platform \(platform)")
167+
switch platform {
168+
case .macOS, .macCatalyst, .iOS, .watchOS, .tvOS, .xrOS, .driverKit, .freebsd:
169+
#expect(ld_flags == ["-lc++", "$(inherited)"], "for platform \(platform)")
170+
case .android, .linux, .wasi, .openbsd:
171+
#expect(ld_flags == ["-lstdc++", "$(inherited)"], "for platform \(platform)")
172+
case .windows, ._iOSDevice:
173+
#expect(ld_flags == nil, "for platform \(platform)")
175174
}
176175
}
177176
}

0 commit comments

Comments
 (0)