Skip to content

Commit 10fd75f

Browse files
authored
Merge pull request #2891 from neonichu/pif-module-map-fix
Make module map generation conditional
2 parents 4b5d0a6 + c6a32b2 commit 10fd75f

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

Sources/XCBuildSupport/PIFBuilder.swift

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ final class PackagePIFProjectBuilder: PIFProjectBuilder {
562562

563563
let generatedModuleMapDir = "$(OBJROOT)/GeneratedModuleMaps/$(PLATFORM_NAME)"
564564
let moduleMapFile = "\(generatedModuleMapDir)/\(target.name).modulemap"
565-
let moduleMapFileContents: String
565+
let moduleMapFileContents: String?
566566

567567
if let clangTarget = target.underlyingTarget as? ClangTarget {
568568
// Let the target itself find its own headers.
@@ -572,15 +572,20 @@ final class PackagePIFProjectBuilder: PIFProjectBuilder {
572572

573573
// Also propagate this search path to all direct and indirect clients.
574574
impartedSettings[.HEADER_SEARCH_PATHS, default: ["$(inherited)"]].append(clangTarget.includeDir.pathString)
575-
impartedSettings[.OTHER_SWIFT_FLAGS, default: ["$(inherited)"]] +=
576-
["-Xcc", "-fmodule-map-file=\(moduleMapFile)"]
577575

578-
moduleMapFileContents = """
579-
module \(target.c99name) {
580-
umbrella "\(clangTarget.includeDir.pathString)"
581-
export *
582-
}
583-
"""
576+
if !fileSystem.exists(clangTarget.moduleMapPath) {
577+
impartedSettings[.OTHER_SWIFT_FLAGS, default: ["$(inherited)"]] +=
578+
["-Xcc", "-fmodule-map-file=\(moduleMapFile)"]
579+
580+
moduleMapFileContents = """
581+
module \(target.c99name) {
582+
umbrella "\(clangTarget.includeDir.pathString)"
583+
export *
584+
}
585+
"""
586+
} else {
587+
moduleMapFileContents = nil
588+
}
584589
} else if let swiftTarget = target.underlyingTarget as? SwiftTarget {
585590
settings[.SWIFT_VERSION] = swiftTarget.swiftVersion.description
586591
// Generate ObjC compatibility header for Swift library targets.
@@ -597,8 +602,10 @@ final class PackagePIFProjectBuilder: PIFProjectBuilder {
597602
fatalError("unexpected target")
598603
}
599604

600-
settings[.MODULEMAP_PATH] = moduleMapFile
601-
settings[.MODULEMAP_FILE_CONTENTS] = moduleMapFileContents
605+
if let moduleMapFileContents = moduleMapFileContents {
606+
settings[.MODULEMAP_PATH] = moduleMapFile
607+
settings[.MODULEMAP_FILE_CONTENTS] = moduleMapFileContents
608+
}
602609

603610
// Pass the path of the module map up to all direct and indirect clients.
604611
impartedSettings[.OTHER_CFLAGS, default: ["$(inherited)"]].append("-fmodule-map-file=\(moduleMapFile)")

0 commit comments

Comments
 (0)