Commit Graph

1659 Commits

Author SHA1 Message Date
Steven Wu a87c1203fb Merge pull request #88608 from cachemeifyoucan/eng/PR-caching-swift-build
[build-script] Add --enable-caching support with clang-cache and Swift compilation caching
2026-05-05 11:36:52 -07:00
Doug Gregor f6fd1d8025 Merge pull request #88674 from DougGregor/embedded-swift-armv8m
[Embedded] Build standard library & friends for ARMv8-M and ARMv8.1-M
2026-05-03 23:45:17 -07:00
Steven Wu 72c8c21104 [build-script] Add --enable-caching support with clang-cache and Swift compilation caching
Add a new --enable-caching option that enables compilation caching for both
C/C++ (via clang-cache as compiler launcher) and Swift code (via
-cache-compile-job flags when bootstrapping=hosttools).

New options:
- --enable-caching: main toggle, incompatible with --sccache/--distcc
- --caching-cas-path: CAS directory (default: $BUILD_ROOT/cas)
- --caching-depscan-socket: depscan daemon socket path
- --caching-plugin-path: CAS plugin library path
- --caching-plugin-option: CAS plugin options (repeatable)
- --caching-prefix-map: enable source/SDK/toolchain prefix mapping
- --caching-remote-service-path: remote caching service with auto
  plugin inference from Xcode and implied prefix mapping

The build script starts a clang-cache depscan daemon with reliable cleanup
via atexit and SIGTERM handlers. Per-product build directories get .cas-config
and compilation-prefix-map.json files written automatically.

Caching flags are applied to all Swift host compilation targets: compiler
sources, pure-swift host libraries (ASTGen, macros), swift-syntax, and
the new runtime build when --build-runtime-with-host-compiler is used.

When not using --caching-remote-service-path, enables CAS backend
(-Xfrontend -cas-backend -Xllvm -cas-friendly-debug-info) unless
SWIFT_CACHE_DISABLE_MCCAS is set.

A ninja wrapper is generated at build/<subdir>/build-utils/ninja for
cached incremental builds outside the build-script.

rdar://155876033

Assisted-By: Claude
2026-04-29 14:42:17 -07:00
Doug Gregor f161a60e12 [Embedded] Build standard library & friends for ARMv8-M and ARMv8.1-M
Implements rdar://152598746.
2026-04-25 08:33:14 -07:00
Keith Smiley 76b8f13d52 cmake: fix empty custom command comments
Previously it would print this:

```
[3/3] Linking CXX executable bin/swift-frontend; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;
```

Now we only pass the comment through if it is set, so those go away
2026-04-24 19:17:17 -07:00
3405691582 9ca2816557 Use unversioned triples on OpenBSD.
Prior to this change, we used versioned triples on this platform.
However, swift-build and the planned future migrations effectively
constrain the platform to abandon this module naming scheme.

Ideally, we would look for a swiftmodule named after the versioned
triple, then fall back to the unversioned triple, or vice versa.
However, this is not straightforward to do, and/or would induce a larger
change. It transpired that it was more straightforward to just convert,
despite reservations and modules generated on earlier versions requiring
recompilation in the future. Because the install base for the platform
is likely few, tackle the work to implement the fallback later and just
get this quickly done first, especially so we can hopefully make the cut
to have this incorporated in 6.3.
2026-03-31 16:58:41 -04:00
Steffeeen dd512134d0 [CMake] Don't remove sourcekit-inproc from _SWIFT_DEFAULT_COMPONENTS
SourceKit always needs sourcekit-inproc. With this change we always get
a `lib/sourcekitdInProc.framework` directory in the swift build
directory. This can then be used in SourceKit-LSP to run SourceKitD
in-process on macOS for debugging.
2026-03-27 17:45:37 +01:00
Rintaro Ishizaki 07be0d26cd [CMake] Avoid 'swiftc -parse' with stdin to check compiler capability
When the host compiler is built with assertions, 'swiftc -parse -'
hits an assertion failure, which fails the capability checks.

