Skip to content

Commit 5b8637d

Browse files
committed
Only define these for Swift modules
1 parent 617eec6 commit 5b8637d

File tree

3 files changed

+31
-17
lines changed

3 files changed

+31
-17
lines changed

Sources/SwiftBuildSupport/PackagePIFProjectBuilder+Modules.swift

+13-11
Original file line numberDiff line numberDiff line change
@@ -596,17 +596,19 @@ extension PackagePIFProjectBuilder {
596596
settings[.COREML_COMPILER_CONTAINER] = "swift-package"
597597
}
598598

599-
// Leave an explicit indicator regarding whether we are generating a Bundle.module accessor.
600-
// This will be read by the #bundle macro defined in Foundation.
601-
if !shouldGenerateBundleAccessor {
602-
// No resources, so explicitly indicate that.
603-
// #bundle will then produce an error about there being no resources.
604-
settings[.SWIFT_ACTIVE_COMPILATION_CONDITIONS].lazilyInitializeAndMutate(initialValue: ["$(inherited)"]) { $0.append("SWIFT_MODULE_RESOURCE_BUNDLE_UNAVAILABLE") }
605-
} else if !(resourceBundleName?.isEmpty ?? true) {
606-
// We have an explicit resource bundle via Bundle.module.
607-
// #bundle should call into that.
608-
settings[.SWIFT_ACTIVE_COMPILATION_CONDITIONS].lazilyInitializeAndMutate(initialValue: ["$(inherited)"]) { $0.append("SWIFT_MODULE_RESOURCE_BUNDLE_AVAILABLE") }
609-
} // else we won't set either of those and just let #bundle point to the same bundle as the source code.
599+
if sourceModule.usesSwift {
600+
// Leave an explicit indicator regarding whether we are generating a Bundle.module accessor.
601+
// This will be read by the #bundle macro defined in Foundation.
602+
if !shouldGenerateBundleAccessor {
603+
// No resources, so explicitly indicate that.
604+
// #bundle will then produce an error about there being no resources.
605+
settings[.SWIFT_ACTIVE_COMPILATION_CONDITIONS].lazilyInitializeAndMutate(initialValue: ["$(inherited)"]) { $0.append("SWIFT_MODULE_RESOURCE_BUNDLE_UNAVAILABLE") }
606+
} else if !(resourceBundleName?.isEmpty ?? true) {
607+
// We have an explicit resource bundle via Bundle.module.
608+
// #bundle should call into that.
609+
settings[.SWIFT_ACTIVE_COMPILATION_CONDITIONS].lazilyInitializeAndMutate(initialValue: ["$(inherited)"]) { $0.append("SWIFT_MODULE_RESOURCE_BUNDLE_AVAILABLE") }
610+
} // else we won't set either of those and just let #bundle point to the same bundle as the source code.
611+
}
610612

