Commit Graph

88 Commits

Author SHA1 Message Date
Michael Gottesman
810f5b5088 [cmake] Make SwiftCompilerSources support debug info in RelWithDebInfoMode and use -Os instead of -O with MinSizeRel. 2025-09-25 08:16:20 -05: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
Hamish Knight
8f4fbe3d9a [cmake] Remove remaining XCODE checks
I missed these when ripping out support for CMake Xcode project
generation.
2025-06-09 22:16:12 +01:00
Egor Zhdan
80cd764aff Merge pull request #76575 from swiftlang/egorzhdan/scs-bump-version
[SwiftCompilerSources][build] Bump the minimum supported compiler version to 5.9
2025-05-13 18:03:59 +01:00
Fabrice de Gans
4fd65dda6d Be more explicit in MSVC and Clang version mapping 2025-03-07 10:19:04 -08:00
Fabrice de Gans
a8346a8644 Update compiler/STL version mismatch condition
MSVC 14.43 added a requirement for Clang 18, which is not currently
supported by any Swift toolchain version. This updates the condition for
setting the `_ALLOW_COMPILER_AND_STL_VERSION_MISMATCH` compiler define
for MSVC 14.43 and higher.
2025-03-06 16:45:33 -08:00
Rintaro Ishizaki
efe38a0bcf [Windows] Enable "INLINE" bridging mode
* Workaround for https://github.com/swiftlang/llvm-project/issues/7172
* `-D_CRT_USE_BUILTIN_OFFSETOF` to make `offsetof()` a constant
* Pass correct 'swift/shims' search path
2024-09-27 13:50:18 -07:00
Egor Zhdan
c6ce6ee162 [SwiftCompilerSources][build] Bump the minimum supported compiler version to 5.9
Building SwiftCompilerSources with a Swift 5.8 compiler is not tested anymore, and it might showcase bugs in the old compiler version that are already fixed.