```
Assertion failed: [&]() -> bool { if (FrontendOptions::shouldActionOnlyParse(Action)) { return llvm::all_of( opts.InputsAndOutputs.getAllInputs(), [](const InputFile &IF) { const auto kind = IF.getType(); return kind == file_types::TY_Swift || kind == file_types::TY_SwiftModuleInterfaceFile; }); } return true; }() && "Only supports parsing .swift files", file C:\Users\swift-ci\jenkins\workspace\swift-main-windows-toolchain\swift\lib\FrontendTool\FrontendTool.cpp, line 1737
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.      Program arguments: S:\\b\\toolchains\\DEVELOPMENT-SNAPSHOT-2025-12-01-a\\LocalApp\\Programs\\Swift\\Toolchains\\0.0.0+Asserts\\usr\\bin\\swift-frontend.exe -frontend -parse -primary-file - -target x86_64-unknown-windows-msvc -disable-objc-interop -no-color-diagnostics -Xcc -fno-color-diagnostics -disable-implicit-string-processing-module-import -empty-abi-descriptor -no-auto-bridging-header-chaining -module-name main -in-process-plugin-server-path S:\\b\\toolchains\\DEVELOPMENT-SNAPSHOT-2025-12-01-a\\LocalApp\\Programs\\Swift\\Toolchains\\0.0.0+Asserts\\usr\\bin\\SwiftInProcPluginServer.dll -plugin-path S:\\b\\toolchains\\DEVELOPMENT-SNAPSHOT-2025-12-01-a\\LocalApp\\Programs\\Swift\\Toolchains\\0.0.0+Asserts\\usr\\bin -plugin-path S:\\b\\toolchains\\DEVELOPMENT-SNAPSHOT-2025-12-01-a\\LocalApp\\Programs\\Swift\\Toolchains\\0.0.0+Asserts\\usr\\local\\bin -autolink-library oldnames -autolink-library msvcrt -Xcc -D_MT -Xcc -D_DLL
1.      Swift version 6.3-dev (LLVM 35f48306184cd25, Swift a69dbb3366)
2.      Compiling with effective version 5.10
Exception Code: 0x80000003
 #0 0x00007ff7a6efdda5 (S:\b\toolchains\DEVELOPMENT-SNAPSHOT-2025-12-01-a\LocalApp\Programs\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0x722dda5)
 #1 0x00007ff94d8b1989 (C:\WINDOWS\System32\ucrtbase.dll+0xc1989)
 #2 0x00007ff94d894ab1 (C:\WINDOWS\System32\ucrtbase.dll+0xa4ab1)
 #3 0x00007ff94d8b2986 (C:\WINDOWS\System32\ucrtbase.dll+0xc2986)
 #4 0x00007ff94d8b2b61 (C:\WINDOWS\System32\ucrtbase.dll+0xc2b61)
 #5 0x00007ff7a02d944d (S:\b\toolchains\DEVELOPMENT-SNAPSHOT-2025-12-01-a\LocalApp\Programs\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0x60944d)
 #6 0x00007ff7a02db914 (S:\b\toolchains\DEVELOPMENT-SNAPSHOT-2025-12-01-a\LocalApp\Programs\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0x60b914)
 #7 0x00007ff7a011b19e (S:\b\toolchains\DEVELOPMENT-SNAPSHOT-2025-12-01-a\LocalApp\Programs\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0x44b19e)
 #8 0x00007ff7a011ad57 (S:\b\toolchains\DEVELOPMENT-SNAPSHOT-2025-12-01-a\LocalApp\Programs\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0x44ad57)
 #9 0x00007ff7a6f667d0 (S:\b\toolchains\DEVELOPMENT-SNAPSHOT-2025-12-01-a\LocalApp\Programs\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0x72967d0)
#10 0x00007ff94e6be8d7 (C:\WINDOWS\System32\KERNEL32.DLL+0x2e8d7)
#11 0x00007ff94fe2c40c (C:\WINDOWS\SYSTEM32\ntdll.dll+0x8c40c)
```
2026-03-03 12:47:59 -08:00
Saleem Abdulrasool 5b411c8f88 Merge pull request #87529 from compnerd/flags
build: clean up Windows default flags
2026-02-26 15:32:44 -08:00
Saleem Abdulrasool 92ee906043 build: clean up Windows default flags
Ensure that we build with `/DUNICODE /D_UNICODE` on Windows to enable
the unicode paths.

Remove a workaround for `_DEBUG` in light of llvm/llvm-project#183120.

