Is `module.modulemap` required for C/Objc targets?

I have an issue with swift run --repl when using Swift 6.4 beta (swift-driver version: 1.168.4 Apple Swift version 6.4 (swiftlang-6.4.0.25.4 clang-2100.3.25.1) – Target: arm64-apple-macosx27.0.0).

The problem happens when running the command in a package that has a target (or that has a dependency which has a target) which is not written in Swift (tested with C, ObjC), and that does not have a module.modulemap file in the include folder.

The package compiles fine when using swift build, but when using the REPL we get a “missing module” error, for the modules that are not written in Swift.
Adding the module.modulemap fixes the issue (ignoring another issue, where the REPL is launched using standalone -I options (with no value) randomly in the command-line, which hides actual, useful -I options, but that’s another problem…)

My question is: Is the module.modulemap file technically required?
If it is, it’s the build step that is at fault, and it should fail. If not, the REPL run should generate the module.modulemap file(s) and add them in the search path for Swift’s invocation.

Yes, module maps are required—Swift only understands C headers at the module level, not the individual header level.

I would expect SwiftPM using swift run --repl to pass the required flags to the REPL invocation the same way it passes them to the compiler when doing a regular build. If that doesn't work, it sounds like a SwiftPM bug (so your issue is probably better filed under swift-package-manager instead of swift, but I'll let the owners of that project make that determination).

1 Like

Thanks!
That’s true even if I have made an umbrella header in the include folder, right?

I should clarify, the module map is required by the compiler. SwiftPM, sitting on top of the compiler, will automatically generate a module map for you if you have headers in your include folder if you don't supply one yourself. So the compiler does require it (the directory it's in must be passed via -I), but SwiftPM adds the extra convenience on top.

Oh so that looks definitely like an SPM bug, specifically for the run --repl command. I’ll move my issue there.

Done

1 Like