Commit Graph

827 Commits

Author SHA1 Message Date
Erik Eckstein
83bfa1b0f3 cmake: export the libswift target and the LIBSWIFT_BUILD_MODE that the lldb build can see it. 2021-11-15 17:23:21 +01:00
Saleem Abdulrasool
127874edea Merge pull request #40124 from compnerd/root
build: allow building libswift with unified builds
2021-11-11 08:01:05 -08:00
Saleem Abdulrasool
f57c16700b build: allow building libswift with unified builds
When building with unified builds, `CMAKE_SOURCE_DIR` is not the Swift
repository.  Use the locally defined `SWIFT_SOURCE_DIR` variable to
reference the root of the Swift repository.  Because libswift uses
`project` in the CMakeLists, we cannot use `PROJECT_SOURCE_DIR` here.
2021-11-10 11:56:16 -08:00
Erik Eckstein
3c40ea5d77 cmake: allow more than one dependency for libswift targets 2021-11-10 13:03:49 +01:00
Erik Eckstein
581a41c377 cmake: Don’t add -lobjc in linux builds
Fixes a linux build error.
It doesn’t make sense to let add HAS_LIBSWIFT to add_swift_host_library(). This was added to work around a linker bug (d22b348adb). Instead do the workaround in libSwiftScan/CMakeLists.txt.
2021-11-09 09:16:08 +01:00
Erik Eckstein
09552abc44 libswift: improve the bootstrapping-with-hostlibs build mode
Don't build the swiftCore module files in the bootstrapping phases. Instead use the module files in the SDK.
This reduces the build time overhead from 3min -> 30seconds.
2021-11-05 18:32:25 +01:00
Erik Eckstein
78c4c3ff6d libswift: fixes for the linux bootstrapping build 2021-10-29 08:56:02 +02:00
Josh Learn
40da89c89d Undefine IB macros when building libswift 2021-10-27 14:51:38 -07:00
Erik Eckstein
4383610ed3 cmake: some fixes for the libswift bootstrapping build
* fix a typo which prevented linking the right bootstrapping libs
* build swiftDarwin for bootstrapping
* disable COW checks if built with bootstrapping-with-hostlibs
2021-10-19 13:10:59 +02:00
Saleem Abdulrasool
15a5d2c54b Revert "[android] Update to NDK 23" 2021-10-16 11:07:23 -07:00
Butta
7fa1b4b2ac [android] Update to NDK 23
The latest Long Term Support NDK finally removed binutils, including the bfd/gold
linkers and libgcc. This simplifies our Android support, including making lld the
default linker for Android. Disable three reflection tests that now fail, likely
related to issues with swift-reflection-dump and switching to lld.

