Commit Graph

89 Commits

Author SHA1 Message Date
Kavon Farvardin
771c99f895 cmake: add support for bootstrapping with swiftly
For hosts that have a swiftly-managed Swift compiler, we could not
bootstrap using those tools, because of some hardcoded assumptions
about where the `/lib` directory lives, relative to the `/bin`
directory that contains the detected `swiftc`.

This patch adds specific support for detecting when the `swiftc`
is coming from a swiftly install and uses the correct paths.

I've tested this patch on my Linux machine that has swiftly 1.0.1,
with the Swift 6.1.2 toolchain.
2025-08-13 14:41:01 -07:00
Evan Wilde
90eed66da0 FreeBSD: Set sourcekitInProc rpaths
The sourcekit in proc dynamic library looks up runtimes in a spot
relative to the Swift compiler. Set this location on freebsd, fixing the
sourcekit tests.
2025-06-23 14:16:14 -07:00
Hamish Knight
b60fe39dc2 [SourceKit] Change bundle ID from com.apple to org.swift
rdar://146840864
2025-03-12 10:29:28 +00:00
Ben Barham
652da5555f [SourceKit] Do not hardcode the XPC service name
Write the service name into a resource file rather than have it
hardcoded, allowing it to be updated post-build if necessary.
2025-02-28 21:19:45 -08:00
Hamish Knight
d260bd8ddb [build-script] Remove Xcode generation support
This was quite brittle and has now been superseded
by swift-xcodegen. Remove the CMake/build-script
logic for it, leaving the option behind to inform
users to switch to using xcodegen instead.
2025-02-12 12:19:21 +00: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
Alastair Houghton
6afdcd311f Merge pull request #72061 from al45tair/eng/PR-123504095
[Linux][Runtime][IRGen] Mark metadata sections as retained and support section GC.
2024-05-04 09:23:06 +01:00
eeckstein
74ed041119 Merge pull request #73247 from eeckstein/windows-enable-swift
Enable SwiftCompilerSources on Windows
2024-04-30 09:04:55 +02:00
Alastair Houghton
7698836ecc [Test][SourceKit] Use the *builder*'s swiftrt.o when in hosttools.
We were linking with the newly built `swiftrt.o` when in hosttools mode,
which is wrong because the newly built `swiftrt.o` does not match the
compiler we were using for the `SwiftCompilerSources`.

This manifests as a failure in

  `SwiftCompilerSources/Sources/Optimizer/Utilities/Verifier.swift`

because `self is ForwardingInstruction` fails as we can't find the
protocol conformance records.

rdar://123504095
2024-04-29 10:48:23 +01:00
eeckstein
e9d6ba9154 cmake: enable SwiftCompilerSources on Windows 2024-04-29 10:52:24 +02:00
Eric Miotto
291065d3b1 CMake: amend search path for Swift content from Darwin toolchain
Additional testing showed that the path I initially choose does not work
in all scenarios.

Expands on #73255
Still addresses rdar://127014753
2024-04-26 15:12:24 -07:00
Eric Miotto
5f545b43f9 CMake: add option to link Swift content from Darwin toolchain
This is needed in specific Apple internal configurations -- as a result
of the limited applicability, this option is not exposed through
`build-script` on purpose.

Addresses rdar://127014753
2024-04-25 12:48:50 -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
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
Saleem Abdulrasool
a2cc0d0468 Merge pull request #68780 from hjyamauchi/sourcekitclangdep
Fix the clang dependency of sourcekit libraries.
2023-10-08 10:41:57 -07:00
Rintaro Ishizaki
d2eaa84088 Merge pull request #68807 from rintaro/sourcekit-framework-rpath-rdar115976985
[SourceKit] Fix RPATH to lib/swift/host in SourceKit frameworks
2023-10-02 16:57:18 -07:00
Hiroshi Yamauchi
71d8118af9 Fix the clang dependency of sourcekit libraries.
Because swift_swap_compiler_if_needed updates the compiler ID to
Clang, we need to account for it when deciding to add a dependency on
clang. Otherwise, the sourcekit build could fail due to the clang
executable not having been built there yet.
2023-09-27 14:15:12 -07:00
Rintaro Ishizaki
88ec86f36f [SourceKit] Fix RPATH to lib/swift/host in SourceKit frameworks
Relative path calculation to lib/swift/host was not correct.

