Skip to content

[PackageModel] Associated swift version build setting with `SWIFT_VER… #7550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 11, 2024
Merged
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
Expand Up @@ -820,6 +820,9 @@ package final class SwiftTargetBuildDescription {
let scope = self.defaultBuildParameters.createScope(for: self.target)
var flags: [String] = []

// A custom swift version.
flags += scope.evaluate(.SWIFT_VERSION).flatMap { ["-swift-version", $0] }

// Swift defines.
let swiftDefines = scope.evaluate(.SWIFT_ACTIVE_COMPILATION_CONDITIONS)
flags += swiftDefines.map { "-D" + $0 }
Expand Down
4 changes: 2 additions & 2 deletions Sources/PackageLoading/PackageBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1176,10 +1176,10 @@ public final class PackageBuilder {
throw InternalError("only Swift supports swift language version")

case .swift:
decl = .OTHER_SWIFT_FLAGS
decl = .SWIFT_VERSION
}

values = ["-swift-version", version.rawValue]
values = [version.rawValue]
}

// Create an assignment for this setting.
Expand Down
1 change: 1 addition & 0 deletions Sources/PackageModel/BuildSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public enum BuildSettings {
// Swift.
public static let SWIFT_ACTIVE_COMPILATION_CONDITIONS: Declaration = .init("SWIFT_ACTIVE_COMPILATION_CONDITIONS")
public static let OTHER_SWIFT_FLAGS: Declaration = .init("OTHER_SWIFT_FLAGS")
public static let SWIFT_VERSION: Declaration = .init("SWIFT_VERSION")

// C family.
public static let GCC_PREPROCESSOR_DEFINITIONS: Declaration = .init("GCC_PREPROCESSOR_DEFINITIONS")
Expand Down
8 changes: 4 additions & 4 deletions Tests/BuildTests/BuildPlanTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4083,7 +4083,7 @@ final class BuildPlanTests: XCTestCase {
)

let exe = try result.target(for: "exe").swiftTarget().compileArguments()
XCTAssertMatch(exe, [.anySequence, "-DFOO", "-swift-version", "5", "-g", "-Xcc", "-g", "-Xcc", "-fno-omit-frame-pointer", .end])
XCTAssertMatch(exe, [.anySequence, "-swift-version", "5", "-DFOO", "-g", "-Xcc", "-g", "-Xcc", "-fno-omit-frame-pointer", .end])

let linkExe = try result.buildProduct(for: "exe").linkArguments()
XCTAssertMatch(linkExe, [.anySequence, "-lsqlite3", "-llibz", "-Ilfoo", "-L", "lbar", "-g", .end])
Expand Down Expand Up @@ -4149,7 +4149,7 @@ final class BuildPlanTests: XCTestCase {
)

let exe = try result.target(for: "exe").swiftTarget().compileArguments()
XCTAssertMatch(exe, [.anySequence, "-DFOO", "-swift-version", "5", "-g", "-Xcc", "-g", "-Xcc", "-fomit-frame-pointer", .end])
XCTAssertMatch(exe, [.anySequence, "-swift-version", "5", "-DFOO", "-g", "-Xcc", "-g", "-Xcc", "-fomit-frame-pointer", .end])
}

// omit frame pointers explicitly set to false
Expand Down Expand Up @@ -4206,7 +4206,7 @@ final class BuildPlanTests: XCTestCase {
)

let exe = try result.target(for: "exe").swiftTarget().compileArguments()
XCTAssertMatch(exe, [.anySequence, "-DFOO", "-swift-version", "5", "-g", "-Xcc", "-g", "-Xcc", "-fno-omit-frame-pointer", .end])
XCTAssertMatch(exe, [.anySequence, "-swift-version", "5", "-DFOO", "-g", "-Xcc", "-g", "-Xcc", "-fno-omit-frame-pointer", .end])
}

do {
Expand Down Expand Up @@ -4253,10 +4253,10 @@ final class BuildPlanTests: XCTestCase {
exe,
[
.anySequence,
"-swift-version", "4",
"-DFOO",
"-cxx-interoperability-mode=default",
"-Xcc", "-std=c++17",
"-swift-version", "4",
"-g",
"-Xcc", "-g",
.end,
Expand Down
10 changes: 5 additions & 5 deletions Tests/PackageLoadingTests/PackageBuilderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3055,33 +3055,33 @@ final class PackageBuilderTests: XCTestCase {
package.target.buildSettings,
environment: BuildEnvironment(platform: .macOS, configuration: .debug)
)
XCTAssertEqual(macosDebugScope.evaluate(.OTHER_SWIFT_FLAGS), ["-swift-version", "5"])
XCTAssertEqual(macosDebugScope.evaluate(.SWIFT_VERSION), ["5"])

let macosReleaseScope = BuildSettings.Scope(
package.target.buildSettings,
environment: BuildEnvironment(platform: .macOS, configuration: .release)
)
XCTAssertEqual(macosReleaseScope.evaluate(.OTHER_SWIFT_FLAGS), ["-swift-version", "5"])
XCTAssertEqual(macosReleaseScope.evaluate(.SWIFT_VERSION), ["5"])
}

package.checkModule("bar") { package in
let linuxDebugScope = BuildSettings.Scope(
package.target.buildSettings,
environment: BuildEnvironment(platform: .linux, configuration: .debug)
)
XCTAssertEqual(linuxDebugScope.evaluate(.OTHER_SWIFT_FLAGS), ["-swift-version", "3"])
XCTAssertEqual(linuxDebugScope.evaluate(.SWIFT_VERSION), ["3"])

let macosDebugScope = BuildSettings.Scope(
package.target.buildSettings,
environment: BuildEnvironment(platform: .macOS, configuration: .debug)
)
XCTAssertEqual(macosDebugScope.evaluate(.OTHER_SWIFT_FLAGS), ["-swift-version", "4"])
XCTAssertEqual(macosDebugScope.evaluate(.SWIFT_VERSION), ["4"])

let macosReleaseScope = BuildSettings.Scope(
package.target.buildSettings,
environment: BuildEnvironment(platform: .macOS, configuration: .release)
)
XCTAssertEqual(macosReleaseScope.evaluate(.OTHER_SWIFT_FLAGS), [])
XCTAssertEqual(macosReleaseScope.evaluate(.SWIFT_VERSION), [])
}
}
}
Expand Down