Skip to content

Ninja: Emit swiftmodule from executable with exports

This patch adds support for tracking the swiftmodules for executables exporting symbols.

This fixes a bug in the earlier implementation around emitting the swiftmodule. Previously, the code would use CMAKE_EXE_EXPORTS_Swift_FLAG to inject the -emit-module, and module path information into the CMAKE_Swift_LINK_EXECUTABLE rule. Because Swift skips the build step and only runs during the link phase, these flags were injected in cmNinjaNormalTargetGenerator::ComputeLinkCmd instead of cmLocalGenerator::GetTargetFlags where it is done normally.

Unfortunately, injecting in ComputeLinkCmd didn't do anything because we have a linkCmd so ComputeLinkCmd exits early, before the EXE_EXPORT flags get added to the link command.

Instead of playing with that flag, CMake checks CMAKE_Swift_LINK_EXECUTABLE_WITH_EXPORTS and uses that as the link rule if it exists and falls back on CMAKE_Swift_LINK_EXECUTABLE. I've defined that variable in terms of CMAKE_Swift_LINK_EXECUTABLE with the necessary additional flags for emitting the swift module instead. This has the same end effect as the desired behavior, but simplifies things a bit.

Since we're generating the swiftmodule for executables with exports, I've also updated the dependency graph to include the swiftmodule as an output in the build dependency graph if the executable has exports.

Tests updated:

  • RunCMake/NoWorkToDo: Ensure that the build graph does not result in unnecessary rebuilds with exporting executables.

  • SwiftOnly: Ensure that we can consume functions defined in the executable by a library getting linked into said executable.

Topic-rename: ninja-swift-exported-executables

Edited by Brad King

Merge request reports