rdar://115976985
2023-09-27 13:29:48 -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
00d4879c84 build: adjust the build to support non-Apple environments
Account for import libraries and the associated layout difference on
platforms (e.g. DLLs are placed in `bin`).  This is required to enable
building the macro path on Windows.
2023-09-06 12:45:58 -07:00
Rintaro Ishizaki
537f3180c5 [SourceKit] RPATH 'lib/swift/host' should be added without BOOTSTRAPPING
as long as the Swift parser integration is enabled.
Also, remove redundant RPATH additions.
2023-09-01 11:21:09 -07:00
Rintaro Ishizaki
9d78971b9b [CMake][SourceKit] Add RPATH to 'lib/swift/host'
RPATH to 'lib/swift/host' was missing in Darwin platform.
2023-08-30 11:56:00 -07:00
Rintaro Ishizaki
602604be74 [CMake] Further cleanup for RUNPATH setting
`$ORIGIN` is only supported in Linux, BSD, etc. (i.e. not in Windows)
2023-08-25 23:42:19 +00:00
Rintaro Ishizaki
914a6fdf7a [CMake] Fix weiredness in swift runtime linking for SourceKit libraries
SourceKit components are never built while bootstrapping stages. So it
doen't need to have stage 0 or 1 handling.
2023-08-25 22:37:34 +00:00
Rintaro Ishizaki
0f0c4925ae [CMake] Fatal error when bootstrapping is not "hosttools"
and Swift parser integration is enabled.
If swift parser integration is enabled, SwiftSyntax libraries are always
built with host tools. Other SwiftCompilerSources modules must use the
same runtime with parser libraries.
2023-08-24 23:31:47 +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
Doug Gregor
3ca13588a4 [SourceKit] Fix paths when including the new Swift compiler 2023-05-28 23:27:15 -07:00
Rintaro Ishizaki
9004fd24d4 [ASTGen] Separate JSON serialization module from ASTGen
For future usage from other host libraries written in Swift

For CMake:
 * Explicitly specify LINKER_LANGAGE to CXX in existing components so
   that 'swiftc' is not used when linking with 'swiftASTGen'
 * Add 'EMIT_MODULE' argument to 'add_pure_swift_host_library' to emit
   .swiftmodule usable from other Swift libraries.
2023-03-09 19:15:45 -08:00
Ben Barham
c8e092d078 [SourceKit] Add required rpath back to sourcekitd RPATH_LIST
This was modified to `.../swift/host` in
b338472a2b, but the SourceKit libraries
are not under `swift/host`.

Resolves rdar://103006159.
2022-12-05 20:24:49 -08:00
Doug Gregor
b338472a2b Start building libswift_CompilerPluginSupport into lib/swift/host. 2022-11-30 13:54:03 -08:00
Doug Gregor
20013181e1 [CMake] Link to swift-syntax libriares from lib/swift/host. 2022-11-30 13:54:03 -08:00
Doug Gregor
52b64e53ae [SourceKit] Make sure we link the compiler plugin support library 2022-11-15 20:52:40 -08:00
Doug Gregor
77dfffc49e [CMake] Use an absolute path when adding Swift runtime paths.
The SourceKit version of these operations takes an absolute path, whereas
the primary one takes a relative path.

