Skip to content

Commit 3093b07

Browse files
authored
Merge pull request #1993 from DougGregor/internal-import-bridging-header
2 parents df3d079 + 1c78d00 commit 3093b07

File tree

5 files changed

+109
-50
lines changed

5 files changed

+109
-50
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,9 @@ public struct Driver {
353353
/// Original ObjC Header passed from command-line
354354
let originalObjCHeaderFile: VirtualPath.Handle?
355355

356+
/// Whether to import the bridging header as internal (vs public).
357+
let importBridgingHeaderAsInternal: Bool
358+
356359
/// Enable bridging header chaining.
357360
let bridgingHeaderChaining: Bool
358361

@@ -1165,10 +1168,12 @@ public struct Driver {
11651168
}
11661169
self.producePCHJob = maybeNeedPCH
11671170

1168-
if let objcHeaderPathArg = parsedOptions.getLastArgument(.importObjcHeader) {
1169-
self.originalObjCHeaderFile = try? VirtualPath.intern(path: objcHeaderPathArg.asSingle)
1171+
if let importBridgingHeaderOption = parsedOptions.last(for: .importBridgingHeader, .internalImportBridgingHeader) {
1172+
self.originalObjCHeaderFile = try? VirtualPath.intern(path: importBridgingHeaderOption.argument.asSingle)
1173+
self.importBridgingHeaderAsInternal = importBridgingHeaderOption.option == .internalImportBridgingHeader
11701174
} else {
11711175
self.originalObjCHeaderFile = nil
1176+
self.importBridgingHeaderAsInternal = false
11721177
}
11731178

11741179
if parsedOptions.hasFlag(positive: .autoBridgingHeaderChaining,
@@ -2059,8 +2064,8 @@ extension Driver {
20592064

20602065
// Put bridging header as first input if we have it
20612066
let allInputs: [TypedVirtualPath]
2062-
if let objcHeader = originalObjCHeaderFile {
2063-
allInputs = [TypedVirtualPath(file: objcHeader, type: .objcHeader)] + inputFiles
2067+
if let bridgingHeader = originalObjCHeaderFile {
2068+
allInputs = [TypedVirtualPath(file: bridgingHeader, type: .objcHeader)] + inputFiles
20642069
} else {
20652070
allInputs = inputFiles
20662071
}

Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ extension Driver {
229229
try commandLine.appendLast(.nostdimport, from: &parsedOptions)
230230
try commandLine.appendLast(.nostdlibimport, from: &parsedOptions)
231231
try commandLine.appendLast(.parseStdlib, from: &parsedOptions)
232-
try commandLine.appendLast(.solverMemoryThreshold, from: &parsedOptions)
233232
try commandLine.appendLast(.valueRecursionThreshold, from: &parsedOptions)
234233
try commandLine.appendLast(.warnSwift3ObjcInference, from: &parsedOptions)
235234
try commandLine.appendLast(.remarkLoadingModule, from: &parsedOptions)
@@ -475,14 +474,17 @@ extension Driver {
475474
try computeCanonicalObjCHeader(explicitModulePlanner: explicitModulePlanner)
476475
let objcHeaderFile = (kind == .scanDependencies) ? originalObjCHeaderFile : importedObjCHeader
477476
if let importedObjCHeader = objcHeaderFile, bridgingHeaderHandling != .ignored {
477+
let importBridgingHeaderFlag: Option = importBridgingHeaderAsInternal
478+
? .internalImportBridgingHeader
479+
: .importObjcHeader
478480
if bridgingHeaderHandling == .precompiled, let pch = precompiledObjCHeader {
479481
// For explicit module build, we directly pass the compiled pch to
480482
// swift-frontend, rather than rely on swift-frontend to locate
481483
// the pch in the pchOutputDir and can start an implicit build in case
482484
// of a lookup failure.
483485
if parsedOptions.contains(.pchOutputDir) &&
484486
!parsedOptions.contains(.driverExplicitModuleBuild) {
485-
commandLine.appendFlag(.importObjcHeader)
487+
commandLine.appendFlag(importBridgingHeaderFlag)
486488
try addPathArgument(VirtualPath.lookup(importedObjCHeader), to:&commandLine, remap: jobNeedPathRemap)
487489
try commandLine.appendLast(.pchOutputDir, from: &parsedOptions)
488490
if !compilerMode.isSingleCompilation {
@@ -491,21 +493,21 @@ extension Driver {
491493
} else {
492494
// If header chaining is enabled, pass objc header through `-import-objc-header` and
493495
// PCH file through `-import-pch`. Otherwise, pass either the PCH or header through
494-
// `-import-objc-header` option.
496+
// `-import-objc-header` option (or its internal variant).
495497
if isFrontendArgSupported(.importPch), importedObjCHeader != originalObjCHeaderFile {
496-
commandLine.appendFlag(.importPch)
498+
commandLine.appendFlag(importBridgingHeaderAsInternal ? .internalImportPch : .importPch)
497499
try addPathArgument(VirtualPath.lookup(pch), to:&commandLine, remap: jobNeedPathRemap)
498500
if let originalHeader = originalObjCHeaderFile {
499-
commandLine.appendFlag(.importObjcHeader)
501+
commandLine.appendFlag(importBridgingHeaderFlag)
500502
try addPathArgument(VirtualPath.lookup(originalHeader), to:&commandLine, remap: jobNeedPathRemap)
501503
}
502504
} else {
503-
commandLine.appendFlag(.importObjcHeader)
505+
commandLine.appendFlag(importBridgingHeaderFlag)
504506
try addPathArgument(VirtualPath.lookup(pch), to:&commandLine, remap: jobNeedPathRemap)
505507
}
506508
}
507509
} else {
508-
commandLine.appendFlag(.importObjcHeader)
510+
commandLine.appendFlag(importBridgingHeaderFlag)
509511
try addPathArgument(VirtualPath.lookup(importedObjCHeader), to:&commandLine, remap: jobNeedPathRemap)
510512
}
511513
}

Sources/SwiftDriver/Jobs/ReplJob.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ extension Driver {
1818
try addCommonFrontendOptions(commandLine: &commandLine, inputs: &inputs, kind: .repl)
1919
try addRuntimeLibraryFlags(commandLine: &commandLine)
2020

21-
try commandLine.appendLast(.importObjcHeader, from: &parsedOptions)
21+
try commandLine.appendLast(
22+
.importObjcHeader, .internalImportBridgingHeader,
23+
from: &parsedOptions
24+
)
2225
toolchain.addLinkedLibArgs(
2326
to: &commandLine,
2427
parsedOptions: &parsedOptions

0 commit comments

Comments
 (0)