Commit Graph

40 Commits

Author SHA1 Message Date
Rintaro Ishizaki
ca5a020e21 [CMake] '-no-emit-module-separately-wmo' for swift modules
Emitting modules in separate frontend job doesn't give any benefits
because single add_library is just a single job from CMake's point of
view. Clients need to wait for `.dylib`/`.so` being emitted before using
the `.swiftmodule`. *Not* emitting modules separately is actually faster
in CMake because it doesn't parse and typecheck the source code twice.
2025-03-11 13:33:34 -07:00
Rintaro Ishizaki
6f6742f060 Merge pull request #78622 from rintaro/sanitizer-rdar142516855
[CMake] Globally set sanitizer options for Swift targets
2025-01-28 04:56:44 -08:00
Alastair Houghton
18496c5626 [Backtracing] Remove support for implicit import of _Backtracing.
We're going to rename the module to Runtime, and it isn't going to be an
implicit import, so we don't need any of this.

rdar://124913332
2025-01-17 10:09:36 +00:00
Rintaro Ishizaki
84a09071cb [CMake] Globally set sanitizer options Swift targets
For C/CXX targets, sanitizer options are set by 'CMAKE_{C|CXX}_FLAGS' in
HandleLLVMComfig.cmake. However for Swift targets, they are set for each
target. That caused some mismatch issues. Instead set them globally for
Swift targets too.

rdar://142516855
2025-01-13 15:54:39 -08:00
Rintaro Ishizaki
fdacd9dabb [CMake] Add 'CXX_INTEROP' option to add_pure_swift_host_library 2024-10-02 19:34:59 -07:00
Rintaro Ishizaki
7a002b29b9 [CMake] Enable library evolution unconditionally for package CMO
'-package-cmo' requires consistent resilient settings among package
modules at this point. Even if a module (e.g. execuables) don't provide
any public interfaces, specify '-enable-library-evolution'

rdar://135110846
2024-09-04 09:25:29 -07:00
Rintaro Ishizaki
3bf75e7130 [CMake] Typo target -> target_name 2024-08-28 20:55:52 -07:00
Rintaro Ishizaki
371dfe860e [CMake] Build macro plugin and plugin servers as a package
Build 'lib/swift/host' libraries and linking binaries as a single
"package" instead of buillding the linking binaries with
"prefer-interface" hack.
This enables CMO between them.
2024-08-28 15:03:05 -07:00
Alastair Houghton
7268640b60 Merge pull request #74731 from al45tair/eng/PR-116525111
[Build][Linux] Set `--build-id=sha1` for the linker.
2024-06-28 11:31:36 +01:00
Alastair Houghton
35f123bbbf [Build][Linux] Set --build-id=sha1 for the linker.
This means we will get build IDs in the tools and standard library,
which is useful for debugging (it lets us associate debug symbols with
the binaries later on, as well as allowing us to reliably identify
exactly which binary we are looking at).

rdar://116525111
2024-06-27 12:21:50 +01:00
Rintaro Ishizaki
2f7aa428db [Macros] In-process plugin server
Separate swift-syntax libs for the compiler and for the library plugins.
Compiler communicates with library plugins using serialized messages
just like executable plugins.

* `lib/swift/host/compiler/lib_Compiler*.dylib`(`lib/CompilerSwiftSyntax`):
  swift-syntax libraries for compiler. Library evolution is disabled.
* Compiler (`ASTGen` and `swiftIDEUtilsBridging`) only depends on
  `lib/swift/host/compiler` libraries.
* `SwiftInProcPluginServer`: In-process plugin server shared library.
  This has one `swift_inproc_plugins_handle_message` entry point that
  receives a message and return the response.
* In the compiler
  * Add `-in-process-plugin-server-path` front-end option, which specifies
    the `SwiftInProcPluginServer` shared library path.
  * Remove `LoadedLibraryPlugin`, because all library plugins are managed
    by `SwiftInProcPluginServer`
  * Introduce abstract `CompilerPlugin` class that has 2 subclasses:
    * `LoadedExecutablePlugin` existing class that represents an
      executable plugin
    * `InProcessPlugins` wraps `dlopen`ed `SwiftInProcPluginServer`
  * Unified the code path in `TypeCheckMacros.cpp` and `ASTGen`, the
    difference between executable plugins and library plugins are now
    abstracted by `CompilerPlugin`
