From 182d5e59779614431d391edfdf28dc2a977f639f Mon Sep 17 00:00:00 2001 From: Dave Inglis Date: Tue, 21 Oct 2025 09:29:55 -0400 Subject: [PATCH] Use a switch instead of if/else if --- .../PackagePIFProjectBuilder+Modules.swift | 11 +++++++---- .../SwiftBuildSupportTests/PIFBuilderTests.swift | 15 +++++++-------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/Sources/SwiftBuildSupport/PackagePIFProjectBuilder+Modules.swift b/Sources/SwiftBuildSupport/PackagePIFProjectBuilder+Modules.swift index b0fc05cbe03..df2fc9eaea7 100644 --- a/Sources/SwiftBuildSupport/PackagePIFProjectBuilder+Modules.swift +++ b/Sources/SwiftBuildSupport/PackagePIFProjectBuilder+Modules.swift @@ -487,10 +487,13 @@ extension PackagePIFProjectBuilder { if sourceModule.isCxx { for platform in ProjectModel.BuildSettings.Platform.allCases { // darwin & freebsd - if [.macOS, .macCatalyst, .iOS, .watchOS, .tvOS, .xrOS, .driverKit, .freebsd].contains(platform) { - settings[.OTHER_LDFLAGS, platform] = ["-lc++", "$(inherited)"] - } else if [.android, .linux, .wasi, .openbsd].contains(platform) { - settings[.OTHER_LDFLAGS, platform] = ["-lstdc++", "$(inherited)"] + switch platform { + case .macOS, .macCatalyst, .iOS, .watchOS, .tvOS, .xrOS, .driverKit, .freebsd: + settings[.OTHER_LDFLAGS, platform] = ["-lc++", "$(inherited)"] + case .android, .linux, .wasi, .openbsd: + settings[.OTHER_LDFLAGS, platform] = ["-lstdc++", "$(inherited)"] + case .windows, ._iOSDevice: + break } } } diff --git a/Tests/SwiftBuildSupportTests/PIFBuilderTests.swift b/Tests/SwiftBuildSupportTests/PIFBuilderTests.swift index 23bbd411c6b..a4970fbec2d 100644 --- a/Tests/SwiftBuildSupportTests/PIFBuilderTests.swift +++ b/Tests/SwiftBuildSupportTests/PIFBuilderTests.swift @@ -157,14 +157,13 @@ struct PIFBuilderTests { for platform in ProjectModel.BuildSettings.Platform.allCases { let ld_flags = releaseConfig.settings[.OTHER_LDFLAGS, platform] - if [.macOS, .macCatalyst, .iOS, .watchOS, .tvOS, .xrOS, .driverKit, .freebsd].contains(platform) { - #expect(ld_flags == ["-lc++", "$(inherited)"], "for platform \(platform)") - } else if [.android, .linux, .wasi, .openbsd].contains(platform) { - #expect(ld_flags == ["-lstdc++", "$(inherited)"], "for platform \(platform)") - } else if [.windows, ._iOSDevice].contains(platform) { - #expect(ld_flags == nil, "for platform \(platform)") - } else { - Issue.record("Unexpected platform \(platform)") + switch platform { + case .macOS, .macCatalyst, .iOS, .watchOS, .tvOS, .xrOS, .driverKit, .freebsd: + #expect(ld_flags == ["-lc++", "$(inherited)"], "for platform \(platform)") + case .android, .linux, .wasi, .openbsd: + #expect(ld_flags == ["-lstdc++", "$(inherited)"], "for platform \(platform)") + case .windows, ._iOSDevice: + #expect(ld_flags == nil, "for platform \(platform)") } } }