Skip to content

Add build setting to enable version-independent APINotes processing mode #664

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions Sources/SWBCore/Settings/BuiltinMacros.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,7 @@ public final class BuiltinMacros {
public static let SWIFT_ENABLE_EXPLICIT_MODULES = BuiltinMacros.declareEnumMacro("SWIFT_ENABLE_EXPLICIT_MODULES") as EnumMacroDeclaration<SwiftEnableExplicitModulesSetting>
public static let _SWIFT_EXPLICIT_MODULES_ALLOW_CXX_INTEROP = BuiltinMacros.declareBooleanMacro("_SWIFT_EXPLICIT_MODULES_ALLOW_CXX_INTEROP")
public static let _SWIFT_EXPLICIT_MODULES_ALLOW_BEFORE_SWIFT_5 = BuiltinMacros.declareBooleanMacro("_SWIFT_EXPLICIT_MODULES_ALLOW_BEFORE_SWIFT_5")
public static let SWIFT_ENABLE_VERSION_INDEPENDENT_APINOTES = BuiltinMacros.declareBooleanMacro("SWIFT_ENABLE_VERSION_INDEPENDENT_APINOTES")
public static let _EXPERIMENTAL_SWIFT_EXPLICIT_MODULES = BuiltinMacros.declareEnumMacro("_EXPERIMENTAL_SWIFT_EXPLICIT_MODULES") as EnumMacroDeclaration<SwiftEnableExplicitModulesSetting>
public static let SWIFT_ENABLE_TESTABILITY = BuiltinMacros.declareBooleanMacro("SWIFT_ENABLE_TESTABILITY")
public static let SWIFT_EXEC = BuiltinMacros.declarePathMacro("SWIFT_EXEC")
Expand Down Expand Up @@ -2200,6 +2201,7 @@ public final class BuiltinMacros {
SWIFT_ENABLE_EXPLICIT_MODULES,
_SWIFT_EXPLICIT_MODULES_ALLOW_CXX_INTEROP,
_SWIFT_EXPLICIT_MODULES_ALLOW_BEFORE_SWIFT_5,
SWIFT_ENABLE_VERSION_INDEPENDENT_APINOTES,
_EXPERIMENTAL_SWIFT_EXPLICIT_MODULES,
SWIFT_ENABLE_BARE_SLASH_REGEX,
SWIFT_ENABLE_EMIT_CONST_VALUES,
Expand Down
13 changes: 13 additions & 0 deletions Sources/SWBUniversalPlatform/Specs/Swift.xcspec
Original file line number Diff line number Diff line change
Expand Up @@ -1354,6 +1354,19 @@
};
},

{
Name = "SWIFT_ENABLE_VERSION_INDEPENDENT_APINOTES";
Type = Boolean;
DefaultValue = NO;
CommandLineArgs = {
YES = (
"-Xfrontend",
"-version-independent-apinotes",
);
NO = ();
};
},

// Hidden clang importer options to control C++ behavior
// in the clang importer, not visible in build settings.
{
Expand Down
54 changes: 54 additions & 0 deletions Tests/SWBTaskConstructionTests/SwiftTaskConstructionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1692,6 +1692,60 @@ fileprivate struct SwiftTaskConstructionTests: CoreBasedTests {
}
}

@Test(.requireSDKs(.macOS))
func enableVersionIndependentAPINotes() async throws {
let testProject = try await TestProject(
"aProject",
groupTree: TestGroup(
"SomeFiles", path: "Sources",
children: [
TestFile("main.swift"),
]),
buildConfigurations: [
TestBuildConfiguration(
"Debug",
buildSettings: [
"PRODUCT_NAME": "$(TARGET_NAME)",
"SWIFT_ENABLE_EXPLICIT_MODULES": "YES",
"SWIFT_VERSION": "4.2"
]),
],
targets: [
TestStandardTarget(
"Exec", type: .commandLineTool,
buildConfigurations: [
TestBuildConfiguration("Debug",
buildSettings: [
"SWIFT_EXEC": swiftCompilerPath.str,
]),
],
buildPhases: [
TestSourcesBuildPhase([
"main.swift",
]),
])
])
let tester = try await TaskConstructionTester(getCore(), testProject)

await tester.checkBuild(BuildParameters(configuration: "Debug", overrides: ["SWIFT_ENABLE_VERSION_INDEPENDENT_APINOTES": "YES"]), runDestination: .macOS) { results in
results.checkTarget("Exec") { target in
results.checkTask(.matchTarget(target), .matchRuleType("SwiftDriver Compilation")) { task in
task.checkCommandLineContains(["-Xfrontend", "-version-independent-apinotes"])
}
}
results.checkNoDiagnostics()
}

await tester.checkBuild(BuildParameters(configuration: "Debug", overrides: ["SWIFT_ENABLE_VERSION_INDEPENDENT_APINOTES": "NO"]), runDestination: .macOS) { results in
results.checkTarget("Exec") { target in
results.checkTask(.matchTarget(target), .matchRuleType("SwiftDriver Compilation")) { task in
task.checkCommandLineDoesNotContain("-version-independent-apinotes")
}
}
results.checkNoDiagnostics()
}
}

/// Check control of whether Swift module is copied for other targets to use.
@Test(.requireSDKs(.macOS))
func swiftModuleNotCopiedWhenAskedNotTo() async throws {
Expand Down