Take the opportunity to reflow some text and add some explanatory
comments.

Fixes: #87470
2026-02-25 22:57:38 -08:00
Saleem Abdulrasool 0cd628a67f build: quote SHELL escaped parmeters better in CMake
Adjust the quoting that is applied to SHELL escaped compile options.
2026-02-24 13:41:16 -08:00
Saleem Abdulrasool 5431add4fb cmake: correct quoting for options
Extracted from the work by @hjyamauchi. These are required to adjust the
invocation for the GNU driver.
2026-02-20 11:26:56 -08:00
Saleem Abdulrasool 2cd3aaff04 Merge pull request #86578 from Steelskin/fabrice/llvm-dll-adjust-shared-cmake-config
Adjust swift LLVM config to support `LLVM_LINK_LLVM_DYLIB`
2026-02-12 09:01:03 -08:00
Daniel Rodríguez Troitiño 55a94ec57a [CMake] MSVC does not support -fno-lto, so skip it (#86660)
Sadly MSVC doesn't seem to have a equivalent to `-fno-lto` and it does
not like `-fno-lto`, printing a warning. Pointed out after landing in
the comments of #86187.

In order to avoid the warning, skip the `-fno-lto` flag for MSVC
compilers. This means that MSVC will still suffer the problem described
in #86187 (enabling LTO in a LLVM unified build will force enabling LTO
on Swift/Swift stdlib, even if disabled explicitly with\
`SWIFT_STDLIB_ENABLE_LTO`). This was the result even after #86187, since
MSVC was ignoring the `-fno-lto` anyway.

It cannot be done with a generator expression because the resulting
string seems to be used in some context that does not support generator
expressions.
2026-01-20 17:22:00 -08:00
Fabrice de Gans 8d1ae65a4b Adjust swift LLVM config to support LLVM_LINK_LLVM_DYLIB
When building LLVM as a dynamic library, we only need to depend on the
LLVM target to build properly.

