Skip to content

Commit d5dc040

Browse files
committed
[Build] Pass modulemap of dependencies to C targets as well
This enables ObjC targets to import other ObjC targets using @import. <rdar://problem/51669951>
1 parent d5cbf5c commit d5dc040

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

Sources/Build/BuildPlan.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,6 +1220,13 @@ public class BuildPlan {
12201220
case let target as ClangTarget where target.type == .library:
12211221
// Setup search paths for C dependencies:
12221222
clangTarget.additionalFlags += ["-I", target.includeDir.pathString]
1223+
1224+
// Add the modulemap of the dependency if it has one.
1225+
if case let .clang(dependencyTargetDescription)? = targetMap[dependency] {
1226+
if let moduleMap = dependencyTargetDescription.moduleMap {
1227+
clangTarget.additionalFlags += ["-fmodule-map-file=\(moduleMap.pathString)"]
1228+
}
1229+
}
12231230
case let target as SystemLibraryTarget:
12241231
clangTarget.additionalFlags += ["-fmodule-map-file=\(target.moduleMapPath.pathString)"]
12251232
clangTarget.additionalFlags += pkgConfig(for: target).cFlags

Tests/BuildTests/BuildPlanTests.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,12 @@ final class BuildPlanTests: XCTestCase {
311311

312312
args += ["-g", "-O0", "-DSWIFT_PACKAGE=1", "-DDEBUG=1"]
313313
args += ["-fblocks", "-fmodules", "-fmodule-name=exe",
314-
"-I", "/Pkg/Sources/exe/include", "-I", "/Pkg/Sources/lib/include", "-I", "/ExtPkg/Sources/extlib/include",
315-
"-fmodules-cache-path=/path/to/build/debug/ModuleCache"]
314+
"-I", "/Pkg/Sources/exe/include", "-I", "/Pkg/Sources/lib/include",
315+
"-fmodule-map-file=/path/to/build/debug/lib.build/module.modulemap",
316+
"-I", "/ExtPkg/Sources/extlib/include",
317+
"-fmodule-map-file=/path/to/build/debug/extlib.build/module.modulemap",
318+
"-fmodules-cache-path=/path/to/build/debug/ModuleCache",
319+
]
316320
XCTAssertEqual(exe.basicArguments(), args)
317321
XCTAssertEqual(exe.objects, [AbsolutePath("/path/to/build/debug/exe.build/main.c.o")])
318322
XCTAssertEqual(exe.moduleMap, nil)

0 commit comments

Comments
 (0)