Commit Graph

828 Commits

Author SHA1 Message Date
3405691582
0158137afc Supply -z,nobtcfi on x86_64 as well.
On older x86_64 hardware, this isn't a problem since CET IBT hardware
support may not have been available. However, newer x86_64 hardware
supports the feature, which will lead to BTCFI failures. Therefore ensure
the same BTCFI disabling logic applies on x86_64 as well as aarch64.
2025-10-20 21:23:45 -04:00
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
bca1378fdb SILOptimizer: Disable invalid passes in C++-only compiler
The SimplifyCFG and LoopRotate passes result in verification failures
when built in a compiler that is not built with Swift sources enabled.

Fixes: rdar://146357242
2025-04-21 12:46:01 -07:00
3405691582
2c35bca3f8 Use -z,nobtcfi when BTCFI is disabled on OpenBSD.
This was accidentally left off from #80389, and will properly ensure
BTCFI enforcement is disabled on the platform when required.
2025-04-04 18:13:01 -04:00
Yuta Saito
9d4e5b6911 [build] Add initial support for Emscripten SDK
This patch adds initial support for Emscripten SDK alongside the existing
support for WASI SDK. This is a first step towards building a part of
Swift compiler for Emscripten target (which will be used to build LLDB
with Swift to WebAssembly target).
2025-02-13 00:53:45 +00: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
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
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
Egor Zhdan
1d5481655f Merge pull request #73619 from apple/egorzhdan/bootstrapping-without-backdeployment
[build] Fix bootstrapping builds that disable back-deployment
2024-05-22 15:23:50 +01:00
Egor Zhdan
421ee98fc5 [build] Fix bootstrapping builds that disable back-deployment
This fixes a build that passes `-D SWIFT_STDLIB_SUPPORT_BACK_DEPLOYMENT=NO` and `-D BOOTSTRAPPING_MODE=BOOTSTRAPPING-WITH-HOSTLIBS`.

Previously a few CMake errors would be emitted:
```
CMake Error at cmake/modules/AddSwift.cmake:478 (get_property):
  get_property could not find TARGET HostCompatibilityLibs.  Perhaps it has
  not yet been created.

CMake Error at cmake/modules/AddSwift.cmake:527 (add_dependencies):
  add_dependencies called with incorrect number of arguments
Call Stack (most recent call first):
  cmake/modules/AddSwift.cmake:969 (_add_swift_runtime_link_flags)
  tools/driver/CMakeLists.txt:23 (add_swift_host_tool)
```
2024-05-20 14:31:12 +01:00
Eric Miotto
ce0e620d1a [CMake] allow custom options when building the compiler with debug info
Currently those are hardcoded to `-g`, but in some Apple internal
configurations we would like to change them.

There are other part of the build system that hardcode `-g`
(e.g. in `SwiftCompilerSources` and `AddSwiftStdlib.cmake`),
but we are not interested in those at the moment -- we will address those
in the future if need be.

Supports rdar://127503136
2024-05-14 08:42:35 -07:00
Hamish Knight
37dc7ce5b5 [cmake] Only check HostCompatibilityLibs for bootstrapping builds
Locally I build debug builds without the standard library,
using a copy of the stdlib in my release build. This hit
a CMake error here since the `HostCompatibilityLibs` target
isn't defined. Update to only access it when doing a bootstrapping
build.
2024-05-01 22:43:29 +01:00
Eric Miotto
dbc8c4b08b Merge pull request #73065 from edymtt/edymtt/use-hostcompatibilitylibs-for-all-bootstrapping-modes
CMake: ensure Swift host tools depend on HostCompatibilityLibs target
2024-04-30 09:16:31 -07:00
Eric Miotto
4d14497016 CMake: ensure Swift host tools depend on HostCompatibilityLibs target
At the time I implemented #60728, I did not realize that in all the
bootstrapping mode we need to depend on the compatibility libraries we
build -- otherwise when targeting a low deployment target we risk
failing because we are not able to find such libraries.

Addresses rdar://126552386
2024-04-29 10:52:21 -07: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
eeckstein
9504de5ed7 Merge pull request #71552 from finagolfin/cross-compile
[CMake] Add broader support for cross-compiling the portions of the compiler that are written in Swift to non-Darwin Unix
2024-03-15 16:28:38 +01:00
Allan Shortlidge
347a1409ba CMake: Pass -no_warn_duplicate_libraries to the linker when supported.
The output of build-script on macOS is currently full of spammy linker warnings
like this:

```
ld: warning: ignoring duplicate libraries: '.../swift-project/build/Ninja-RelWithDebInfoAssert/llvm-macosx-arm64/lib/libLLVMDemangle.a', 'lib/libswiftDemangling.a'
```

Apple's linker complains about duplicate libraries, which CMake likes to do to
support ELF platforms. To silence that warning, we can use
`-no_warn_duplicate_libraries`, but only in versions of the linker that support
that flag.
2024-03-12 22:25:05 -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
Ben Barham
406d5337dc Merge pull request #69538 from finagolfin/android
[android] Add more changes to build the compiler
2023-12-15 10:57:21 -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
Rintaro Ishizaki
abd416480f [Windows] Link host tools with 'swiftrt.obj'
swiftrt.obj is required for making things work
2023-11-16 11:01:32 -08:00
Finagolfin
bf137cb30d [android] Add more changes to build the compiler 2023-11-06 21:53:56 +05:30
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
8dbde04c61 Merge pull request #68408 from rintaro/fetch-content
[CMake] Replace early swift-syntax with FetchContent
2023-09-28 11:22:10 -07:00
Alastair Houghton
e1827448e5 [Linux][Build] Use host swiftrt.o when in HOSTTOOLS mode.
When we're building with host tools, we should use the host's swiftrt.o
and not the one we've just built when we're trying to build tools that we
will run on the host system.