611613
if desiredModuleType == .macro {
612614
settings[.SWIFT_IMPLEMENTS_MACROS_FOR_MODULE_NAMES] = [sourceModule.c99name]

Sources/SwiftBuildSupport/PackagePIFProjectBuilder+Products.swift

+5-2
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,11 @@ extension PackagePIFProjectBuilder {
267267

268268
if result.shouldGenerateBundleAccessor {
269269
settings[.GENERATE_RESOURCE_ACCESSORS] = "YES"
270-
settings[.SWIFT_ACTIVE_COMPILATION_CONDITIONS].lazilyInitializeAndMutate(initialValue: ["$(inherited)"]) { $0.append("SWIFT_MODULE_RESOURCE_BUNDLE_AVAILABLE") }
271-
} else {
270+
271+
if mainModule.usesSwift {
272+
settings[.SWIFT_ACTIVE_COMPILATION_CONDITIONS].lazilyInitializeAndMutate(initialValue: ["$(inherited)"]) { $0.append("SWIFT_MODULE_RESOURCE_BUNDLE_AVAILABLE") }
273+
}
274+
} else if mainModule.usesSwift {
272275
settings[.SWIFT_ACTIVE_COMPILATION_CONDITIONS].lazilyInitializeAndMutate(initialValue: ["$(inherited)"]) { $0.append("SWIFT_MODULE_RESOURCE_BUNDLE_UNAVAILABLE") }
273276
}
274277
if result.shouldGenerateEmbedInCodeAccessor {

Sources/XCBuildSupport/PIFBuilder.swift

+13-4
Original file line numberDiff line numberDiff line change
@@ -488,21 +488,26 @@ final class PackagePIFProjectBuilder: PIFProjectBuilder {
488488
settings[.GENERATE_INFOPLIST_FILE] = "YES"
489489
}
490490

491+
var isSwiftModule = false
491492
if let clangTarget = mainTarget.underlying as? ClangModule {
492493
// Let the target itself find its own headers.
493494
settings[.HEADER_SEARCH_PATHS, default: ["$(inherited)"]].append(clangTarget.includeDir.pathString)
494495
settings[.GCC_C_LANGUAGE_STANDARD] = clangTarget.cLanguageStandard
495496
settings[.CLANG_CXX_LANGUAGE_STANDARD] = clangTarget.cxxLanguageStandard
496497
} else if let swiftTarget = mainTarget.underlying as? SwiftModule {
498+
isSwiftModule = true
497499
try settings.addSwiftVersionSettings(target: swiftTarget, parameters: self.parameters)
498500
settings.addCommonSwiftSettings(package: self.package, target: mainTarget, parameters: self.parameters)
499501
}
500502

501503
if let resourceBundle = addResourceBundle(for: mainTarget, in: pifTarget) {
502504
settings[.PACKAGE_RESOURCE_BUNDLE_NAME] = resourceBundle
503505
settings[.GENERATE_RESOURCE_ACCESSORS] = "YES"
504-
settings[.SWIFT_ACTIVE_COMPILATION_CONDITIONS, default: ["$(inherited)"]].append("SWIFT_MODULE_RESOURCE_BUNDLE_AVAILABLE")
505-
} else {
506+
507+
if isSwiftModule {
508+
settings[.SWIFT_ACTIVE_COMPILATION_CONDITIONS, default: ["$(inherited)"]].append("SWIFT_MODULE_RESOURCE_BUNDLE_AVAILABLE")
509+
}
510+
} else if isSwiftModule {
506511
settings[.SWIFT_ACTIVE_COMPILATION_CONDITIONS, default: ["$(inherited)"]].append("SWIFT_MODULE_RESOURCE_BUNDLE_UNAVAILABLE")
507512
}
508513

@@ -657,6 +662,7 @@ final class PackagePIFProjectBuilder: PIFProjectBuilder {
657662
let moduleMapFileContents: String?
658663
let shouldImpartModuleMap: Bool
659664

665+
var isSwiftModule = false
660666
if let clangTarget = target.underlying as? ClangModule {
661667
// Let the target itself find its own headers.
662668
settings[.HEADER_SEARCH_PATHS, default: ["$(inherited)"]].append(clangTarget.includeDir.pathString)
@@ -683,6 +689,7 @@ final class PackagePIFProjectBuilder: PIFProjectBuilder {
683689
shouldImpartModuleMap = false
684690
}
685691
} else if let swiftTarget = target.underlying as? SwiftModule {
692+
isSwiftModule = true
686693
try settings.addSwiftVersionSettings(target: swiftTarget, parameters: self.parameters)
687694

688695
// Generate ObjC compatibility header for Swift library targets.
@@ -732,9 +739,11 @@ final class PackagePIFProjectBuilder: PIFProjectBuilder {
732739
if let resourceBundle = addResourceBundle(for: target, in: pifTarget) {
733740
settings[.PACKAGE_RESOURCE_BUNDLE_NAME] = resourceBundle
734741
settings[.GENERATE_RESOURCE_ACCESSORS] = "YES"
735-
settings[.SWIFT_ACTIVE_COMPILATION_CONDITIONS, default: ["$(inherited)"]].append("SWIFT_MODULE_RESOURCE_BUNDLE_AVAILABLE")
742+
if isSwiftModule {
743+
settings[.SWIFT_ACTIVE_COMPILATION_CONDITIONS, default: ["$(inherited)"]].append("SWIFT_MODULE_RESOURCE_BUNDLE_AVAILABLE")
744+
}
736745
impartedSettings[.EMBED_PACKAGE_RESOURCE_BUNDLE_NAMES, default: ["$(inherited)"]].append(resourceBundle)
737-
} else {
746+
} else if isSwiftModule {
738747
settings[.SWIFT_ACTIVE_COMPILATION_CONDITIONS, default: ["$(inherited)"]].append("SWIFT_MODULE_RESOURCE_BUNDLE_UNAVAILABLE")
739748
}
740749

0 commit comments

Comments
 (0)