Skip to content

Commit 5f4041c

Browse files
committed
[Explicit Module Builds] Add support for Swift incremental dependency scanning
With an opt-in build setting SWIFT_ENABLE_INCREMENTAL_SCAN to allow early adopters to try it out
1 parent f267224 commit 5f4041c

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

Sources/SWBCore/Settings/BuiltinMacros.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,7 @@ public final class BuiltinMacros {
10021002
public static let SWIFT_EMIT_MODULE_INTERFACE = BuiltinMacros.declareBooleanMacro("SWIFT_EMIT_MODULE_INTERFACE")
10031003
public static let SWIFT_ENABLE_BATCH_MODE = BuiltinMacros.declareBooleanMacro("SWIFT_ENABLE_BATCH_MODE")
10041004
public static let SWIFT_ENABLE_INCREMENTAL_COMPILATION = BuiltinMacros.declareBooleanMacro("SWIFT_ENABLE_INCREMENTAL_COMPILATION")
1005+
public static let SWIFT_ENABLE_INCREMENTAL_SCAN = BuiltinMacros.declareBooleanMacro("SWIFT_ENABLE_INCREMENTAL_SCAN")
10051006
public static let SWIFT_ENABLE_LAYOUT_STRING_VALUE_WITNESSES = BuiltinMacros.declareBooleanMacro("SWIFT_ENABLE_LAYOUT_STRING_VALUE_WITNESSES")
10061007
public static let SWIFT_ENABLE_LIBRARY_EVOLUTION = BuiltinMacros.declareBooleanMacro("SWIFT_ENABLE_LIBRARY_EVOLUTION")
10071008
public static let SWIFT_ENABLE_BARE_SLASH_REGEX = BuiltinMacros.declareBooleanMacro("SWIFT_ENABLE_BARE_SLASH_REGEX")
@@ -2164,6 +2165,7 @@ public final class BuiltinMacros {
21642165
SWIFT_EMIT_MODULE_INTERFACE,
21652166
SWIFT_ENABLE_BATCH_MODE,
21662167
SWIFT_ENABLE_INCREMENTAL_COMPILATION,
2168+
SWIFT_ENABLE_INCREMENTAL_SCAN,
21672169
SWIFT_ENABLE_LAYOUT_STRING_VALUE_WITNESSES,
21682170
SWIFT_ENABLE_LIBRARY_EVOLUTION,
21692171
SWIFT_USE_INTEGRATED_DRIVER,

Sources/SWBCore/SpecImplementations/Tools/SwiftCompiler.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ public struct SwiftSourceFileIndexingInfo: SourceFileIndexingInfo {
119119
"-emit-dependencies",
120120
"-serialize-diagnostics",
121121
"-incremental",
122+
"-incremental-dependency-scan",
122123
"-parseable-output",
123124
"-use-frontend-parseable-output",
124125
"-whole-module-optimization",
@@ -153,6 +154,7 @@ public struct SwiftSourceFileIndexingInfo: SourceFileIndexingInfo {
153154
// can be removed after we use the new driver instead (rdar://75851402).
154155
private static let newDriverFlags: Set<ByteString> = [
155156
"-driver-print-graphviz",
157+
"-incremental-dependency-scan",
156158
"-explicit-module-build",
157159
"-experimental-explicit-module-build",
158160
"-nonlib-dependency-scanner",
@@ -1743,6 +1745,10 @@ public final class SwiftCompilerSpec : CompilerSpec, SpecIdentifierType, SwiftDi
17431745

17441746
if cbc.scope.evaluate(BuiltinMacros.SWIFT_ENABLE_INCREMENTAL_COMPILATION) {
17451747
args.append("-incremental")
1748+
if LibSwiftDriver.supportsDriverFlag(spelled: "-incremental-dependency-scan"),
1749+
cbc.scope.evaluate(BuiltinMacros.SWIFT_ENABLE_INCREMENTAL_SCAN) {
1750+
args.append("-incremental-dependency-scan")
1751+
}
17461752
}
17471753
}
17481754

@@ -3284,6 +3290,8 @@ public final class SwiftCompilerSpec : CompilerSpec, SpecIdentifierType, SwiftDi
32843290
for arg in [
32853291
// Should strip this because it saves some work and avoids writing a useless incremental build record
32863292
"-incremental",
3293+
// Same as above
3294+
"-incremental-dependency-scan",
32873295

32883296
// Stripped because we want to end up in single file mode
32893297
"-enable-batch-mode",

Tests/SWBTaskConstructionTests/SwiftTaskConstructionTests.swift

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,6 +1535,64 @@ fileprivate struct SwiftTaskConstructionTests: CoreBasedTests {
15351535
}
15361536
}
15371537

1538+
@Test(.requireSDKs(.macOS), .enabled(if: LibSwiftDriver.supportsDriverFlag(spelled: "-incremental-dependency-scan")))
1539+
func optOutIncrementalScanning() async throws {
1540+
let testProject = try await TestProject(
1541+
"aProject",
1542+
groupTree: TestGroup(
1543+
"SomeFiles", path: "Sources",
1544+
children: [
1545+
TestFile("main.swift"),
1546+
]),
1547+
buildConfigurations: [
1548+
TestBuildConfiguration(
1549+
"Debug",
1550+
buildSettings: [
1551+
"PRODUCT_NAME": "$(TARGET_NAME)",
1552+
"SWIFT_ENABLE_EXPLICIT_MODULES": "YES",
1553+
]),
1554+
],
1555+
targets: [
1556+
TestStandardTarget(
1557+
"Exec", type: .commandLineTool,
1558+
buildConfigurations: [
1559+
TestBuildConfiguration("Debug",
1560+
buildSettings: [
1561+
"SWIFT_EXEC": swiftCompilerPath.str,
1562+
"SWIFT_VERSION": swiftVersion,
1563+
]),
1564+
],
1565+
buildPhases: [
1566+
TestSourcesBuildPhase([
1567+
"main.swift",
1568+
]),
1569+
])
1570+
])
1571+
let tester = try await TaskConstructionTester(getCore(), testProject)
1572+
1573+
await tester.checkBuild(BuildParameters(configuration: "Debug", overrides: ["SWIFT_ENABLE_INCREMENTAL_SCAN": "YES"]), runDestination: .macOS) { results in
1574+
results.checkTarget("Exec") { target in
1575+
results.checkTask(.matchTarget(target), .matchRuleType("SwiftDriver Compilation Requirements")) { task in
1576+
task.checkCommandLineContains(["-explicit-module-build"])
1577+
task.checkCommandLineContains(["-incremental"])
1578+
task.checkCommandLineContains(["-incremental-dependency-scan"])
1579+
}
1580+
}
1581+
results.checkNoDiagnostics()
1582+
}
1583+
1584+
await tester.checkBuild(runDestination: .macOS) { results in
1585+
results.checkTarget("Exec") { target in
1586+
results.checkTask(.matchTarget(target), .matchRuleType("SwiftDriver Compilation Requirements")) { task in
1587+
task.checkCommandLineContains(["-explicit-module-build"])
1588+
task.checkCommandLineContains(["-incremental"])
1589+
task.checkCommandLineDoesNotContain("-incremental-dependency-scan")
1590+
}
1591+
}
1592+
results.checkNoDiagnostics()
1593+
}
1594+
}
1595+
15381596
@Test(.requireSDKs(.macOS))
15391597
func swift4DisablesExplicitModules() async throws {
15401598
let testProject = try await TestProject(

0 commit comments

Comments
 (0)