Commit Graph

122 Commits

Author SHA1 Message Date
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]: 9b4b907079/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
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
Saleem Abdulrasool
78ec9a7af6 Merge pull request #78774 from compnerd/unknown-silence
build: silence C4067 on Windows (NFCI)
2025-01-22 08:26:16 -08:00
Saleem Abdulrasool
6b58947382 build: silence C4067 on Windows (NFCI)
This silences a warning that the MSVC compiler emits about unknown
pragmas. This helps clear up the build a small amount so real issues do
not get hidden.
2025-01-21 09:37:11 -08:00
Saleem Abdulrasool
c9e4dff925 build: only add compiler flag if it is supported
This ensures that we only add the flag if it is supported by the
compiler rather than doing it unconditionally.
2025-01-21 09:35:24 -08: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
Daniel Rodríguez Troitiño
4921eaf92f [CMake] Avoid stomping cache variables when cross-compiling (#76054)
If one is building unified and also cross-compiling (for example
building from Linux x86_64 to Linux aarch64), these variables which are
normally set in the cache pointing to a native toolchain are overwritten
unconditionally pointing to the `CMAKE_BINARY_DIR`, which can be
incompatible with the build machine.

The value of `SWIFT_NATIVE_CLANG_TOOLS_PATH` is eventually passed to the Swift
compiler as `-tools-directory`, which the new `swift-driver` actually
seems to use to find `swiftc`. When the `swift-driver` tries to use the
incompatible `swiftc`, it returns with a very unhelpful "error: failed to
retrieve frontend target info".

Avoiding overwriting the variables when cross-compiling lets the build
system use the variables provided in the cache, which point to correct
binaries for the build machine.
2024-08-23 06:59:41 -07:00
Ben Barham
0d764d059f [Build] Disable -Wdocumentation
LLVM doesn't have this warning enabled, so we end up with a whole tonne
of warnings from the LLVM headers.
2024-04-01 14:27:48 -07:00
Saleem Abdulrasool
49a5098db4 build: update for cmark build revamp and split the build
Extricate cmark from the unified build system. This is preparatory work
to support building CMark GFM with dynamic linkage for sharing it across
swift-markdown and the compiler. It also simplifies the build logic for
the unified build.
2024-01-17 08:54:36 -08:00
Daniel Rodríguez Troitiño
449ef8af75 [CMake] Replicate what ClangConfig does for unified builds (#70890)
ClangConfig sets `CLANG_INCLUDE_DIRS` and Swift build system uses that
variable in a couple of places. Without this, several of the include
directories for Clang might not be added to different parts of the
compiler, like when using SwiftSourceSupport files. Before these
changes, headers like `clang/CAS/CASOptions.h` were not being found.
2024-01-13 07:57:43 -08:00
Rintaro Ishizaki
362b555288 [CMake] Disable warnings for anonymous nested types
Some commit accidentally changed `-Wno-nested-anon-types` to
`-Wnested-anon-types`.
2024-01-09 11:44:13 -08:00
Saleem Abdulrasool
43c5cf910c Merge pull request #70673 from compnerd/user
build: do not modify user variables
2024-01-03 09:44:28 -08:00
Saleem Abdulrasool
f75619fc4a build: do not touch the user specified flags
`CMAKE_CXX_FLAGS` are user controlled and should not be touched by the
build system [1]. Use global `add_compile_options` and
`add_compile_definitions` to control the flags for the targets.

[1] https://cmake.org/cmake/help/book/mastering-cmake/
2024-01-02 14:22:36 -08:00
Saleem Abdulrasool
d21c339a5d build: sink flag handling into global handling
This shuffles the warning from the unified build only to the global
build configuration.
2024-01-02 14:05:02 -08:00
Saleem Abdulrasool
8b47616d6d build: simplify the unified build configuration
Conditionalise the inclusion of directory paths. If the include
directory is empty, CMake will raise an error. This allows us to disable
larger portions of the Swift build to speed up some of the build tool
configuration phase and prepares for consuming CMark GFM as a CMake
project.
2024-01-02 12:58:50 -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
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
Victoria Mitchell
455cdbc5a7 use swift-cmark/gfm instead of /main 2022-03-16 14:56:21 -06:00
Michael Gottesman
4a189d8025 [cmake] Work around a bug in the swift-driver by passing host side libraries from LLVMSupport to linker jobs via a -Xlinker flag.
Clang and Swift both support this so we can do this until the actual fix lands
in a host toolchain to unblock ErikE.

The specific problem is the swift driver should just push tbd files through to
the linker, but it treats it as an input file. I am going to be putting a fix
into 5.5. This patch in the mean time filters out the tbd files in cmake. This
is a temporary fix.

I also had to add direct dependencies from swift-refactor and
libSwiftSyntaxParser on LLVMSupport to ensure that the right linker flags get to
them.
2021-06-01 18:43:12 -07:00
swift_jenkins
9f5e4e98f7 Merge remote-tracking branch 'origin/main' into next 2021-01-06 17:12:10 -08:00
Butta
934823a99c [build] Replace SWIFT_CROSS_COMPILING with SWIFT_PREBUILT_CLANG 2020-12-13 18:22:34 +05:30
Nathan Hawes
5b6c137586 [cmake] Fix zlib cmake issue: Target <X> links to target "ZLIB::ZLIB" but the target was not found...
...after the changes in https://reviews.llvm.org/D79219.

Resolves rdar://problem/66057385
2020-07-24 17:28:03 -07:00
Mishal Shah
587ce889e1 [Apple Silicon] Don't set native llvm tools path when cross compiling swift 2020-07-02 18:14:39 -07:00
Saleem Abdulrasool
5f428f594a build: use the new CMark export targets
CMark upstream now provides an exports target entry that we can use.
2020-01-03 14:40:58 -08:00
Vlad Gorlov
62dd6bda10 Android build on macOS Cross-Compile host: Fixes wrong Ninja rules generation. (#25576)
* Fixes wrong Ninja rules generation for Android build on macOS Cross-Compile host.

* PR review fixes.
2019-06-21 17:04:51 -07:00
Saleem Abdulrasool
a6c0e9438b build: allow the user to specify the llvm tools
This is needed for cross-compiling the toolchain to Windows ARM64 on
Windows x64 using Visual Studio which does not permit the NATIVE
sub-build to work properly.
2019-06-19 16:47:18 -07:00
Saleem Abdulrasool
816dfe23ac build: don't always load clang/cmark
clang/cmark are only needed for the tools, not for the runtime/SDK
overlay.  Do not attempt to configure clang and CMark in the case we do
not build the tools.  This is needed to enable the standalone standard
library only builds.
2019-05-01 22:18:29 -07:00
Saleem Abdulrasool
22859376c6 build: do not search for native LLVM when not building tools
The standard library does not depend on the LLVM libraries at runtime.  Do not
perform the search for the LLVM configuration when the tools are not being
built.  This is needed to permit cross-compiling the standard library standalone
for android on a Linux host without building LLVM and Clang for android.
2019-04-09 12:38:57 -07:00
Saleem Abdulrasool
01f6a2ad6d build: correct the variable name for cross-compiling
A typo snuck into the cross-compiling path and due to the machine that it was
tested on hvaing `/bin/llvm-tblgen`, the build succeeded.  Correct the typo to
ensure that we use the correct tblgen.
2019-03-18 08:55:31 -07:00
Saleem Abdulrasool
ac5687b81e build: remove some unused variables 2019-02-27 11:14:10 -08:00
Saleem Abdulrasool
350cf67788 utils: attempt to replace custom variables
CMake defaults to using a special <package>_DIR for finding packages.
Prefer this to import the CMake package for LLVM/Clang/Swift rather than
custom paths.
2019-02-22 18:47:26 -08:00
Slava Pestov
1d8928425a Revert "utils: attempt to replace custom variables" 2019-02-22 19:21:13 -05:00
Saleem Abdulrasool
817597c7f9 utils: attempt to replace custom variables
CMake defaults to using a special <package>_DIR for finding packages.
Prefer this to import the CMake package for LLVM/Clang/Swift rather than
custom paths.
2019-02-14 20:19:08 -08:00
Saleem Abdulrasool
adbb7d7cbd build: simplify condition and IWYU CMake edition
Include a missing CMake module in a couple of locations that we were
using the function.  Simplify a condition to use `MATCHES` rather than
two `STREQUAL`.
2019-02-14 17:35:18 -08:00
Saleem Abdulrasool
509060c78a build: convert paths to CMake paths before use
This converts the path separators to the CMake way.  This is primarily
important for Windows where the path separator is \ rather than /.  This
conversion allows the specification of the path in the proper windows
path style.
2018-12-30 12:27:16 -08:00
Saleem Abdulrasool
16a4af0e5b build: assume a parallel tree layout for unified builds
Attempt to repair the build for the unified swift build.  This allows us
to build a single unified toolchain with swift support.  In this layout
assume that cmark and clang are peers of LLVM rather than located in
`tools`.  Doing so allows a uniform layout of the tree and a simpler
build approach.
2018-11-29 12:26:02 -08:00
Michael Gottesman
3f17bb6ddf Carefully split the build's invocation of add_swift_library into host/target variants.
The key thing here is that all of the underlying code is exactly the same. I
purposely did not debride anything. This is to ensure that I am not touching too
much and increasing the probability of weird errors from occurring. Thus the
exact same code should be executed... just the routing changed.
2018-10-27 12:58:51 -07:00
Saleem Abdulrasool
d9dde28bf1 build: improve the builds with Visual Studio
Visual Studio's compiler does not accept `-Werror=switch`.  Use the equivalent
`-we4062` option instead.  Avoid using the `--` separate that clang uses to
identify that the options that follow are files and not options on the Visual
Studio compiler to reduce the unnecessary spew when building on Windows.
2018-09-12 12:06:48 -07:00
Shoaib Meenai
4a0274acff [CMake] Use NO_CMAKE_FIND_ROOT_PATH for LLVM and clang
When cross-compiling or specifying a custom sysroot and desiring a
hermetic build, many CMake toolchain files will have a custom
CMAKE_FIND_ROOT_PATH and set the CMAKE_FIND_ROOT_PATH_MODE_* variables
to ONLY, meaning packages will only be searched for in the rerooted
directories. We don't want this rerooting to happen when searching for
the LLVM and clang packages though, since we're specifying our search
paths explicitly and excluding search paths from the system, and we
don't want those explicit search paths to be rerooted.

It's standard to set CMAKE_FIND_ROOT_PATH_MODE_PROGRAM to NEVER instead
of ONLY, since you usually want programs to be found for the build
system and not the host system, so the change for the llvm-config search
is not technically required. It doesn't hurt for consistency though, and
I can envision some scenarios in which it might come in handy.
2018-07-12 12:04:04 -07:00
Saleem Abdulrasool
9e7f0e1475 build: filter -z,nodelete on Windows
LLVM recently added a new ELF-only linker flag that gets exported.
Filter this from  the linker flags too.
2018-05-24 09:25:10 -07:00
swift-ci
577b2722f7 Merge pull request #13140 from troughton/windows-cross-compile-fixes 2018-04-18 10:56:06 -07:00
Jordan Rose
20ae19ef22 [CMake] Improve Xcode project generation with folders (#15738)
- Re-enable the use of folders with the USE_FOLDER setting. This got
  lost a while ago when we stopped including LLVM's top-level
  CMakeLists.txt.

- Put a bunch of new targets into folders.

Should not affect the built product and definitely shouldn't affect
anyone not building with Xcode (or MSVC, I guess).
2018-04-04 18:22:59 -07:00
Thomas Roughton
7c2230bc56 Fix cross-compilation for the Windows stdlib
Disable SwiftPrivate, remove -Wl,-z,defs, and use the VFS overlay for compiling the runtime.
2018-02-01 22:08:18 +13:00
Bob Wilson
390058972a [master-next] Use PRIVATE in target_link_libraries for executables
This is needed to work with LLVM r319840.
2017-12-06 21:55:22 -08:00
Saleem Abdulrasool
d48686ff0d build: effectively revert 986beb7522
This change broke the Windows builds for all the variants.  `-z defs` cannot be
used on all targets, particularly in environments where the stdlib is being
compiled for a foreign host.  This needs to be handled more carefully as I
mentioned on the PR itself.  In the mean time, revert it to get Windows building
again.
2017-12-01 13:34:30 -08:00
David Zarzycki
986beb7522 [CMake] Localize a build hack
The '-Wl,-z,defs' flag is useful, so let's disable it only where needed.
2017-11-13 07:40:54 -05:00
Mishal Shah
df070b858f Update swift master to build with Xcode 9 beta 6, macOS 10.13, iOS 11, tvOS 11, and watchOS 4 SDKs. 2017-08-22 11:52:50 -07:00
swift-ci
d189132667 Merge remote-tracking branch 'origin/master' into master-next 2017-08-01 09:28:54 -07:00
David Zarzycki
dc1d0943b2 [CMake] Infer -Werror=switch via asserts being enabled (#11098)
LLVM-style projects like Swift make heavy use of switch statements and
therefore -Werror=switch is very useful during feature development. That
being said, if asserts are disabled, then you're probably not actively
hacking on the project and -Werror (or warnings in general) aren't
helpful.
2017-08-01 09:23:25 -07:00