Fixes rdar://100976577
2022-10-10 11:28:20 -07:00
Doug Gregor
7478df009d [CMake] Ensure that the SourceKit framework links Swift as needed 2022-10-07 15:47:29 -07:00
Doug Gregor
4da85ea091 Clean up build logic for ASTGen library.
Only introduce it and its dependency when the new Swift parser is being
built, and rely more on existing logic to make sure we get the right
build/link flags.
2022-10-07 10:19:05 -07:00
Doug Gregor
962e330e9a [CMake with Swift] Add toolchain lib path for stage != 0 bootstrapping builds.
Fixes a linker failure where we cannot find the compatibility libraries.
2022-09-27 14:40:21 -07:00
Alex Hoppen
53901f5a22 [Build] Ensure that we link in SwiftSyntax and Swift for SourceKit
This applies the changes from c50b142a14 to AddSwiftSourceKit.cmake.
2022-09-26 17:19:26 +02:00
Josh Soref
436484c8c8 Gardening: Fix spelling mistakes in */SourceKit
* about
* and
* answering
* because
* before
* cancellation
* clear
* comment
* complete
* corresponding
* cursor
* custom
* dependencies
* doesn't
* expression
* extension
* immediately
* implementation
* implicit
* innovation
* intentionally
* occasionally
* oldest
* parameter
* property
* response
* reuseastcontext
* snapshot
* sourcekit_swift_runtime_link_flags
* synchronously
* target
* that
* unlabeled
* usefulness
* work

Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2022-09-21 02:03:25 -04:00
Doug Gregor
b247c6d9f3 Enable build of Swift Swift parser even when bootstrapping is OFF.
The Swift Swift parser doesn't require any bootstrapping, so allow it to
be built even when bootstrapping is off.
2022-09-07 17:52:21 -07:00
Eric Miotto
b6878ce752 Link all compatibility libraries when cross compiling and bootstrapping (#60728)
Refactor the logic so to have a single target to reference the
compatibility libraries for the host, and use that when needed.

The main driver for this change is supporting the cross-compilation of
x86-64 on Apple Silicon.

Supports rdar://90307965
2022-08-31 02:18:19 -07:00
Rintaro Ishizaki
88e1905746 [SourceKit] Link SwiftCompilerModules to SourceKit
This is required for SourceKit to parse Regex literals

rdar://90236990
2022-03-30 09:14:57 -07:00
Saleem Abdulrasool
b6d2c5bc9a Revert "build: add a workaround for CMake[>=3.22] and SourceKit"
This reverts commit 1e5df70d89.

This does not actually impact the build, so revert it to reduce the
complexity in the build.
2021-12-22 10:15:26 -08:00
Saleem Abdulrasool
1e5df70d89 build: add a workaround for CMake[>=3.22] and SourceKit
The switch between compilers causes problems due to new flags being used
for building.  This adds a workaround to avoid the search path
re-ordering which breaks the build with a newer CMake.
2021-12-03 16:26:38 -08:00
Argyrios Kyrtzidis
fcad3802ea [AddSwiftSourceKit.cmake] Add dependency to the module map file due to the custom pre-build command 2021-09-12 16:53:58 -07:00
Ben Langmuir
d7b813b9ef [sourcekit] Identify xpc service by toolchain instead of sdk
rdar://72310494
2020-12-14 13:31:35 -08:00
Ben Langmuir
d4a52b8cb7 [sourcekit] Avoid duplicating implementation of InProc and XPC service when possible
When installing both InProc and XPC versions of sourcekitd, dynamically
link the XPC service to the InProc version. This lets us install both
frameworks without wasting the disk space from having another copy of
the swift frontend statically linked.
2020-11-10 14:31:40 -08:00
Butta
69d04aad08 [linux] remove absolute rpath of /usr/lib/swift/linux added to many shared libraries
This was presumably added as a backup, in case the libraries in a toolchain
couldn't be found, but will not work well, so take it out.
2020-09-25 23:07:14 +05:30
Dario Rexin
6290d8c28d Merge pull request #31125 from compnerd/opt-flags
optimize flag computation
2020-05-01 10:16:34 -07:00