Skip to content

Add build setting for enabling the builtin module #6311

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 2 commits into from
Mar 22, 2023
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
6 changes: 6 additions & 0 deletions Sources/PackageDescription/BuildSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,12 @@ public struct SwiftSetting {
return SwiftSetting(
name: "interoperabilityMode", value: values, condition: condition)
}

@available(_PackageDescription, introduced: 5.9)
@_spi(FrontendOptions)
public static var enableBuiltinModule: SwiftSetting {
SwiftSetting(name: "enableBuiltinModule", value: [], condition: nil)
}
}

/// A linker build setting.
Expand Down
2 changes: 2 additions & 0 deletions Sources/PackageLoading/ManifestJSONParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,8 @@ extension TargetBuildSettingDescription.Kind {
return .enableExperimentalFeature(value)
case "unsafeFlags":
return .unsafeFlags(values)
case "enableBuiltinModule":
return .enableBuiltinModule
default:
throw InternalError("invalid build setting \(name)")
}
Expand Down
12 changes: 12 additions & 0 deletions Sources/PackageLoading/PackageBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,18 @@ public final class PackageBuilder {
}

values = ["-enable-experimental-feature", value]

case .enableBuiltinModule:
switch setting.tool {
case .c, .cxx, .linker:
throw InternalError(
"only Swift supports enabling the builtin module")

case .swift:
decl = .OTHER_SWIFT_FLAGS
}

values = ["-enable-builtin-module"]
}

// Create an assignment for this setting.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ public enum TargetBuildSettingDescription {

case unsafeFlags([String])

case enableBuiltinModule

public var isUnsafeFlags: Bool {
switch self {
case .unsafeFlags(let flags):
// If `.unsafeFlags` is used, but doesn't specify any flags, we treat it the same way as not specifying it.
return !flags.isEmpty
case .headerSearchPath, .define, .linkedLibrary, .linkedFramework, .interoperabilityMode, .enableUpcomingFeature, .enableExperimentalFeature:
case .headerSearchPath, .define, .linkedLibrary, .linkedFramework, .interoperabilityMode, .enableUpcomingFeature, .enableExperimentalFeature, .enableBuiltinModule:
return false
}
}
Expand Down
4 changes: 4 additions & 0 deletions Sources/PackageModel/ManifestSourceGeneration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,8 @@ fileprivate extension SourceCodeFragment {
params.append(SourceCodeFragment(from: condition))
}
self.init(enum: setting.kind.name, subnodes: params)
case .enableBuiltinModule:
self.init(enum: setting.kind.name)
}
}
}
Expand Down Expand Up @@ -678,6 +680,8 @@ extension TargetBuildSettingDescription.Kind {
return "enableUpcomingFeature"
case .enableExperimentalFeature:
return "enableExperimentalFeature"
case .enableBuiltinModule:
return "enableBuiltinModule"
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions Tests/BuildTests/BuildPlanTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3245,7 +3245,8 @@ final class BuildPlanTests: XCTestCase {
.init(tool: .swift, kind: .interoperabilityMode(.Cxx, "swift-5.9"), condition: .init(platformNames: ["linux"])),
.init(tool: .swift, kind: .interoperabilityMode(.Cxx, "swift-6.0"), condition: .init(platformNames: ["macos"])),
.init(tool: .swift, kind: .enableUpcomingFeature("BestFeature")),
.init(tool: .swift, kind: .enableUpcomingFeature("WorstFeature"), condition: .init(platformNames: ["macos"], config: "debug"))
.init(tool: .swift, kind: .enableUpcomingFeature("WorstFeature"), condition: .init(platformNames: ["macos"], config: "debug")),
.init(tool: .swift, kind: .enableBuiltinModule)
]
),
try TargetDescription(
Expand Down Expand Up @@ -3311,7 +3312,7 @@ final class BuildPlanTests: XCTestCase {
XCTAssertMatch(cbar, [.anySequence, "-DCCC=2", "-I\(A.appending(components: "Sources", "cbar", "Sources", "headers"))", "-I\(A.appending(components: "Sources", "cbar", "Sources", "cppheaders"))", "-Icfoo", "-L", "cbar", "-Icxxfoo", "-L", "cxxbar", .end])

let bar = try result.target(for: "bar").swiftTarget().compileArguments()
XCTAssertMatch(bar, [.anySequence, "-DLINUX", "-Isfoo", "-L", "sbar", "-cxx-interoperability-mode=swift-5.9", "-enable-upcoming-feature", "BestFeature", .end])
XCTAssertMatch(bar, [.anySequence, "-DLINUX", "-Isfoo", "-L", "sbar", "-cxx-interoperability-mode=swift-5.9", "-enable-upcoming-feature", "BestFeature", "-enable-builtin-module", .end])

let exe = try result.target(for: "exe").swiftTarget().compileArguments()
XCTAssertMatch(exe, [.anySequence, "-DFOO", .end])
Expand All @@ -3327,7 +3328,7 @@ final class BuildPlanTests: XCTestCase {
XCTAssertMatch(cbar, [.anySequence, "-DCCC=2", "-I\(A.appending(components: "Sources", "cbar", "Sources", "headers"))", "-I\(A.appending(components: "Sources", "cbar", "Sources", "cppheaders"))", "-Icfoo", "-L", "cbar", "-Icxxfoo", "-L", "cxxbar", .end])

let bar = try result.target(for: "bar").swiftTarget().compileArguments()
XCTAssertMatch(bar, [.anySequence, "-DDMACOS", "-Isfoo", "-L", "sbar", "-cxx-interoperability-mode=swift-6.0", "-enable-upcoming-feature", "BestFeature", "-enable-upcoming-feature", "WorstFeature", .end])
XCTAssertMatch(bar, [.anySequence, "-DDMACOS", "-Isfoo", "-L", "sbar", "-cxx-interoperability-mode=swift-6.0", "-enable-upcoming-feature", "BestFeature", "-enable-upcoming-feature", "WorstFeature", "-enable-builtin-module", .end])

let exe = try result.target(for: "exe").swiftTarget().compileArguments()
XCTAssertMatch(exe, [.anySequence, "-DFOO", .end])
Expand Down