Skip to content

Commit dda7c81

Browse files
authored
Merge pull request swiftlang#78192 from hamishknight/couple-of-xcodegen-fixes
[xcodegen] A couple of fixes for `--stdlib-swift`
2 parents ab43437 + 486cd42 commit dda7c81

File tree

5 files changed

+33
-6
lines changed

5 files changed

+33
-6
lines changed

utils/swift-xcodegen/Sources/SwiftXcodeGen/BuildArgs/SwiftTargets.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,11 @@ struct SwiftTargets {
212212
// Add the dependencies. We track dependencies for any input files, along
213213
// with any recorded swiftmodule dependencies.
214214
dependenciesByTargetName.withValue(for: name, default: []) { deps in
215-
deps.formUnion(rule.inputs)
215+
deps.formUnion(
216+
rule.inputs.filter {
217+
$0.hasExtension(.swiftmodule) || $0.hasExtension(.o)
218+
}
219+
)
216220
deps.formUnion(
217221
rule.dependencies.filter { $0.hasExtension(.swiftmodule) }
218222
)

utils/swift-xcodegen/Sources/SwiftXcodeGen/Generator/ProjectGenerator.swift

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -531,11 +531,20 @@ fileprivate final class ProjectGenerator {
531531
guard checkNotExcluded(buildRule.parentPath, for: "Swift target") else {
532532
return nil
533533
}
534-
// Create the target. Swift targets can always use buildable folders
535-
// since they have a consistent set of arguments.
534+
// Swift targets can almost always use buildable folders since they have
535+
// a consistent set of arguments, but we need to ensure we don't have any
536+
// child source files that aren't part of the target.
537+
let canUseBuildableFolder = try {
538+
guard let parent = buildRule.parentPath else { return false }
539+
let repoSources = Set(buildRule.sources.repoSources)
540+
return try getAllRepoSubpaths(of: parent)
541+
.allSatisfy { !$0.isSourceLike || repoSources.contains($0) }
542+
}()
543+
// Create the target.
536544
let target = generateBaseTarget(
537-
targetInfo.name, at: buildRule.parentPath, canUseBuildableFolder: true,
538-
productType: .staticArchive, includeInAllTarget: includeInAllTarget
545+
targetInfo.name, at: buildRule.parentPath,
546+
canUseBuildableFolder: canUseBuildableFolder, productType: .staticArchive,
547+
includeInAllTarget: includeInAllTarget
539548
)
540549
guard let target else { return nil }
541550

@@ -558,6 +567,13 @@ fileprivate final class ProjectGenerator {
558567
buildSettings.common.DEFINES_MODULE = "YES"
559568
}
560569

570+
// Disable the Obj-C bridging header; we don't currently use this, and
571+
// even if we did, we'd probably want to use the one in the Ninja build
572+
// folder.
573+
// This also works around a compiler crash
574+
// (https://github.com/swiftlang/swift/issues/78190).
575+
buildSettings.common.SWIFT_OBJC_INTERFACE_HEADER_NAME = ""
576+
561577
if let last = buildArgs.takeFlagGroup(.O, .Onone) {
562578
buildSettings.common.SWIFT_OPTIMIZATION_LEVEL = last.printed
563579
}

utils/swift-xcodegen/Sources/SwiftXcodeGen/Path/FileExtension.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ public enum FileExtension: String {
1616
case def
1717
case gyb
1818
case h
19+
case m
1920
case md
21+
case mm
2022
case modulemap
2123
case o
2224
case rst

utils/swift-xcodegen/Sources/SwiftXcodeGen/Path/PathProtocol.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,11 @@ extension PathProtocol {
124124
}
125125

126126
var isCSourceLike: Bool {
127-
hasExtension(.c, .cpp)
127+
hasExtension(.c, .cpp, .m, .mm)
128+
}
129+
130+
var isSourceLike: Bool {
131+
isCSourceLike || hasExtension(.swift)
128132
}
129133

130134
var isDocLike: Bool {

utils/swift-xcodegen/Sources/Xcodeproj/XcodeProjectModel.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ public struct Xcode {
441441
public var SWIFT_FORCE_DYNAMIC_LINK_STDLIB: String?
442442
public var SWIFT_INCLUDE_PATHS: [String]?
443443
public var SWIFT_MODULE_ALIASES: [String: String]?
444+
public var SWIFT_OBJC_INTERFACE_HEADER_NAME: String?
444445
public var SWIFT_OPTIMIZATION_LEVEL: String?
445446
public var SWIFT_VERSION: String?
446447
public var TARGET_NAME: String?

0 commit comments

Comments
 (0)