Commit Graph

24 Commits

Author SHA1 Message Date
Evan Wilde
e1d635e71c
Swift: Expand generator expressions in Swift_MODULE_DIRECTORY
This patch makes the `Swift_MODULE_DIRECTORY` property behave more like
the other output directory properties, allowing generator expressions
and fixing the behavior with multi-config generators.

Issue: #26010
2024-12-09 10:37:05 -08:00
Winfried Auner
75e4cd8d18 Ninja: Fix escaping of paths with spaces for Swift tooling
If a path inside a project contains spaces, the generated Ninja
definitions previously contained superfluous quotes.

Fixes: #26404
2024-11-01 08:59:32 -04:00
Brad King
9e3b559b6a Tests: Update cmake_minimum_required versions to 3.10 2024-10-03 14:18:16 -04:00
Dave Abrahams
5bb7f8a4dd Swift: Use per-config module file locations in multi-config generators
Place `.swiftmodule` files a subdirectory named after the configuration.

Fixes: #25864
Fixes: #25997

- Swift/RunCMakeTest.cmake:
  - CMP0157-OLD was enabled for Xcode, where it works.
  - A test was added that verifies .swiftmodule's are generated into
    separate directories with multi-config generators.

- Tests/SwiftOnly/CMakeLists.txt: tests were added that validate that
  cross-subdirectory module dependencies (via target_link_libraries)
  work.
2024-05-24 15:23:41 -07:00
Dave Abrahams
acfcce7e1b Swift: test that CMAKE_Swift_MODULE_DIRECTORY is respected. 2024-05-16 13:54:36 -07:00
Brad King
1c9e514d28 Merge topic 'swift-module-libraries'
56e5cea600 Swift: Support module libraries with command-line build systems

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !9379
2024-04-16 08:47:11 -04:00
Evan Wilde
56e5cea600
Swift: Support module libraries with command-line build systems
Wire up the flags needed to support module libraries built and used with
Swift. We need to pass `-bundle` to the linker when linking module
libraries on Darwin, and we need to pass `-export-dynamic` to the linker
when emitting an executable that exports symbols on Linux. This patch
wires up `CMAKE_SHARED_MODULE_CREATE_Swift_FLAGS` and
`CMAKE_SHARED_MODULE_LOADER_Swift_FLAG` on Darwin, and hooks up
`CMAKE_EXE_EXPORTS_Swift_FLAG` on Linux in order to support passing
things correctly.

We can't expose `CMAKE_EXE_LINKER_FLAGS` to Swift, as it contains flags
that the Swift compiler doesn't recognize, but the other
language-specific variables are safe to expose.
2024-04-15 08:23:39 -07:00
Brad King
fbca02163b Merge topic 'swift-fix-submodule-dependencies'
579472d877 Swift: Ninja: Remove module dependency for executables

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !9411
2024-04-10 09:41:39 -04:00
Evan Wilde
579472d877
Swift: Ninja: Remove module dependency for executables
We shouldn't include the swiftmodule in the ninja dependency graph
unless that target emits a swiftmodule.

Fixes: #25869
2024-04-08 18:07:13 -07:00
Brad King
a4e5715959 Tests/SwiftOnly: Bump minimum required CMake to 3.5
This was missed by commit f53bd6f450 (Tests: Bump CMake minimum required
in tests to 3.5, 2023-03-01, v3.27.0-rc1~401^2).
2024-02-08 09:30:40 -05:00
Evan Wilde
4f49f7fc0b Tests: Fix SwiftOnly test on Windows
Add public symbols to SubA and SubB.  The test was broken due to a
broken build graph.  The build graph expects libraries to emit the
`.lib` file.  `link.exe` only emits the implib if the library exports at
least one symbol. Because these two libraries were empty, nothing was
generated.

Fixing by adding a public symbol to both libraries.

Issue: #25573
2024-01-24 14:43:21 -05:00
Evan Wilde
9bed4f4d81
Swift/Ninja: Split compilation model
Splitting the Swift build into an object build and a separate link step,
instead of building and linking in one step. The immediate benefit is
LSP support because we are able to emit compile-commands for Swift files
now. Additionally, it is possible to specify flags to the compile step,
enabling folks to emit C and C++ headers from their Swift builds for
C/C++ interop, without needing custom commands. Eventually, this gives
us a path toward working object libraries.

Object Libraries:
 - Object libraries don't work today because CMake doesn't emit targets
   for object libraries into the Ninja build file.
 - tl;dr: Object libraries work if they aren't WMO. Still need work to
   make WMO'd object libraries work.

   Object libraries still don't completely work with this patch because,
   while we emit the targets, the `TARGET_OBJECTS` generator expression
   expansion has a separate mechanism for determining what the names of
   the objects are based on the input source files, so targets that
   depend on an object library built with a whole-module optimization
   will depend on objects based on the name of the source file instead
   of the actual emitted object file.

