Skip to content

Commit 9929ece

Browse files
committed
Mirror what native build system does for enabling clang modules
- the native builder only enables clang modules on Darwin, so we will need to do the same with swift-build.
1 parent 7046c68 commit 9929ece

File tree

5 files changed

+11
-17
lines changed

5 files changed

+11
-17
lines changed

Sources/SwiftBuildSupport/PIFBuilder.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,8 @@ public final class PIFBuilder {
412412
}
413413

414414
let packagePIFBuilderDelegate = PackagePIFBuilderDelegate(
415-
package: package
415+
package: package,
416+
buildParameters: buildParameters,
416417
)
417418
let packagePIFBuilder = PackagePIFBuilder(
418419
modulesGraph: self.graph,
@@ -484,9 +485,11 @@ public final class PIFBuilder {
484485

485486
fileprivate final class PackagePIFBuilderDelegate: PackagePIFBuilder.BuildDelegate {
486487
let package: ResolvedPackage
488+
let buildParameters: BuildParameters
487489

488-
init(package: ResolvedPackage) {
490+
init(package: ResolvedPackage, buildParameters: BuildParameters) {
489491
self.package = package
492+
self.buildParameters = buildParameters
490493
}
491494

492495
var isRootPackage: Bool {
@@ -522,7 +525,8 @@ fileprivate final class PackagePIFBuilderDelegate: PackagePIFBuilder.BuildDelega
522525
}
523526

524527
func configureProjectBuildSettings(_ buildSettings: inout ProjectModel.BuildSettings) {
525-
/* empty */
528+
// This is parity to the native build, But we should investigate what it would take to get this working on platforms.
529+
buildSettings[.CLANG_ENABLE_MODULES] = self.buildParameters.triple.isDarwin() ? "YES" : "NO"
526530
}
527531

528532
func configureSourceModuleBuildSettings(sourceModule: ResolvedModule, settings: inout ProjectModel.BuildSettings) {

Sources/SwiftBuildSupport/PackagePIFBuilder+Helpers.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,6 @@ extension ProjectModel.BuildSettings {
10341034
self[.PRODUCT_NAME] = productName
10351035
self[.PRODUCT_MODULE_NAME] = productName
10361036
self[.PRODUCT_BUNDLE_IDENTIFIER] = "\(packageIdentity).\(productName)".spm_mangledToBundleIdentifier()
1037-
self[.CLANG_ENABLE_MODULES] = "YES"
10381037
self[.SWIFT_PACKAGE_NAME] = packageName ?? nil
10391038

10401039
if !createDylibForDynamicProducts {

Sources/SwiftBuildSupport/PackagePIFBuilder.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -529,11 +529,6 @@ public final class PackagePIFBuilder {
529529
}
530530

531531
settings[.USE_HEADERMAP] = "NO"
532-
settings[.OTHER_SWIFT_FLAGS].lazilyInitializeAndMutate(initialValue: ["$(inherited)"]) { $0.append("-DXcode") }
533-
534-
// TODO: Might be relevant to make customizable —— Paulo
535-
// (If we want to be extra careful with differences to the existing PIF in the SwiftPM.)
536-
settings[.OTHER_CFLAGS] = ["$(inherited)", "-DXcode"]
537532

538533
if !self.delegate.isRootPackage {
539534
if self.suppressWarningsForPackageDependencies {

Sources/SwiftBuildSupport/PackagePIFProjectBuilder+Products.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ extension PackagePIFProjectBuilder {
115115
settings[.PRODUCT_MODULE_NAME] = product.c99name
116116
settings[.PRODUCT_BUNDLE_IDENTIFIER] = "\(self.package.identity).\(product.name)"
117117
.spm_mangledToBundleIdentifier()
118-
settings[.CLANG_ENABLE_MODULES] = "YES"
119118
settings[.SWIFT_PACKAGE_NAME] = mainModule.packageName
120119

121120
if mainModule.type == .test {

Sources/_InternalTestSupport/SwiftTesting+TraitConditional.swift

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,31 +34,28 @@ extension Trait where Self == Testing.ConditionTrait {
3434
/// Enabled only if toolchain support swift concurrency
3535
public static var requiresSwiftConcurrencySupport: Self {
3636
enabled("skipping because test environment doesn't support concurrency") {
37-
(try? UserToolchain.default)!.supportsSwiftConcurrency()
37+
(try? UserToolchain.default)?.supportsSwiftConcurrency() != nil
3838
}
3939
}
4040

4141
/// Enabled only if 'llvm-profdata' is available
4242
public static var requiresLLVMProfData: Self {
4343
disabled("skipping test because the `llvm-profdata` tool isn't available") {
44-
let toolPath = try (try? UserToolchain.default)!.getLLVMProf()
45-
return toolPath == nil
44+
try (try? UserToolchain.default)?.getLLVMProf() == nil
4645
}
4746
}
4847

4948
/// Enabled only if 'llvm-cov' is available
5049
public static var requiresLLVMCov: Self {
5150
disabled("skipping test because the `llvm-cov` tool isn't available") {
52-
let toolPath = try (try? UserToolchain.default)!.getLLVMCov()
53-
return toolPath == nil
51+
try (try? UserToolchain.default)?.getLLVMCov() == nil
5452
}
5553
}
5654

5755
/// Enabled only if 'swift-symbolgraph-extract' is available
5856
public static var requiresSymbolgraphExtract: Self {
5957
disabled("skipping test because the `swift-symbolgraph-extract` tools isn't available") {
60-
let toolPath = try (try? UserToolchain.default)!.getSymbolGraphExtract()
61-
return toolPath == nil
58+
try (try? UserToolchain.default)?.getSymbolGraphExtract() == nil
6259
}
6360
}
6461

0 commit comments

Comments
 (0)