Skip to content

Commit dde29d6

Browse files
committed
Add generate PCH job
1 parent 5bcc711 commit dde29d6

File tree

5 files changed

+52
-4
lines changed

5 files changed

+52
-4
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,9 +1332,7 @@ extension Driver {
13321332
diagnosticEngine.emit(.error_bridging_header_module_interface)
13331333
}
13341334

1335-
let objcHeaderPath = try VirtualPath(path: objcHeaderPathArg.asSingle)
1336-
// FIXME: Precompile bridging header if requested.
1337-
return objcHeaderPath
1335+
return try VirtualPath(path: objcHeaderPathArg.asSingle)
13381336
}
13391337
}
13401338

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//===--------------- GeneratePCHJob.swift - Swift Autolink Extract ----===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import TSCBasic
14+
import TSCUtility
15+
16+
extension Driver {
17+
mutating func generatePCHJob(input: TypedVirtualPath) throws -> Job {
18+
var inputs = [TypedVirtualPath]()
19+
var outputs = [TypedVirtualPath]()
20+
21+
var commandLine: [Job.ArgTemplate] = swiftCompilerPrefixArgs.map { Job.ArgTemplate.flag($0) }
22+
23+
inputs.append(input)
24+
commandLine.appendPath(input.file)
25+
commandLine.appendFlag(.emitPch)
26+
27+
try addCommonFrontendOptions(commandLine: &commandLine)
28+
29+
if let outputDirectory = parsedOptions.getLastArgument(.pchOutputDir)?.asSingle {
30+
outputs.append(.init(file: try VirtualPath(path: outputDirectory), type: .pch))
31+
try commandLine.appendLast(.pchOutputDir, from: &parsedOptions)
32+
}
33+
34+
return Job(
35+
kind: .generatePCH,
36+
tool: .absolute(try toolchain.getToolPath(.swiftCompiler)),
37+
commandLine: commandLine,
38+
displayInputs: [],
39+
inputs: inputs,
40+
outputs: outputs
41+
)
42+
}
43+
}

Sources/SwiftDriver/Jobs/Job.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public struct Job: Codable, Equatable {
2020
case generateDSYM = "generate-dsym"
2121
case autolinkExtract = "autolink-extract"
2222
case emitModule = "emit-module"
23+
case generatePCH = "generate-pch"
2324
case interpret
2425
case repl
2526
case verifyDebugInfo = "verify-debug-info"

Sources/SwiftDriver/Jobs/Planning.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ extension Driver {
4545
}
4646
}
4747
}
48+
49+
if let importedObjCHeader = importedObjCHeader,
50+
parsedOptions.hasFlag(positive: .enableBridgingPch, negative: .disableBridgingPch, default: true),
51+
importedObjCHeader.extension == FileType.objcHeader.rawValue {
52+
jobs.append(try generatePCHJob(input: .init(file: importedObjCHeader, type: .objcHeader)))
53+
}
4854

4955
// If we should create emit module job, do so.
5056
if shouldCreateEmitModuleJob {

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ final class SwiftDriverTests: XCTestCase {
841841

842842
func testMergeModulesOnly() throws {
843843
do {
844-
var driver = try Driver(args: ["swiftc", "foo.swift", "bar.swift", "-module-name", "Test", "-emit-module", "-import-objc-header", "TestInputHeader.h", "-emit-dependencies", "-emit-module-doc-path", "/foo/bar/Test.swiftdoc"])
844+
var driver = try Driver(args: ["swiftc", "foo.swift", "bar.swift", "-module-name", "Test", "-emit-module", "-disable-bridging-pch", "-import-objc-header", "TestInputHeader.h", "-emit-dependencies", "-emit-module-doc-path", "/foo/bar/Test.swiftdoc"])
845845
let plannedJobs = try driver.planBuild()
846846
XCTAssertEqual(plannedJobs.count, 3)
847847
XCTAssertEqual(plannedJobs[0].outputs.count, 3)

0 commit comments

Comments
 (0)