These features require being able to accurately model wholemodule builds
though, because we actually need to track object files and WMO affects
what objects are emitted. For that, we require CMP0157 use the NEW
policy. When it's OLD, we have to fall back on the old behavior and
cannot provide object libraries or the compile-commands for LSP.

Issue: #25308
2023-12-15 05:51:13 -08:00
Evan Wilde
c1d787e473 Swift: Add abstraction for compilation mode
Add a `CMAKE_Swift_COMPILATION_MODE` variable and corresponding
`Swift_COMPILATION_MODE` target property to control the compilation
mode.  Select among `wholemodule`, `singlefile`, and `incremental`.

Add policy CMP0157 to remove the default `-wmo` flags in favor of the
abstract setting.

Issue: #25366
2023-11-17 08:43:21 -05:00
Evan Wilde
4165eb3d0b
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.
2023-01-19 11:49:24 -08:00
Brad King
cb4e6702b2 Xcode: Implement Swift include directories
Populate Xcode's `SWIFT_INCLUDE_PATHS` build setting with the
target-wide include directories.

Issue: #24116
2022-11-02 17:03:21 -04:00
David Geldreich
5cb625eb2f Xcode: Pass compile definitions to Swift
correct Xcode generator Swift definitions
original code was defining GCC_PREPROCESSOR_DEFINITIONS which is valid only for C languages
add definitions to SWIFT_ACTIVE_COMPILATION_CONDITIONS when Swift language is used in the target
add test in SwiftOnly
for old Xcode (<8.0), append defines to cflags so it ends up in OTHER_SWIFT_FLAGS

Fixes: #23637
2022-07-07 15:00:32 +02:00
Brad King
078ba4b2a4 Swift: Update test case to try CMP0126 NEW behavior
Extend the `SwiftOnly` test to cover the fix in commit 3ddd7f3576
(enable_language: Fix test for working compiler with CMP0126 NEW
behavior, 2021-07-15), as that commit did for the `CSharpOnly` test.

Fixes: #22451
2021-07-21 11:37:45 -04:00
Brad King
14a5712447 Swift: Fix regression in linking to interface libraries
Since commit 2026915f8f (Swift: Propagate Swift_MODULE_DIRECTORY as include
directory, 2020-02-03, v3.18.0-rc1~547^2) we internally call
`GetAllConfigCompileLanguages` on all directly linked targets without
checking if they are interface libraries that don't compile at all.
That violates an internal assumption and assertion.

Fixes: #20977
2020-07-17 08:26:40 -04:00
Saleem Abdulrasool
2026915f8f Swift: Propagate Swift_MODULE_DIRECTORY as include directory
Teach include directory computation for Swift to implicitly propagate
the `Swift_MODULE_DIRECTORY` of all linked targets as include
directories.  This is required to ensure that the swiftmodule of a
linked target is accessible to the compiler of the current target.

Fixes: #19272
2020-03-12 11:50:43 -04:00
Brad King
601fe84bd1 Swift: Restore support for enabling with INTERFACE libraries
The check added in commit b06f4c8a74 (Swift: disallow WIN32_EXECUTABLE
properties, 2019-05-31, v3.15.0-rc1~9^2) makes sense only for
executables because the `WIN32_EXECUTABLE` property is defined only for
them.  Running the check on other target types, particularly those that
do not link such as INTERFACE libraries, violates internal assumptions.
In particular, `GetLinkerLanguage` should not be called on such targets.

Fixes: #19528
2019-07-29 15:24:29 -04:00
Brad King
96dece6dc1 Xcode: Update default Swift language version for Xcode 10.2
Xcode 10.2 no longer supports Swift language versions before 4.0.

Fixes: #18871
2019-02-04 13:26:10 -05:00
Brad King
b35568f3f9 Xcode: Add option to set Swift language version
Create a new CMAKE_Swift_LANGUAGE_VERSION variable to specify the
SWIFT_VERSION attribute in a generated Xcode project.  Ideally this
would be a `<LANG>_STANDARD` property but since Swift support is
very minimal we should reserve that property for more complete
treatment later.

Issue: #16326
2016-09-26 08:46:23 -04:00
Gregor Jasny
61b6d52ad0 Swift: Use dump instead of println
With Swift 2.0 in Xcode7 the println function was renamed into
print. Use dump function instead which adds newlines like println.
2015-09-01 20:32:38 +02:00
Brad King
bf11253163 Add rudimentary support for the Apple Swift language with Xcode
Allow the `Swift` language to be enabled with the Xcode generator for
Xcode >= 6.1.  Reject it on other generators and with older Xcode
versions.  Since Apple is the only vendor implementing the language
right now, the compiler id can be just `Apple`.
2015-07-06 16:15:49 -04:00