Skip to content

Commit 354df9d

Browse files
authored
fix modulemap generation on window using swift-build (#9179)
- Windows paths need to be escaped
1 parent 4bc7241 commit 354df9d

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

Sources/PackageLoading/ModuleMapGenerator.swift

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@ import TSCBasic
1818
/// Name of the module map file recognized by the Clang and Swift compilers.
1919
public let moduleMapFilename = "module.modulemap"
2020

21-
extension Basics.AbsolutePath {
22-
fileprivate var moduleEscapedPathString: String {
23-
return self.pathString.replacing("\\", with: "\\\\")
24-
}
25-
}
26-
2721
/// A protocol for targets which might have a modulemap.
2822
protocol ModuleMapProtocol {
2923
var moduleMapPath: Basics.AbsolutePath { get }
@@ -179,9 +173,9 @@ public struct ModuleMapGenerator {
179173
var moduleMap = "module \(moduleName) {\n"
180174
switch type {
181175
case .umbrellaHeader(let hdr):
182-
moduleMap.append(" umbrella header \"\(hdr.moduleEscapedPathString)\"\n")
176+
moduleMap.append(" umbrella header \"\(hdr.escapedPathString)\"\n")
183177
case .umbrellaDirectory(let dir):
184-
moduleMap.append(" umbrella \"\(dir.moduleEscapedPathString)\"\n")
178+
moduleMap.append(" umbrella \"\(dir.escapedPathString)\"\n")
185179
}
186180
moduleMap.append(
187181
"""

Sources/SwiftBuildSupport/PackagePIFProjectBuilder+Modules.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import Foundation
1414
import TSCUtility
1515

1616
import struct Basics.AbsolutePath
17+
import struct Basics.RelativePath
1718
import class Basics.ObservabilitySystem
1819
import func Basics.resolveSymlinks
1920
import struct Basics.SourceControlURL
@@ -352,8 +353,8 @@ extension PackagePIFProjectBuilder {
352353

353354
// Generate a module map file, if needed.
354355
var moduleMapFileContents = ""
355-
var moduleMapFile = ""
356356
let generatedModuleMapDir = "$(GENERATED_MODULEMAP_DIR)"
357+
let moduleMapFile = try RelativePath(validating:"\(generatedModuleMapDir)/\(sourceModule.name).modulemap").pathString
357358

358359
if sourceModule.usesSwift && desiredModuleType != .macro {
359360
// Generate ObjC compatibility header for Swift library targets.
@@ -366,8 +367,6 @@ extension PackagePIFProjectBuilder {
366367
export *
367368
}
368369
"""
369-
moduleMapFile = "\(generatedModuleMapDir)/\(sourceModule.name).modulemap"
370-
371370
// We only need to impart this to C clients.
372371
impartedSettings[.OTHER_CFLAGS] = ["-fmodule-map-file=\(moduleMapFile)", "$(inherited)"]
373372
} else if sourceModule.moduleMapFileRelativePath(fileSystem: self.pifBuilder.fileSystem) == nil {
@@ -376,22 +375,21 @@ extension PackagePIFProjectBuilder {
376375
log(.debug, "\(package.name).\(sourceModule.name) generated umbrella header")
377376
moduleMapFileContents = """
378377
module \(sourceModule.c99name) {
379-
umbrella header "\(path)"
378+
umbrella header "\(path.escapedPathString)"
380379
export *
381380
}
382381
"""
383382
} else if case .umbrellaDirectory(let path) = sourceModule.moduleMapType {
384383
log(.debug, "\(package.name).\(sourceModule.name) generated umbrella directory")
385384
moduleMapFileContents = """
386385
module \(sourceModule.c99name) {
387-
umbrella "\(path)"
386+
umbrella "\(path.escapedPathString)"
388387
export *
389388
}
390389
"""
391390
}
392391
if moduleMapFileContents.hasContent {
393392
// Pass the path of the module map up to all direct and indirect clients.
394-
moduleMapFile = "\(generatedModuleMapDir)/\(sourceModule.name).modulemap"
395393
impartedSettings[.OTHER_CFLAGS] = ["-fmodule-map-file=\(moduleMapFile)", "$(inherited)"]
396394
impartedSettings[.OTHER_SWIFT_FLAGS] = ["-Xcc", "-fmodule-map-file=\(moduleMapFile)", "$(inherited)"]
397395
}

0 commit comments

Comments
 (0)