2024-06-17 11:36:52 -07:00
Daniel Rodríguez Troitiño
face056ec3 [CMake] Respect LLVM instrumentation variables in libraries and executables (#73629)
In apple/swift#71135 I added this code to `add_pure_swift_host_library`
but failed to realize that it was also needed in
`add_pure_swift_host_tool`. Extract the code into a helper function and
invoke it from both functions in order to be able to instrument the
`swift-plugin-server` and other pure Swift tools.
2024-05-15 15:02:39 -07:00
Rintaro Ishizaki
a16ad9c274 Merge pull request #71173 from rintaro/cmake-parservalidatoin
[CMake] Add option to perform SwiftParser validation by default
2024-04-12 15:03:31 -07:00
Finagolfin
fcf7614638 [CMake] Add broader support for cross-compiling the portions of the compiler that are written in Swift to non-Darwin Unix
Add cross-compilation flags for the newly added Swift source in `lib/ASTGen/`,
similar to how `SwiftCompilerSources/` is already cross-compiled for other
platforms. Make sure the Swift source in the compiler builds and links against
`SWIFTLIB_DIR` in this cross-compilation build directory, not the one that comes
with the native host compiler.

This requires changing the dependency chain in `CROSSCOMPILE` mode, as normally
the Swift compiler is built first when building natively for the host, then it's
used to build the stdlib. However, when cross-compiling the toolchain, the stdlib
must be cross-compiled first by the host compiler, then the portions of the
Swift compiler written in Swift must be cross-compiled with that new stdlib. All
these dependency changes simply change that compilation order when cross-compiling,
including removing the dependency that the Swift compiler is built before the
stdlib when cross-compiling the Swift compiler.

All changes in this pull are gated on the `CROSSCOMPILE` mode, so they will
not affect any of the existing CI or build presets.
2024-02-13 12:24:24 +05:30
Daniel Rodríguez Troitiño
cc25000e1d [CMake] Respect LLVM instrumentation variables in AddPureSwift.cmake (#71135)
If one is building Swift against an instrumented LLVM build, when the
functions in AddPureSwift.cmake tries to link Swift code that also links
LLVM instrumented code, the linking will fail because the linker will
not use the profiling runtimes.

The modifications replicate the existing code in LLVM
HandleLLVMOptions.cmake, but adapted to Swift variables where possible.

The necessary arguments are forwarded through `-Xclang-linker` because
the spelling of the Swift driver does not give access to all the options
that Clang provides.

This has been tested with an unified build, but a standalone build could
still pass the `LLVM_*` variables to the Swift build system to make use
of this code.
2024-01-31 08:47:29 -08:00
Rintaro Ishizaki
810a94cd0f [CMake] Add option to perform SwiftParser validation by default
Disabled by default. We'll enable it for some build presets.

rdar://121545713
2024-01-25 22:32:22 -08:00
Rintaro Ishizaki
b39dba32f3 [CMake] Propagate header changes to pure Swift modules
Changes to the headers imported by Swift files aren't not correctly
propagated in CMake/Ninja. So changes to C/C++ headers didn't rebuild
ASTGen modules. Move the similar hack from SwiftCompilerSources and use
it in ASTGen as well.

rdar://120863405
2024-01-11 14:45:54 -08:00
Evan Wilde
83a4a0be23 Emit private interfaces on all swift libraries
Swift-driver PR [1043](https://github.com/apple/swift-driver/pull/1043)
updated the new driver to always emit private swiftinterface files.
This was not carried back to the old driver, so attempting to bootstrap
the toolchain on a system that does not have the new driver fails to
install because we try to install the private swiftinterface on all
Swift targets.
2024-01-02 16:54:42 -08:00
Rintaro Ishizaki
67af6a0e46 [CMake] Color diagnostics for swift sources
Color is nice.
2023-12-06 10:30:38 -08:00
Hamish Knight
73c6dcb551 [cmake] Fix LLDB for ASTGen
Add the swiftmodule paths for ASTGen via
`-add_ast_path` to the public linker flags such
that downstream linking picks them up, allowing
LLDB to load them when debugging. Also switch
SwiftCompilerModules to using public linker
flags instead of adding the linker flags in
`_add_swift_runtime_link_flags`.
2023-12-05 12:43:25 +00:00
Hamish Knight
e5442fea50 [ASTGen] Enable C++ interop 2023-10-30 23:49:52 +00:00
Hamish Knight
b81e352cfb [cmake] Fix SWIFT_ANALYZE_CODE_COVERAGE
Pass the necessary linker flags as well as the
compile flags to generate coverage.
2023-10-29 14:07:17 +00:00
Rintaro Ishizaki
0165f0979f [CMake] Improve argument list handling of force_target_link_libraries
The argument list handling was a hack and confusing.
2023-09-21 10:35:31 -07:00
Rintaro Ishizaki
f8f7109f7e [CMake] Use global SWIFT_HOST_TRIPLE consistently
Instead of calling 'get_swift_host_triple()' repeatedly, because it
always return the same value.
2023-09-21 09:59:17 -07:00
Rintaro Ishizaki
8909c8a56e [CMake] Centralize the logic to get host '-target' tripple
And pass the value to 'swift-syntax', so they gets correct deployment
target.
2023-09-18 14:44:12 -07:00
Ben Barham
041691184c [CMake] Replace early swift-syntax with FetchContent
Use FetchContent to include swift-syntax directly in swift. This can be
thought of as an `add_subdirectory` for a directory outside the root.

The default build directory will be `_deps/swiftsyntax-subbuild/`, though
the modules and shared libraries will be built in `lib/swift/host` by
passing down `SWIFT_HOST_LIBRARIES_DEST_DIR` to avoid copying them as we
were doing previously.
2023-09-18 14:44:10 -07:00
Saleem Abdulrasool
c8e36f66f5 build: fix the build of the toolchain
This wires up the new macro properly into the build machinery to ensure
that the `distribution` target properly builds and installs the
dependencies.  This fixes the missing `swift-plugin-server` on Windows.
2023-09-06 19:40:45 -07:00
Saleem Abdulrasool
fe42740f3e build: clean up dependency tracking for portability
`:` is not a valid file system character but is used to namespace the
imported targets.  This is then used to create the stamp file.  Sanitize
the name prior to use as a stamp file name.
2023-08-31 18:08:08 -07:00
Finagolfin
010759da20 [CMake] Tweak path separators in new Swift runpaths 2023-08-31 19:26:32 +05:30
Rintaro Ishizaki
8049922861 [CMake] Update host platform check for macro support
"Support Macros in Linux" patches was inconsistent with checking
platforms. Some only checked 'LINUX' but some matches
'LINUX|ANDROID|OPENBSD|FREEBSD'. Although I don't have tested other
platoforms than Linux at all, there's no reason to limit it to Linux.
So use the consistent check to match 'LINUX|ANDROID|OPENBSD|FREEBSD'
2023-08-30 13:52:37 -07:00
Rintaro Ishizaki
9017ef51ce [CMake] Update for review comments 2023-08-25 21:58:38 +00:00
Rintaro Ishizaki
2a2787b2d0 Avoid adding redundant temporary RUNPATH to builder's stdlib
Many shared libs and executables are only run after stdlib/runtime are
built. They don't need to link with builders stdlib at all.
2023-08-24 23:10:20 +00:00
Rintaro Ishizaki
9c9010e5b7 [CMake] Support Macros in Linux
For compiling codes required for macro support, we now need swiftc
compiler in the build machine.

Unlike Darwin OSes, where swiftCore runtime is guaranteed to be present
in /usr/lib, Linux doesn't have ABI stability and the stdlib of the
build machine is not at the specific location. So the built compiler
cannot relies on the shared object in the toolchain.
2023-08-24 17:04:15 +00:00
Stéphan Kochen
7b460ce495 build: fix accidental cmake expansions
As of CMake 3.25, there are now global variables `LINUX=1`, `ANDROID=1`,
etc. These conflict with expressions that used these names as unquoted
strings in positions where CMake accepts 'variable|string', for example:

- `if(sdk STREQUAL LINUX)` would fail, because `LINUX` is now defined and
  expands to 1, where it would previously coerce to a string.

- `if(${sdk} STREQUAL "LINUX")` would fail if `sdk=LINUX`, because the
  left-hand side expands twice.

In this patch, I looked for a number of patterns to fix up, sometimes a
little defensively:

- Quoted right-hand side of `STREQUAL` where I was confident it was
  intended to be a string literal.

- Removed manual variable expansion on left-hand side of `STREQUAL`,
  `MATCHES` and `IN_LIST` where I was confident it was unintended.

Fixes #65028.
2023-07-17 21:50:50 +02:00
Ben Barham
b0b9705ae0 [CMake] Prevent rebuilds of pure swift libraries and executables
`.swiftmodule` is listed as an output of pure swift libraries, but it
isn't updated if there's been no changes (just like the library and
its object files). Add it to the touch hack as well.

Swift *executables* also list `.swiftmodule` as an output, even though
one isn't generated at all. Add a new POST_BUILD command to touch it
regardless.
2023-06-08 20:43:40 -07:00
Ben Barham
7dcebb249c [CMake] Allow install_name_tool to edit pure swift library load paths 2023-06-06 14:02:22 -07:00
Doug Gregor
a41c36934b [CMake] Fix host library builds and rpaths for testing macros
This enables running macro tests on Linux.
2023-05-28 22:20:25 -07:00
Rintaro Ishizaki
d5565c9855 [CMake] Add correct sanitizer options to pure Swift libs/tools
rdar://107056349
2023-03-22 13:05:20 -07:00
Rintaro Ishizaki
025d8746fe [CMake] Set correct RPATH in add_pure_swift_host_tool
Also, build pure swift library/tool with install RPATH like non Swift
things.
2023-03-16 14:00:45 -07:00
Rintaro Ishizaki
f9fba6ce3e [CMake] Move add_pure_swift_host_library to a file
* Move `add_pure_swift_host_library()` from lib/CMakeLists.txt to
  AddPureSwift.cmake so that code outside `lib` can use it
* Add `add_pure_swift_host_tool()` function to make a pure Swift
  host executable target (for future usages)
* Specify depending `SwiftSyntax` modules explicitly because not all
  Swift libraries uses all SwiftSyntax libraries
2023-03-13 19:28:13 -07:00