Skip to content

Commit f460e5c

Browse files
committed
[Build] Consider Swift on Clang Modules as build order dependency
Currently swiftpm fatalError() when some swift package is dependency on a package containing c languages or mixed languages. This shouldn't error out. Swift will not be importable to c modules but there could be swift modules in that package which want to use some external deps. Considering it as a build order dependency should be ok.
1 parent 9ecd75c commit f460e5c

File tree

6 files changed

+12
-1
lines changed

6 files changed

+12
-1
lines changed

Fixtures/DependencyResolution/External/CUsingCDep2/Foo/Sources/swiftExe/main.swift

Whitespace-only changes.

Sources/Build/Command.compile(ClangModule).swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ struct ClangModuleBuildMetadata {
6464
return product.targetName
6565
case let module as CModule:
6666
return module.targetName
67+
case let module as SwiftModule:
68+
return module.targetName
6769
default:
6870
fatalError("ClangModule \(self.module) can't have \(module) as a dependency.")
6971
}

Tests/BuildTests/DescribeTests.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import XCTest
1212

1313
import Basic
14-
import Build
14+
@testable import Build
1515
import PackageDescription
1616
import PackageGraph
1717
import PackageModel
@@ -55,8 +55,17 @@ final class DescribeTests: XCTestCase {
5555
}
5656
}
5757

58+
func testClangModuleCanHaveSwiftDep() throws {
59+
let clangModule = try ClangModule(name: "ClangModule", sources: Sources(paths: [], root: .root))
60+
let swiftModule = try SwiftModule(name: "SwiftModule", sources: Sources(paths: [], root: .root))
61+
clangModule.dependencies = [swiftModule]
62+
let buildMeta = ClangModuleBuildMetadata(module: clangModule, prefix: .root, otherArgs: [])
63+
XCTAssertEqual(buildMeta.inputs, ["<SwiftModule.module>"])
64+
}
65+
5866
static var allTests = [
5967
("testDescribingNoModulesThrows", testDescribingNoModulesThrows),
6068
("testDescribingCModuleThrows", testDescribingCModuleThrows),
69+
("testClangModuleCanHaveSwiftDep", testClangModuleCanHaveSwiftDep),
6170
]
6271
}

0 commit comments

Comments
 (0)