This bumps the minimum allowed version to Swift 5.9, which was shipped in Xcode 15.
2024-09-19 18:17:56 +01:00
Jeremy Day
00acea4071 [windows] Allow compiler and STL version mismatch
VS 17.10 introduced a requirement on Clang 17, but the pinned Swift
toolchain used to bootstrap the compilers (a 5.10 snapshot) uses Clang 16. We
can relax this version requirement with ALLOW_COMPILER_AND_STL_VERSION_MISMATCH
which needs to be set for all CMAKE_Swift_FLAGS when building the
compilers, as well as explicitly in SwiftCompilerSources as the
invocation of swiftc there is via custom_command
2024-06-24 08:09:08 -07:00
Kavon Farvardin
819780ec64 Fix C++ interop in SwiftCompilerSources
part of rdar://128013193
2024-05-15 15:57:36 -07:00
Daniel Rodríguez Troitiño
c6745e6d50 Fix Swift Compiler Modules support in Debug mode (#73506)
The new `swift-driver` seems to enqueue a `wrapmodule` job which uses
the given `module-name` to form the output file name when not doing
optmizations (seems to happen only for `-Onone` in my testing). Since the
CMake functions macros are using the module name also as the explicit output
name, this clashes and ends up in an unhelpful error message from the driver.

```
SwiftDriverExecution/MultiJobExecutor.swift:207: Fatal error: multiple
producers for output ... SwiftCompilerSources/Basic.o: Wrapping Swift
module Basic & Compiling Basic SourceLoc.swift
```

This was reported in https://forums.swift.org/t/debug-swift-build-fails/71380

The changes use a different output object name (by using `.object.o`
suffix) which does not clash with what the `swift-driver` does
automatically. The code around the output objects and the static
libraries have to change slightly to handle this case.

Additionally, the resulting library when in `Debug` is now declaring its
dependency on `swiftSwiftOnoneSupport`, to avoid linking errors when the
libraries are used in the final binaries.

Debug mode seems to enable PURE_BRIDGING_MODE, which seems to skip
transitively including some C headers that files like
`Utilities/Test.swift` depend on. To avoid errors building, add the
missing include in a new `#else` branch.

I think CI will not test the `Debug` mode, so the only thing that it can prove is
that these changes do not break the `Release` mode.
2024-05-08 15:35:29 -07:00
Erik Eckstein
338dd185e7 SwiftCompilerSources: workaround a crash in the LoadableByAddress pass when building on Windows 2024-04-29 10:52:25 +02:00
eeckstein
e9d6ba9154 cmake: enable SwiftCompilerSources on Windows 2024-04-29 10:52:24 +02:00
Adrian Prantl
ec19901ab1 Merge pull request #73081 from adrian-prantl/experimental-cxx
Prefix experimental interop flag with -Xfrontend
2024-04-18 01:37:51 +02:00
Adrian Prantl
40f8cfd5a8 Prefix experimental interop flag with -Xfrontend 2024-04-17 12:51:07 -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
Erik Eckstein
94a94c3332 CMake: add a missing dependency to fix the bootstrapping build
legacy layouts must be copied before the bootstrapping compiler is used to build the SwiftCompilerSources
Fixes a sporadic build failure due to missing legacy layout files
2024-04-12 10:47:47 +02: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
066b6d1d74 CMake: Specify modern Cxx interop flag when building SwiftCompilerSources.
When building with a Swift 5.9 toolchain, we can specify the
`-cxx-interoperability-mode` flag instead of the deprecated
`-enable-experimental-cxx-interop` flag.
2024-03-03 20:49:09 -08: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
Alastair Houghton
e48b05f12c [SwiftCompilerSources] Enable use of the -min-runtime-version option.
Turn on the use of `-min-runtime-version` when building the compiler.

rdar://121522431
2024-02-02 16:19:06 +00: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
Steven Wu
21e779f0c3 [CMake] Change include path in HeaderDependencies.cpp
Update the #include in generated HeaderDependencies.cpp so it doesn't
need a special include path that points into `include/swift`. In the
swift sub-directory, there is a `Strings.h` that can be mistaken as
<string.h> on a case-insensitive file system.

rdar://119997353
2023-12-21 10:12:14 -08:00
Ben Barham
0966c7b7a8 [CMake] Fix SWIFT_TARGET redefinition warning
`HeaderDependencies.cpp` is (as in the name) C++, which means it
receives `-DSWIFT_TARGET` from the top level `add_definitions`. No need
to add it again.
2023-12-08 17:10:01 -08:00
Rintaro Ishizaki
4673d63776 Merge pull request #70271 from rintaro/cmake-swiftsrc-colordiag 2023-12-06 17:45:32 -08:00
Ben Barham
cb29ec8837 [CMake] Ignore None and NoneType deprecations
`llvm::None` is deprecated, but still being used in Swift until we have
fewer 5.10 cherry-picks. Add the `SWIFT_TARGET` definition to ignore the
deprecation.
2023-12-06 10:47:02 -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
Daniel Rodríguez Troitiño
ea62bcc832 [cmake] Allow overriding SwiftCompilerSources arguments from CMake (#70134)
The calculated arguments for compiling the SwiftCompilerSources works in
the cases where the sysroot of the machine building the code is `/` or
can be provided as a single directory in `SWIFT_SDK_<HOST>_<ARCH>_PATH`.
For some cases in which a sysroot is split into multiple directories or
in some cross-compiling scenarios where the SDK layout is beyond our
control, we can provide more flexibility in the build system.

The changes in this commit moves the calculations around the SDK and
libc++ outside the `add_swift_compiler_modules_library`, since they do
not depend on the inputs. Some calculations relative to `-resource-dir`
depend on the Swift compiler path, which cannot be moved outside the
function.

The calculations outside the function are stored in a cached variable,
which is later used in the function. If the need arise, anyone can
provide a custom value for that variable in their CMake invocation or
cache files adapted for their specific case and override the
automatically calculated default.

I also rewrote a couple of `set(list ${list} …)` into `list(APPEND
list …)`.

This should be NFC for the Swift CI, because no value of
`SWIFT_COMPILER_SOURCES_SDK_FLAGS` is provided, and the default should
be the same value as before.
2023-12-02 12:12:31 -08:00
Daniel Rodríguez Troitiño
d8127eb3e7 [CMake] In LLVM unified builds, depend on the generation of Clang headers (#70144)
If one is building a LLVM unified build, with Swift as an external
project, SwiftCompilerSources can compile before the `.td` files that
generate Clang headers are finished, which will make the compilation
fail to find some files (the `.inc` files derived from those `.td`).
Make the library that uses the header depend on `clang-tablegen-targets`
to ensure those are done before the library is tried to be used.

This is not a problem in the normal `build-script` builds because in
those cases, the LLVM/Clang headers are build way before Swift is
started to be build.
2023-12-02 12:12:09 -08:00
Rintaro Ishizaki
8fa9eb50a1 [SwiftCompilerSources] Build without target OS checking
Temporarily workaround an availability issue with CxxStdlib when
building with --bootstrapping=hosttools.
2023-11-28 15:18:01 -08:00
Rintaro Ishizaki
f327bf7616 [CMake] Correct dependencies
HeaderDependencies.cpp and the stdlib filelist didn't have dependencies.
That causes issues when the content is changed.
2023-11-16 13:54:14 -08:00
Rintaro Ishizaki
47f18d492e [ASTGen] Move regex literal parsing from SwiftCompilerSources to ASTGen
ASTGen always builds with the host Swift compiler, without requiring
bootstrapping, and is enabled in more places. Move the regex literal
parsing logic there so it is enabled in more host environments, and
makes use of CMake's Swift support. Enable all of the regex literal
tests when ASTGen is built, to ensure everything is working.

Remove the "AST" and "Parse" Swift modules from SwiftCompilerSources,
because they are no longer needed.
2023-11-16 10:59:23 -08:00
Erik Eckstein
2dbd6cc56b SwiftCompilerSources: rework bridging
Introduce two modes of bridging:
* inline mode: this is basically how it worked so far. Using full C++ interop which allows bridging functions to be inlined.
* pure mode: bridging functions are not inlined but compiled in a cpp file. This allows to reduce the C++ interop requirements to a minimum. No std/llvm/swift headers are imported.

This change requires a major refactoring of bridging sources. The implementation of bridging functions go to two separate files: SILBridgingImpl.h and OptimizerBridgingImpl.h.
Depending on the mode, those files are either included in the corresponding header files (inline mode), or included in the c++ file (pure mode).

The mode can be selected with the BRIDGING_MODE cmake variable. By default it is set to the inline mode (= existing behavior). The pure mode is only selected in certain configurations to work around C++ interop issues:
* In debug builds, to workaround a problem with LLDB's `po` command (rdar://115770255).
* On windows to workaround a build problem.
2023-10-09 09:52:52 +02: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
Erik Eckstein
fa2ac84d29 cmake: correctly set NDEBUG for imported headers in SwiftCompilerSources
So that it's consistent with C++ sources

rdar://110363377
2023-06-13 10:26:12 +02:00
Max Desiatov
1769c88fd6 [NFC] SwiftCompilerSources/CMakeLists.txt: fix comment typo (#66235)
`paltforms` -> `platforms`
2023-05-31 21:03:09 +01:00
swift-ci
19b4935fd6 Merge remote-tracking branch 'origin/main' into rebranch 2023-02-17 09:14:24 -08:00
Daniel Rodríguez Troitiño
89fec217fb Fix calls to add_custom_target_command (#63740)
`add_custom_target_command` has a note in its documentation that ask for
all the `COMMAND` arguments to immediately follow the first argument, or
the function will misbehave.

In the two cases below, the `COMMAND` arguments were after the `OUTPUT`
multivalue, and ended by mistake inside the `OUTPUT` parameter. This
kinda works because CMake will interpolate those back, but causes
problems for dependency resolution, marking many targets as dirty. When
one of those targets is dependent by the compiler, this can create
a huge cascade rebuild.

Fix the two cases I found where `add_custom_target_command` was used
incorrectly. This removes cascade rebuilds in my working directory, and
hope it applies to everybody.
2023-02-17 09:09:58 -08:00
Rintaro Ishizaki
d458c8b74a Merge remote-tracking branch 'origin/main' into rebranch
Conflicts:
	include/swift/Sema/ConstraintSystem.h
	include/swift/Syntax/AbsoluteRawSyntax.h
	include/swift/Syntax/Syntax.h
	include/swift/Syntax/SyntaxData.h
	lib/DependencyScan/ModuleDependencyCacheSerialization.cpp
	lib/Syntax/SyntaxFactory.cpp.gyb
	lib/Syntax/SyntaxNodes.cpp.gyb
	tools/SourceKit/lib/SwiftLang/SwiftEditor.cpp
	tools/swift-syntax-test/swift-syntax-test.cpp
2022-11-18 09:37:38 -08:00
Rintaro Ishizaki
2f50d03d77 Remove swiftCompilerModules_SwiftSyntax library
This was used by _InternalSwiftSyntaxParser which was removed some time
ago.
2022-11-17 10:11:26 -08:00
Erik Eckstein
4595185150 cmake: llvm now requires C++17 2022-11-04 20:44:18 +01:00
Alex Hoppen
d6bcfd915a [CMake] Fix issues when running build-tooling-libs
There were three different issues going on here, all of these were triggered by https://github.com/apple/swift/pull/61618 which stared including `AST/AnyFunctionRef.h` from the ASTBridging modulemap

- We did not find the clang include dirs because the unified build that build-tooling-libs is using does not import ClangConfig, setting `CLANG_INCLUDE_DIRS` in `swift_common_unified_build_config` fixed this problem.
- Some of the headers in `swift-ast-generated-headers` import generated headers from clang that might not have been created yet. Making `swift-ast-generated-headers` depend on the clang generated headers fixes this problem. This just lowers the dependency because `swiftAST` depends on `swift-ast-generated-headers`
- If a Swift compiler from Xcode is used, the SwiftShims don’t live next to the compiler but in the SDK. Adding the SDKs lib to the include paths fixes this problem
2022-10-22 12:35:17 +02:00
Egor Zhdan
1cb85e59f4 [SwiftCompilerSources] Add SwiftShims to the include paths
This allows Swift to import C++ headers from `include/swift` that include SwiftShims headers.

Previously that would result in a build error.
2022-09-15 11:36:29 +01:00
Robert Widmann
8cd8c4dd7d Add Missing Dependency Between Bootstrapping Headers and AST Header Generation 2022-09-14 10:02:23 -07:00
Egor Zhdan
e515db9c48 [cxx-interop][SwiftCompilerSources] Include Clang headers
This will allow using Swift headers that include Clang headers from SwiftCompilerSources.

For example, some headers in `swift/Basic` include headers from `clang/Basic`. Currently adding those Swift headers to the modulemap causes a build error.
2022-09-06 14:37:12 +01: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