Bug: #85241
2026-01-15 17:54:22 +01:00
Daniel Rodríguez Troitiño b37511ef42 [CMake] Explicitly disable LTO if no LTO option is provided (take 2) (#86187)
This is second version of #85621 which was reverted in #85794 because
the result of `_compute_lto_flag` was used as a boolean in some
contexts.

The differences from the original is that `_compute_lto_flag` is split
into a second function `_is_lto_enabled` which provides an actual
boolean for when LTO is enabled, and the half dozen usages of
`_compute_lto_flag` have been audited for using `_compute_lto_flag`
without considering the return value a boolean, or using the new
`_is_lto_enabled` as a proper boolean. A small clean up of commented out
code is performed (probably just a forgetten clean up from #66077).

The changes have been verified by compiling with
`SWIFT_STDLIB_ENABLE_LTO=thin` and
`SWIFT_STDLIB_BUILD_TYPE=RelWithDebInfo`, and checking the resulting
flags for building the stdlib include both `-flto=thin` and
`-gline-tables-only`, while the Swift tools include `-fno-lto` instead.

The following is the original commit message, which explains why this
change is interesting:

---

When compiling Swift as an LLVM external project (not the non-unified
workflow from the build-script), if one tries to enable LTO for LLVM
projects it will end up affecting Swift and the Swift standard library,
even if the options `SWIFT_TOOLS_ENABLE_LTO` and
`SWIFT_STDLIB_ENABLE_LTO` are disabled or using their default values,
because [HandleLLVMOptions] modifies the `CMAKE_C/CXX_FLAGS` globally.

By setting `-fno-lto` explicitly when those options are disabled or
using their default values, the options from `CMAKE_C/CXX_FLAGS` are
overriden, and the `SWIFT_*_ENABLE_LTO` controls the usage or not of LTO
optimizations and the presence of bitcode in the object files.

[HandleLLVMOptions]:
https://github.com/swiftlang/llvm-project/blob/b58b2a34d5094928c4ee1b94a7d5412b14540c01/llvm/cmake/modules/HandleLLVMOptions.cmake#L1278-L1310
2026-01-12 10:08:42 -08:00
Doug Gregor c72d939e46 Revert "[CMake] Explicitly disable LTO if no LTO option is provided (#85621)"
This reverts commit 51d2f2b61d.
2025-12-02 08:29:43 -08:00
Daniel Rodríguez Troitiño 51d2f2b61d [CMake] Explicitly disable LTO if no LTO option is provided (#85621)
When compiling Swift as an LLVM external project (not the non-unified
workflow from the build-script), if one tries to enable LTO for LLVM
projects it will end up affecting Swift and the Swift standard library,
even if the options `SWIFT_TOOLS_ENABLE_LTO` and
`SWIFT_STDLIB_ENABLE_LTO` are disabled or using their default values,
because [HandleLLVMOptions] modifies the `CMAKE_C/CXX_FLAGS` globally.

By setting `-fno-lto` explicitly when those options are disabled or
using their default values, the options from `CMAKE_C/CXX_FLAGS` are
overriden, and the `SWIFT_*_ENABLE_LTO` controls the usage or not of LTO
optimizations and the presence of bitcode in the object files.

[HandleLLVMOptions]:
https://github.com/swiftlang/llvm-project/blob/b58b2a34d5094928c4ee1b94a7d5412b14540c01/llvm/cmake/modules/HandleLLVMOptions.cmake#L1278-L1310
2025-12-01 09:40:59 -08:00
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
Rintaro Ishizaki 65505d197b [ASTGen/CMake] Link swiftOnoneSupport in "Debug" build
When building the swift compler with "Debug" configuration, modules
written in Swift must be linked to swiftOnoneSupport. Explicitly link it
as some linker doesn't auto-link it.

rdar://162631685
2025-10-15 09:58:47 -07: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 f009cfa785 FreeBSD: Remove extra '}' in triple
Accidentally included an extra closing brace in the FreeBSD triple.
2025-08-08 14:09:10 -07:00
Evan Wilde 8f3341e7be FreeBSD: Set runtime module triple correctly
LLVM FreeBSD triples include the version number, which gets encoded into
the swiftmodule. The filename should not include the version number
though. This patch drops the version number from the filename, but not
from the target triple.

This fixes several tests which uses the computed target triple as the
flag to pass to `-target`. Since it was missing the version number, the
compiler assumed it defaulted to zero and would report
"compiling for freebsd 0, but module 'Dispatch' has a minimum deployment
target of freebsd 14.3"

Fixes: rdar://156163594
2025-08-07 10:29:26 -07:00
Eric Miotto 0869919eca Test: allow different deployment target versions for tests on Darwin
Currently we are using the same versions we use to build compiler and
standard library. This is an unnecessary coupling especially when
testing the generation of backdeployed executables for macOS -- here
we have interest in being able to run the tests on previous OSes, not
the compiler itself.

To support this, add new `--darwin-test-deployment-version-<platform>`
flags to build-script, which by default take the same value as the
matching `--darwin-deployment-version-<platform>` ones.

Addresses rdar://156724078
2025-07-31 08:19:13 -07:00
Yuta Saito 3a0d5fd0a1 [wasm] Rename wasm32-unknown-wasi to wasm32-unknown-wasip1 2025-07-18 02:03:16 +00:00
finagolfin b2f52524c5 [android] Disable a couple Reflection tests and fix an install path (#82620)
The tests broke on the community Android CI since #82325, and I just
noticed the install issue when cross-compiling Testing with a
freshly-built compiler, which I'd never done before. Also, fix the NDK
path shown in the CMake output.
2025-07-02 09:41:59 +05:30
(null) 9d915c68da libc++ is the default standard library on FreeBSD 2025-06-17 16:13:38 -04:00
Alastair Houghton df35df17ce [Build] Fix the minimal-stdlib build by setting a deployment version.
We need to set a deployment version, not just blank, because otherwise
we don't know the correct deployment target to use for the standard
library.
2025-06-05 13:09:43 +01:00
Alastair Houghton d5ed335339 Merge pull request #81440 from al45tair/currentos-availability
[Concurrency][Stdlib] Add SwiftStdlibCurrentOS availability, use it.
2025-06-03 15:01:22 +01:00
Konrad `ktoso` Malawski 31b6ae2fcf Merge pull request #80984 from ktoso/task-names-update
[Concurrency][SE-review update] Task names update
2025-05-28 06:23:49 +09:00
Ian Anderson 0027779029 Merge pull request #81726 from ian-twilightcoder/remove_darwin_overlay
[CMake][Darwin] Remove support for building the SDK overlays on Apple platforms
2025-05-26 12:19:28 -07:00
Ian Anderson 15345ef2d5 [CMake][Darwin] Remove support for building the SDK overlays on Apple platforms
The SDK overlays have been provided in the Apple SDKs for many years, and the interface and implementation has diverged in more recent years such that trying to build the Swift version no longer works. Remove all of the dead code.

rdar://151889154
2025-05-23 23:38:08 -07:00
Evan Wilde fd2ba8b95d Fix the ARM architecture on FreeBSD
The 64-bit ARM architecture spelling on FreeBSD is aarch64, not arm64.
This results in a build failure about a missing
`freebsd/arm64/swiftrt.o` while building the runtimes.
2025-05-20 21:38:41 -07:00
Alastair Houghton 28f96e64ab [Concurrency][Stdlib] Add SwiftStdlibCurrentOS availability, use it.
If you use SwiftStdlibCurrentOS availability, you will be able to
use new types and functions from within the implementation. This
works by, when appropriate, building with the CurrentOS availability
set to the current deployment target.

rdar://150944675
2025-05-12 12:07:24 +01:00
3405691582 79e0b6a7e0 Unconditionally add -z,origin on OpenBSD. (#80897)
This is a little less than ideal, since as I understand it, it only
makes sense to add -z,origin when $ORIGIN expansion is required, but
doing this surgically per target is rather cumbersome. I don't believe
there are any significant drawbacks to doing it unconditionally like
this, however.
2025-04-30 19:46:29 +05:30
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
Rintaro Ishizaki 90340a069a Merge pull request #79918 from rintaro/cmake-no-emit-module-separately
[CMake] '-no-emit-module-separately-wmo' for swift modules
2025-03-17 11:38:18 -07:00
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 860ea2c967 [CMake] Fix package CMO capability chekcing logic
Package CMO requires '-enable-library-evolution' in 6.1+ compilers.
Otherwise:
  <unknown>:0: error: Library evolution must be enabled for Package CMO

rdar://146673779
2025-03-10 11:09:47 -07:00
Yuta Saito 9595425717 Merge pull request #79344 from kateinoigakukun/pr-c16855f8d94328f5545bcc3105985cd5286ce69f
[build] Configure library naming conventions for WebAssembly platforms
2025-02-14 13:32:43 +09:00
Yuta Saito bf008af355 Merge pull request #79343 from kateinoigakukun/pr-fba68e2574f281558869dcf2006c48d8cf894e99
[build] Add initial support for Emscripten SDK
2025-02-14 13:32:20 +09:00
Yuta Saito 720327727f [build] Configure library naming conventions for WebAssembly platforms
Use the same conventions used in wasi-libc and Emscripten
2025-02-13 00:54:13 +00: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
Yuta Saito 6e3d401b41 [build] Stop assuming llvm is always the top-level in unified build
Even with unified build, llvm is not always the top-level project but it
can be a part of a larger build. (e.g. [^1]) In that case,
`CMAKE_BINARY_DIR` is not the binary directory of llvm but the binary
directory of the top-level project. This patch fixes the issue by using
`LLVM_BINARY_DIR` instead.

[^1]: https://github.com/ChromeDevTools/devtools-frontend/blob/9b4b9070790196d78489756c515c528a0fe7ac00/extensions/cxx_debugging/CMakeLists.txt#L105
2025-02-13 00:27:02 +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
Michael Chiu c6d9efa553 Remove FreeBSD version from SDK triple 2025-02-01 12:05:39 -08:00
Cyndy Ishida 3232df4d67 Reapply '[BuildSystem] Stop building for i386-watch-simulator (#77692)' (#79018)
* Reapply '[BuildSystem] Stop building for i386-watch-simulator (#77692)'

    * [BuildSystem] Stop building for i386-watch-simulator

    In Xcode16 it is not supported.

This initially broke client projects who were still building the legacy
architecture but now that's resolved.
2025-01-31 15:04:28 -08: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 ab8e561583 Merge pull request #78516 from al45tair/eng/PR-124913332
[Backtracing] Implement API per SE-0419
2025-01-28 10:48:33 +00:00