Also, add the libatomic dependency for Android armv7, just as on linux.
2021-10-12 12:37:01 +05:30
Erik Eckstein
af71088d29 libswift: bootstrapping build
Adding build modes for libswift: off, hosttools, bootstrapping, bootstrapping-with-hostlibs
The two bootstrapping modes are new. For details see libswift/README.md
2021-09-28 18:51:42 +02:00
zoecarver
f063701f84 [cxx-interop][libswift] Use std::string instead of BridgedStringRef.
The first C-bridge to be removed! 🚀
2021-09-22 16:13:44 -07:00
zoecarver
25e5bc22e6 [cxx-interop][libswift][build] Enable C++ interop when building libSwift 2021-09-17 18:00:13 -07:00
Argyrios Kyrtzidis
8224df3bb2 Merge pull request #38913 from akyrtzi/link-with-demangle-along-with-support
[cmake/AddSwift] When `support` is passed for LLVM_LINK_COMPONENTS also implicitly include `demangle`
2021-08-27 14:19:58 -07:00
Kuba (Brecka) Mracek
c079c0897b Split SWIFT_DARWIN_PLATFORMS and SWIFT_APPLE_PLATFORMS in CMake. SWIFT_APPLE_PLATFORMS may contain 'FREESTANDING' when building the freestanding SDK and SWIFT_FREESTANDING_FLAVOR is set to 'apple'. (#38997) 2021-08-23 19:16:28 -07:00
Argyrios Kyrtzidis
dea7f9f1c3 [cmake/AddSwift] When support is passed for LLVM_LINK_COMPONENTS also implicitly include demangle
Using `support` llvm component ends up adding `-Xlinker /path/to/lib/libLLVMDemangle.a`
to `LINK_FLAGS` but `libLLVMDemangle.a` is not added as an input to the linking ninja statement.
As a workaround, in order to setup precise inputs for the ninja link statement, include `demangle` component
whenever `support` is mentioned.
2021-08-17 14:54:09 -07:00
Argyrios Kyrtzidis
35f0744b1c [CMake] Declare the precise dependencies of the gyb custom command invocations 2021-08-10 13:51:54 -07:00
Xi Ge
d22b348adb cmake: add a workaround to rdar://77839981 2021-07-14 10:02:27 -07:00
Alastair Houghton
4b1978cff5 Merge pull request #38023 from al45tair/sr-14813
[SR-14813] [Fuzzers] Fix the mangler and reflection fuzzer build.
2021-06-29 09:38:45 +01:00
Michael Gottesman
c5fe4f0c18 [cmake] Add the SDK directory after the toolchain directory when compiling host swift code.
This ensures that we pick up libraries from the toolchain before picking up
libraries from the SDK we are using. Normally it would not matter the order that
we add these -L files since the contents of the SDK and toolchain are
disjoint. Once we begin performing stage2 swift builds though, we no longer have
this property since we pass in the stage1's installed libraries as the SDK
directory and we have not split the two sets of libraries yet. The end result is
that if we have the -L in the previous order, we will pick up just built
compatibility libraries before we pick up the actual compatibility libraries
from the actual toolchain we are using to compile. This results in compilation
breakage.
2021-06-27 16:40:19 -07:00
Alastair Houghton
d74fef90a2 [SR-14813] Add Swift compile options for fuzzing.
We only had the C/C++/ObjC/ObjC++ option.  Add the Swift one too.
2021-06-23 12:52:06 +01:00
Alastair Houghton
a6ec498099 [SR-14813] [Fuzzers] Fix the mangler and reflection fuzzer build.
The mangler fuzzer and reflection fuzzer build was broken, both by a problem in
the CMake scripts and also because of changes that have happened in other parts
of the code.
2021-06-22 11:56:53 +01:00
Evan Wilde
49fad17cb4 Fix spacing in if's
Little fix for the indentation of the if's.
2021-06-17 10:58:30 -07:00
Evan Wilde
b33d2273cc Update cmake/modules/AddSwift.cmake
Use `SEND_ERROR` instead of `FATAL_ERROR`.

Co-authored-by: Saleem Abdulrasool <compnerd@compnerd.org>
2021-06-17 10:39:31 -07:00
Evan Wilde
a884e7faec This should work on Windows
After talking with compnerd, because we're passing this directly to the
swift driver, we shouldn't have to do anything weird with the flags and
it should "just work". I'm frustrated enough with Windows that I'm just
going to go with that and go to bed. If I broke something, I'm sorry. I
tried as far as my sanity would allow.
2021-06-16 21:59:15 -07:00
Evan Wilde
90abf31d6f Pass sanitizer flags to swift on Unix-y systems
This patch fixes the part of the build system where we aren't passing
the sanitizer flags to swift, so the linker isn't linking against the
sanitizer libraries.
2021-06-16 16:42:53 -07:00
Erik Eckstein
809ce72e05 libswift: build support for the initial libswift
* add the (still empty) libswift package
* add build support for libswift in CMake
* add libswift to swift-frontend and sil-opt

The build can be controlled with the LIBSWIFT_BUILD_MODE cmake variable: by default it’s “DISABLE”, which means that libswift is not built. If it’s “HOSTTOOLS”, libswift is built with a pre-installed toolchain on the host system.
2021-06-09 11:25:15 +02:00
Michael Gottesman
98ab14d9ef [cmake] Rather than forcing parts of the build that don't depend on LLVM to define LLVM_COMMON_DEPENDS, just have add_swift_host_library respect the global if it is set. 2021-06-08 14:42:16 -07:00
Michael Gottesman
db370dec73 [cmake] Do not use the just built swift link directory for host side executables.
This is just cruft that remained from the time when swift's host/target used the
same cmake code. Host tools do not statically link against just built artifacts.
2021-06-08 14:42:16 -07:00
David Zarzycki
987faae14e [cmake] Fix fallout from pull request #37741 2021-06-03 14:37:19 -04:00
Michael Gottesman
ef2b9d8631 [cmake] On Darwin, teach add_swift_host_tool how to find swift's SDK/compat libs, fix the rpath of tools, and add tests.
There are three things going on here (note all on Darwin):

1. If one compiles a swift static library and links the static library into a
   cxx executable, the cxx executable will need the -L flags to find the
   appropriate libraries in the SDK/toolchain.

2. I fixed an rpath issue where due to old code I didn't understand/propagated
   forward, we were setting the rpath to be the -L directory in the appropriate
   SDK. After reasoning about this a little bit I realized that this was code
   that was actually intended to be used for target libraries (for which the
   given rpath would be correct). On the host side though on Darwin, we want to
   use the rpath for the standard stabilized stdlib on the system.

3. I added Build System Unittests to ensure that this keeps on working. I also
   added test cases that I should have added before. I just had never thought
   about how to test this and I realized this method would work and would
   prevent regressions while I am waiting for a new swiftc with driver fixes to
   land.
2021-06-01 22:01:39 -07:00
Michael Gottesman
cf4cdf4670 [cmake] Now that we link with cxx and set the right load paths, use appropriate backdeployment target for swiftc.
Before a8ae9525aa, we could not do this since we
would fail to link since we didn't pass to clang the path to the toolchain dir
when the compatibility libraries live.
2021-06-01 19:05:26 -07:00
Michael Gottesman
0b8c39bb9f [cmake] When compiling swift libraries that are not pure swift on macOS be sure to set the linker language to cxx.
I already did this for executables. The reason why we must do this is that right
now there are bugs in cmake's swift support that makes it so that one can not
use swiftc to link targets with mixed c/c++/swift content even if the swift
content is indirectly added via linking. To work around this we must also ensure
that all libraries with mixed c/c++/swift objects link using clang. As an
additional side-effect of this, we must pass to the clang linker -L flags that
swiftc would normally provide for the linker. The two cases where I needed to do
this were:

1. -L path for the compatibility libraries. This path points into the toolchain
where these live. This is important since otherwise we will fail to link given
the minimum deployment target that swift (both host/stdlib) target today (10.9).

2. -L path to the SDK. This path points to the SDKs lib/swift/${HOST_PLATFORM}
for swiftCore and friends.

That being said, we still want people to be able to link pure swift libraries
using swiftc, so we introduce an option called PURE_SWIFT to add_host_library
that preserves this and is used to also set
IGNORE_LLVM_UPDATE_COMPILE_FLAGS (which arguably should have been called
PURE_SWIFT).
2021-06-01 10:26:34 -07:00
Michael Gottesman
467b23ad9b Merge pull request #37577 from gottesmm/pr-1105250c37357c900a8232c2106cbb9fd68896f8
[cmake] Some more small changes to enable host side tools that use swift using standard cmake.
2021-05-23 11:43:04 -07:00
Argyrios Kyrtzidis
a3095e71aa [AddSwift.cmake] Unbreak non-assertions build
Fails to build with "error: macro name must be an identifier" due to trying to pass `-D-DNDEBUG` as compiler argument.
2021-05-21 21:57:48 -07:00
Michael Gottesman
53a7ccafba [cmake] Allow for add_swift_host_libraries to set that they shouldn't use llvm update flags.
This is specifically important for host libraries that include swift
content. llvm_update_compile_flags currently doesn't conditionalize the flags it
adds since it needs to be updated like I updated Swift's cmake in
558c9d4086.

In the short amount of time that I am dealing with upstream to patch those
flags, this patch will unblock eeckstein and let him continue with his libswift
work.
2021-05-21 15:20:30 -07:00
Michael Gottesman
245905d161 [cmake] Allow for host libraries to be object libraries by letting add_swift_host_library take an OBJECT parameter. 2021-05-21 15:20:30 -07:00
Michael Gottesman
0c1d8a6c6f [cmake] Enable cross-module-optimization when compiling swift libraries in release/relwithdebinfo. 2021-05-20 13:57:04 -07:00
Michael Gottesman
bc6dbd4a09 [cmake] Force the linker_language of host executables to be CXX.
In certain cases our executables are going to have a mix of cxx,swift. There are
current issues when linking cxx,swift code with swiftc itself, so this lets us
avoid that problem.
2021-05-20 13:57:04 -07:00
Michael Gottesman
7e439eed09 [cmake] For now when compiling host swift code into a library, put -gnone to prevent the driver from running dsymutil on static libraries.
Work around for this problem until rdar://78271443 (which tracks the underlying
issue) lands so this no longer happens.
2021-05-20 13:57:04 -07:00
Michael Gottesman
95aeaf7b64 Merge pull request #37510 from gottesmm/pr-af6b60d3b83155f33bb1d91e497422748ddcc917
[cmake] Use generator expressions to change conditionalize target_compile_definition that are for c/c++ only be used for c/c++
2021-05-19 19:01:57 -07:00
Michael Gottesman
558c9d4086 [cmake] Use generator expressions to change conditionalize target_compile_definition that are for c/c++ only be used for c/c++
I am in the process now of preparing the tree for the addition of Swift code in
the optimizer as a normal source of source file. The goal is to make it so that
one can just include a random swift library anywhere in the swift project host
build and the cmake will use the swift compiler from the host
toolchain/compile-link the code just as if it was a normal host side thing (1).