rdar://115774613
2023-09-22 15:45:54 +01: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
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
dc6877334f [CMake] Stop some exectuable link with swiftCore
swift-compatibility-symbols, swift-def-to-strings-converter,
and swift-serialize-diagnostics don't use any Swift modules. But when
SWIFT_SWIFT_PARSER was enabled, they are linked with swiftCore. But
these binaries can be executed before the runtime is being built.
We need to stop them linking with swiftCore.
2023-08-28 19:10:01 +00:00
Rintaro Ishizaki
757aaa347d [CMake] Set LD_LIBRARY_PATH to builder's runtime when building stdlib
In Linux. Instead of setting temporary "fallback" RUNPATH, Set
LD_LIBRARY_PATH to builder's runtime when building standard library.
So we don't need to strip the temporary RUNPATH when installing.
2023-08-28 01:16:18 +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
Alex Hoppen
ef8e4ac0f3 [AST] Remove gyb_syntax_support
We are no longer using these Python files to generate anything in SwiftSyntax. We can just remove them and instead commit the generated `.def` files.
2023-08-01 17:20:14 -07: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
Saleem Abdulrasool
53e4e19e71 build: add a workaround for ARM64 Windows
MSVC 17.6p3 introduced new ARM64 intrinsics for atomic
(load-acquire/store-release) operations.  Since clang does not support
this yet, force the fallback path to temporarily unblock the build while
we implement support for the `__stlr[8|16|32|64]` intrinsics in clang.

See: llvm/llvm-project#62103
2023-06-21 22:08:59 -04:00
Doug Gregor
c9383ff619 [CMake] Add paths for building Swift code against host toolchain
When building Swift code into the compiler (e.g, the new Swift parser
along with macros support), make sure we always add the appropriate
paths to (1) link against the host Swift toolchain, and (2) find the
host Swift libraries (such as SwiftSyntax) at runtime.

The CMake code for doing this was only running for Darwin builds, so
generalize it to also work on Linux.
2023-05-28 17:01:01 -07:00
Alex Langford
7c52fe21d6 [CMake] Workaround sanitizer flag bug in swift driver
Some versions of the swift driver have a bug where passing `-sanitize=`
does not emit the correct `-fsanitize=` flag for the clang link step.
Although this is being fixed, we must be able to correctly build with older
versions of the swift driver for some period of time. We workaround that
issue by explicitly passing the correct `-fsanitize=` argument
ourselves.

This works around rdar://107733898
2023-04-06 16:58:01 -07:00
Ben Barham
4186d628e1 [CMake] Add lib to swift host libraries link directories
Our libraries have a `LC_LINKER_OPTION` for eg. `-lswiftLLVMJSON`.
This is resolved (probably just based on the actual libswiftLLVMJSON.a
added to the link command) by ld, but not by lld. Add in a link
directory so that these libraries can be found.
2023-03-15 16:55:01 -07:00
Mishal Shah
41a903c425 Fix the bad merge from main to rebranch in cmake/modules/AddSwift.cmake 2023-03-01 22:28:05 -08:00
Arnold Schwaighofer
ed9da31fc6 Revert "Merge pull request #63650 from al45tair/backtracing/add-libexec"
This reverts commit b88f3b6545, reversing
changes made to be4caa5b93.
2023-02-28 10:08:56 -08:00
swift-ci
8c1e33acd8 Merge remote-tracking branch 'origin/main' into rebranch 2023-02-28 06:35:01 -08:00
Alastair Houghton
f68c4b40f3 Add support for building target executables into libexec.
We're going to add a program, `swift-backtrace`, that gets built alongside
the stdlib and the runtime, and that needs to be installed in libexec/swift
alongside the libraries in lib/swift.

It wants to be built with the stdlib/runtime because there's an internal
interface between `swift-backtrace` and the runtime, so the program needs
to stay in lock-step with the runtime library.

rdar://105390807
2023-02-13 20:04:37 +00:00
swift-ci
53edbec88e Merge remote-tracking branch 'origin/main' into rebranch 2022-12-16 08:55:12 -08:00
Alex Hoppen
1ebe7ef6a2 Copy files from SwiftSyntax’s gyb_syntax_support that are relevant to the compiler to this repo
This allows us to evolve e.g. token kinds and how attributes are modelled independently between SwiftSyntax and the compiler. It also makes it easier to e.g. add an attribute because you don’t need to create PRs for two repositories.
2022-12-15 16:40:28 +01:00
swift-ci
21b2cf9c50 Merge remote-tracking branch 'origin/main' into rebranch 2022-12-01 20:14:31 -08:00
Doug Gregor
8f7b303e83 Set host libraries rpath correctly for bootstrapped builds 2022-11-30 18:11:02 -08:00