Repository navigation
Emit the swiftmodule at the nested path via CMake's own module properties - #379
Merged
Merged
Conversation
…ties emit_swift_interface() passed its own -emit-module-path for the nested <module>.swiftmodule/<triple>.swiftmodule layout, in addition to the -emit-module-path that CMake always adds. The compiler honors whichever comes last, so the result depends on where CMake places its flag relative to the target's compile options. When CMake's flag wins, a plain <module>.swiftmodule file is produced instead of the nested directory, and clients of the exported SwiftSubprocess::Subprocess target fail at generate time with "Cannot find source file: .../Subprocess.swiftmodule/<triple>.swiftmodule". This happens when building swift-build against swift-subprocess on Windows. Set Swift_MODULE_DIRECTORY and Swift_MODULE so that CMake's own module path is the nested one (or let CMake nest it when CMP0195 is NEW), and drop the extra flag and the custom command that would now duplicate CMake's output.
iCharlesHu
approved these changes
Oct 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On Windows, building swift-build against swift-subprocess fails at configure time. swift-build's CMake does
find_package(SwiftSubprocess)and linksSwiftSubprocess::Subprocess(swiftlang/swift-build#638), and configuration stops with:The same setup configures and builds on Linux and macOS. swift-build would also hit this in the Windows toolchain build, because
build.ps1already passesSwiftSubprocess_DIRto swift-build.Cause
emit_swift_interface()asks for the nested<module>.swiftmodule/<triple>.swiftmodulelayout by passing its own-emit-module-path. CMake always passes an-emit-module-pathof its own as well, so the compiler receives two. It honors the last one, which means the result depends on where CMake puts its flag relative to the target's compile options:When CMake's path wins, a plain
Subprocess.swiftmodulefile is written instead of the nested directory. The existing "Removing regular file …" workaround in this function is there for that same clash.I couldn't reproduce the Windows build locally, so I haven't directly confirmed which detail makes CMake's path win there. This change removes the dependence on flag order altogether, whatever that detail is.
Change
Swift_MODULE_DIRECTORYandSwift_MODULEso that the path CMake emits is the nested path itself. When CMP0195 isNEW, keepSwift_MODULEas<module>.swiftmoduleand let CMake add the triple.-emit-module-path, and theadd_custom_command(OUTPUT …)that would now be a second rule for CMake's own output. The interface source is markedGENERATEDinstead.This also has CMake create the parent directory and track the module as a real build output.
.swiftdocand.swiftsourceinfonow land in the nested directory as well.Testing (macOS, Swift 6.4)
Each configuration is static and shared, Debug:
CMP0157OLD, single-step buildCMP0157NEW, split build; same version as the Windows runnerCMAKE_POLICY_DEFAULT_CMP0195=NEWIn every configuration:
ninja -vshows exactly one-emit-module-path, the nested path.Subprocess.swiftmoduleis a directory.find_package(SwiftSubprocess)andSwiftSubprocess_DIRimports Subprocess and runs a process.cmake --installproduceslib/swift/macosx/Subprocess.swiftmodule/arm64-apple-macos.{swiftmodule,swiftdoc,swiftsourceinfo}.Subprocess_ENABLE_LIBRARY_EVOLUTION=YESfails on macOS with availability errors ('FilePath' is only available in macOS 11.0 or newer; clients of 'Subprocess' may have a lower deployment target). That happens onmainas well, so this PR doesn't address it.Windows is being validated through swift-build's Windows
cmake-smoke-test(swiftlang/swift-build#638, temporarily pointed at this branch) and through toolchain builds.