In order to do this though, we need to deal with the legacy of our cmake
creating compile flags without constraining the flags to only being used if
cmake is compiling c/c++ code. To fix this, I just inserted generator
expressions into the host side swift build's cmake that uses generator
expressions to perform such conditionalization. The result is that the parts of
a target that are c/c++ will get these flags, but these flags will not propagate
to any Swift files that we add.

(1) With time this implies that we will need to be able to bootstrap the swift
compiler. We are not crossing that bridge now since the only places that we are
going to use this today is in the SILOptimizer optimier passes. These can always
be disabled while cross compiling, meaning that we can make progress here
without having the bootstrapping completely ironed out.
2021-05-19 14:46:36 -07:00
Michael Gottesman
9412f19802 [cmake] Change set_swift_llvm_is_available to set definitions on a specific target.
Otherwise we set it on all targets/languages in a subdirectory (I forgot if it
propagates up). Regardless, this type of viral stuff is something we want to
move away from since it creates a code that is a "forall" piece of code rather
than a piece of code that only effects a single target.

I also conditionalized the actual definitions being added on the compiled file's
language being C,CXX,OBJC,OBJCXX since as we add Swift sources to the host side
of the compiler, we will not want these flags to propagate to Swift sources.
2021-05-19 13:22:02 -07:00
Dario Rexin
1ae371b470 Re-add dependency on libatomic for 32-bit Linux platforms (#36659) 2021-03-31 13:31:58 -07:00
buttaface
e6f5913772 [android] Move to the NDK's unified sysroot (#34491)
Since the NDK removes the platforms/ and sysroot/ directories in the latest NDK
22, switch to the unified sysroot in toolchains/llvm/ and take advantage of a
bunch of simplification that's now possible.
2021-02-07 09:19:18 -08:00
Varun Gandhi
36b589d623 Merge pull request #35538 from mininny/disable-dead-stripping-option
[build-script] Add swift-disable-dead-stripping option for disabling dead stripping
2021-01-31 16:31:48 -08:00
Erik Eckstein
adae4d7dc7 cmake: another fix for include all header files in Xcode projects.
Header files from within the lib directory were missing.
Also: use get_filename_component instead of regex matching.
2021-01-29 20:48:33 +01:00
Erik Eckstein
3c90576db0 cmake: fix Xcode project generation to include all header files.
This was broken by commit cf1f240534.
This commit reverts the 2 lines which broke the inclusion of header files in the generated Xcode project.
2021-01-29 16:29:08 +01:00
Minhyuk Kim
b0426829fe Add swift_disable_dead_stripping option for disabling dead stripping in Swift build 2021-01-22 23:56:02 +09:00