Skip to content

Commit 9382e7b

Browse files
committed
[Build] Enable Swift compiler's batch mode
This leads to faster build times when WMO is off. <rdar://problem/39262812> SwiftPM should build using multifile mode (batch mode)
1 parent b760467 commit 9382e7b

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

Sources/Build/BuildPlan.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,17 @@ public final class SwiftTargetDescription {
323323
public func compileArguments() -> [String] {
324324
var args = [String]()
325325
args += ["-swift-version", swiftVersion.rawValue]
326+
327+
// Enable batch mode in debug mode.
328+
//
329+
// Technically, it should be enabled whenever WMO is off but we
330+
// don't currently make that distinction in SwiftPM
331+
switch buildParameters.configuration {
332+
case .debug:
333+
args += ["-enable-batch-mode"]
334+
case .release: break
335+
}
336+
326337
args += buildParameters.toolchain.extraSwiftCFlags
327338
args += optimizationArguments
328339
args += ["-j\(SwiftCompilerTool.numThreads)"]

Tests/BuildTests/BuildPlanTests.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ final class BuildPlanTests: XCTestCase {
7878
result.checkTargetsCount(2)
7979

8080
let exe = try result.target(for: "exe").swiftTarget().compileArguments()
81-
XCTAssertMatch(exe, ["-swift-version", "3", "-Onone", "-g", "-enable-testing", .equal(j), "-DSWIFT_PACKAGE", "-DDEBUG", "-module-cache-path", "/path/to/build/debug/ModuleCache", .anySequence])
81+
XCTAssertMatch(exe, ["-swift-version", "3", "-enable-batch-mode", "-Onone", "-g", "-enable-testing", .equal(j), "-DSWIFT_PACKAGE", "-DDEBUG", "-module-cache-path", "/path/to/build/debug/ModuleCache", .anySequence])
8282

8383
let lib = try result.target(for: "lib").swiftTarget().compileArguments()
84-
XCTAssertMatch(lib, ["-swift-version", "3", "-Onone", "-g", "-enable-testing", .equal(j), "-DSWIFT_PACKAGE", "-DDEBUG", "-module-cache-path", "/path/to/build/debug/ModuleCache", .anySequence])
84+
XCTAssertMatch(lib, ["-swift-version", "3", "-enable-batch-mode", "-Onone", "-g", "-enable-testing", .equal(j), "-DSWIFT_PACKAGE", "-DDEBUG", "-module-cache-path", "/path/to/build/debug/ModuleCache", .anySequence])
8585

8686
#if os(macOS)
8787
let linkArguments = [
@@ -334,7 +334,7 @@ final class BuildPlanTests: XCTestCase {
334334
XCTAssertEqual(lib.moduleMap, AbsolutePath("/path/to/build/debug/lib.build/module.modulemap"))
335335

336336
let exe = try result.target(for: "exe").swiftTarget().compileArguments()
337-
XCTAssertMatch(exe, ["-swift-version", "3", "-Onone", "-g", "-enable-testing", .equal(j), "-DSWIFT_PACKAGE", "-DDEBUG","-Xcc", "-fmodule-map-file=/path/to/build/debug/lib.build/module.modulemap", "-I", "/Pkg/Sources/lib/include", "-module-cache-path", "/path/to/build/debug/ModuleCache", .anySequence])
337+
XCTAssertMatch(exe, ["-swift-version", "3", "-enable-batch-mode", "-Onone", "-g", "-enable-testing", .equal(j), "-DSWIFT_PACKAGE", "-DDEBUG","-Xcc", "-fmodule-map-file=/path/to/build/debug/lib.build/module.modulemap", "-I", "/Pkg/Sources/lib/include", "-module-cache-path", "/path/to/build/debug/ModuleCache", .anySequence])
338338

339339
#if os(macOS)
340340
XCTAssertEqual(try result.buildProduct(for: "exe").linkArguments(), [
@@ -370,10 +370,10 @@ final class BuildPlanTests: XCTestCase {
370370
#endif
371371

372372
let foo = try result.target(for: "Foo").swiftTarget().compileArguments()
373-
XCTAssertMatch(foo, ["-swift-version", "3", "-Onone", "-g", "-enable-testing", .equal(j), "-DSWIFT_PACKAGE", "-DDEBUG", "-module-cache-path", "/path/to/build/debug/ModuleCache", .anySequence])
373+
XCTAssertMatch(foo, ["-swift-version", "3", "-enable-batch-mode", "-Onone", "-g", "-enable-testing", .equal(j), "-DSWIFT_PACKAGE", "-DDEBUG", "-module-cache-path", "/path/to/build/debug/ModuleCache", .anySequence])
374374

375375
let fooTests = try result.target(for: "FooTests").swiftTarget().compileArguments()
376-
XCTAssertMatch(fooTests, ["-swift-version", "3", "-Onone", "-g", "-enable-testing", .equal(j), "-DSWIFT_PACKAGE", "-DDEBUG", "-module-cache-path", "/path/to/build/debug/ModuleCache", .anySequence])
376+
XCTAssertMatch(fooTests, ["-swift-version", "3", "-enable-batch-mode", "-Onone", "-g", "-enable-testing", .equal(j), "-DSWIFT_PACKAGE", "-DDEBUG", "-module-cache-path", "/path/to/build/debug/ModuleCache", .anySequence])
377377

378378
#if os(macOS)
379379
XCTAssertEqual(try result.buildProduct(for: "PkgPackageTests").linkArguments(), [
@@ -409,7 +409,7 @@ final class BuildPlanTests: XCTestCase {
409409
result.checkProductsCount(1)
410410
result.checkTargetsCount(1)
411411

412-
XCTAssertMatch(try result.target(for: "exe").swiftTarget().compileArguments(), ["-swift-version", "3", "-Onone", "-g", "-enable-testing", .equal(j), "-DSWIFT_PACKAGE", "-DDEBUG", "-Xcc", "-fmodule-map-file=/Clibgit/module.modulemap", "-module-cache-path", "/path/to/build/debug/ModuleCache", .anySequence])
412+
XCTAssertMatch(try result.target(for: "exe").swiftTarget().compileArguments(), ["-swift-version", "3", "-enable-batch-mode", "-Onone", "-g", "-enable-testing", .equal(j), "-DSWIFT_PACKAGE", "-DDEBUG", "-Xcc", "-fmodule-map-file=/Clibgit/module.modulemap", "-module-cache-path", "/path/to/build/debug/ModuleCache", .anySequence])
413413

414414
#if os(macOS)
415415
XCTAssertEqual(try result.buildProduct(for: "exe").linkArguments(), [
@@ -550,10 +550,10 @@ final class BuildPlanTests: XCTestCase {
550550
result.checkTargetsCount(2)
551551

552552
let exe = try result.target(for: "exe").swiftTarget().compileArguments()
553-
XCTAssertMatch(exe, ["-swift-version", "4", "-Onone", "-g", "-enable-testing", .equal(j), "-DSWIFT_PACKAGE", "-DDEBUG", "-module-cache-path", "/path/to/build/debug/ModuleCache", .anySequence])
553+
XCTAssertMatch(exe, ["-swift-version", "4", "-enable-batch-mode", "-Onone", "-g", "-enable-testing", .equal(j), "-DSWIFT_PACKAGE", "-DDEBUG", "-module-cache-path", "/path/to/build/debug/ModuleCache", .anySequence])
554554

555555
let lib = try result.target(for: "lib").swiftTarget().compileArguments()
556-
XCTAssertMatch(lib, ["-swift-version", "4", "-Onone", "-g", "-enable-testing", .equal(j), "-DSWIFT_PACKAGE", "-DDEBUG", "-module-cache-path", "/path/to/build/debug/ModuleCache", .anySequence])
556+
XCTAssertMatch(lib, ["-swift-version", "4", "-enable-batch-mode", "-Onone", "-g", "-enable-testing", .equal(j), "-DSWIFT_PACKAGE", "-DDEBUG", "-module-cache-path", "/path/to/build/debug/ModuleCache", .anySequence])
557557

558558
#if os(macOS)
559559
let linkArguments = [

0 commit comments

Comments
 (0)