Commit Graph

557 Commits

Author SHA1 Message Date
Devin Coughlin
63ce243437 [CMake] Add initial build system support for macCatalyst
This commit adds initial build system support for macCatalyst,
an Apple technology that enables code targeting iOS
to be recompiled so that it can be executed on macOS while still using
iOS APIs. This is the first in a series of commits building out support for
macCatalyst in the compiler, runtime, standard library, and overlays. Swift
for macCatalyst represents the work of multiple people, including
Devin Coughlin, Ross Bayer, and Brent Royal-Gordon.

Under macCatalyst, compiler-provided shared libraries (including overlays)
are built as one of four kinds (or "flavors") of libraries,
each with different install names and Mach-O load commands. This commit
adds the build system infrastructure to produce these different
library flavors.

**macOS-like Libraries**

A "macOS-like" library (such as the GLKit overlay) is a plain-old macOS library
that can only be loaded into regular macOS processes. It has a macOS slice with
a single load command allowing it to be loaded into normal macOS processes.

**iOS-like Libraries**

An "iOS-like" library, such as the UIKit overlay, is a library with a
macOS slice but with a load command that only allows it be loaded into
macCatalyst processes. iOS-like libraries are produced by passing a new
target tuple to the compiler:

  swiftc ... -target x86_64-apple-ios13.0-macabi ...

Here 'ios' (and an iOS version number) is used for OS portion
of the triple, but the 'macabi' environment tells the compiler
that the library is intended for macCatalyst.

**Zippered Libraries**

A "zippered" library can be loaded into either a macCatalyst process or
a standard macOS process. Since macCatalyst does not introduce a new Mach-O
slice, the same code is shared between both processes. Zippered libraries
are usually relatively low level and with an API surface that is similar
between macOS and iOS (for example, both the Foundation overlay and the Swift
Standard Library/Runtime itself are zippered).

Zippered libraries are created by passing both the usual `-target`
flag to the compiler and an additional `-target-variant` flag:

   swiftc ... -target x86_64-apple-macos10.15 \
              -target-variant x86_64-apple-ios13.0-macabi

Just like the -target flag, -target-variant takes a target tuple.
This tells the compiler to compile the library for the -target tuple but
to add an extra load command, allowing the library to be loaded into processes
of the -target-variant flavor as well.

While a single zippered library and slice is shared between macOS and
macCatalyst, zippered libraries require two separate .swiftinterface/.swiftmodule
files, one for macOS and one for macCatalyst. When a macOS or macCatalyst client
imports the library, it will use module file for its flavor to determine what
symbols are present. This enables a zippered library to expose a subset of its
target APIs to its target-variant.

**Unzippered-Twin Libraries**

"Unzippered Twins" are pairs of libraries with the same name but different
contents and install locations, one for use from macOS processes and one for
use from macCatalyst processes. Unzippered twins are usually libraries that
depend on AppKit on macOS and UIKit on iOS (for example, the MapKit overlay)
and so do not share a common implementation between macOS and macCatalyst.

The macCatalyst version of an unzippered twin is installed in a parallel
directory hierarchy rooted at /System/iOSSupport/. So, for example, while macOS
and zippered Swift overlays are installed in /usr/lib/swift/, iOS-like and
the macCatalyst side of unzippered twins are installed in
/System/iOSSupport/usr/lib/swift. When building for macCatalyst, the build system
passes additional search paths so that the macCatalyst version of libraries is
found before macOS versions.

The add_swift_target_library() funciton now take an
optional  MACCATALYST_BUILD_FLAVOR, which enables swift libraries to indicate
which flavor of library they are.
2020-01-21 18:26:13 -08:00
Xi Ge
7a1ac6b5a4 cmake: add SDK library search path for overlays unavailable in the source
When force linking auto-linked libraries, an overlay will fail to link if the dependence
libraries are missing from the source. This change provides linker flags
to search overlay libraries from the SDK.
2020-01-06 21:17:02 -08:00
Butta
14cc620016 [android] A few tweaks for native compilation and to get more tests working
Now that CMAKE_HOST_SYSTEM_NAME and CMAKE_SYSTEM_NAME are set by default to
Android in the Termux app, make the needed tweaks. Some tests were adapted
to work natively on Android too, adds sys/cdefs.h to the Bionic modulemap,
and includes the start of native Android platform support in the build-script.
2019-12-07 01:01:59 +05:30
Eric Miotto
88a046c959 Incorporate review feedback from Micheal 2019-11-20 14:27:24 -08:00
Eric Miotto
4827ed7d85 Add explanation about the change 2019-11-15 15:41:14 -08:00
Eric Miotto
61a8e72091 Build: search libraries in Apple SDKs (if needed)
Addresses rdar://problem/56204969
2019-11-07 07:46:40 -08:00
Saleem Abdulrasool
b861bcc87b build: check the compiler against the correct variable
We were checking the compiler ID against the name of the compiler
binary.  This happened to pass incorrectly on Windows, which hid the
bug.
2019-11-04 10:52:18 -08:00
Saleem Abdulrasool
7a2a0e77dc build: add a dependency on clang
This enables injecting a dependency on clang for the target libraries if
the host compiler is not clang.
2019-10-30 16:50:04 -07:00
Dan Zheng
2bd55f6755 [Autodiff upstream] Add build-script flag for differentiable programming. (#27595)
Add `--enable-experimental-differentiable-programming` build-script flag.

The build-script flag enables/disables standard library additions
related to differentiable programming. This will allow official Swift
releases to disable these additions.

The build-script flag is on by default to ensure testing of
differentiable programming standard library additions. An additional
driver flag must be enabled to use differentiable programming features:
https://github.com/apple/swift/pull/27446
2019-10-14 14:34:48 -07:00
Saleem Abdulrasool
89516d00e7 build: dereference variable as appropriate
Certain versions of CMake behave differently with variable expansion.  This may
be evaluated incorrectly in some versions.  Dereference the value explicitly.
2019-08-29 13:54:20 -07:00
Alex Langford
61be4d969f [CMake][NFC] Introduce component targets for proper dependency tracking
This commit introduces a CMake target for each component, adds install targets
for them, and switches build-script-impl to use the target `install-components`
for installation. Each of the targets for each component depends on each
of the individual targets and outputs that are associated with the
corresponding swift-component.

This is equivalent to what already exists, because right now install rules are
only generated for components that we want to install. Therefore, this commit
should be an NFC.

This is a resubmission (with modifications) of an earlier change. I originally
committed this but there were problems with some installation rules.
2019-08-22 10:16:50 -07:00
Alex
1319fbd29e Revert "[CMake] Fix up and fill out swift exports." 2019-08-19 15:28:51 -07:00
Alex Langford
f7dde8d419 [CMake] Fix up SwiftConfig and SwiftExports 2019-08-09 11:02:50 -07:00
Ben Langmuir
327c666b8a Revert "[CMake][NFC] Introduce component targets for proper dependency tracking" 2019-08-08 16:35:59 -07:00
Alex Langford
50a0e87c69 [CMake][NFC] Introduce component targets for proper dependency tracking
This commit introduces a CMake target for each component, adds install targets
for them, and switches build-script-impl to use the target `install-components`
for installation. Each of the targets for each component depends on each
of the individual targets and outputs that are associated with the
corresponding swift-component.

This is equivalent to what already exists, because right now install rules are
only generated for components that we want to install. Therefore, this commit
should be an NFC.
2019-08-08 11:50:35 -07:00
Daniel Rodríguez Troitiño
7e332e4437 Merge pull request #23208 from buttaface/droid
[android] Add support for natively building on Android
2019-08-05 08:39:40 -07:00
Alex Langford
184d942ba0 [CMake] add_swift_target_library shouldn't implicitly set INSTALL_IN_TARGET
This makes it more explicit what the install component of a target
library is if you don't see one (and its marked as IS_SDK_OVERLAY).
Explicit in this case makes more sense, as you don't have to rely on
knowledge of how `add_swift_target_library` is implemented to understand
what component is used to install the target.
2019-08-02 13:51:52 -07:00
swift-ci
e6ae7867bf Merge pull request #26441 from alexshap/linux_compile_flags 2019-08-01 18:46:57 -07:00
swift-ci
d5d4ac672b Merge pull request #26338 from xiaobai/debride-option 2019-08-01 18:42:33 -07:00
Alex Langford
8519460e00 [CMake] Fix small bug in _add_swift_library_single
This option should be `SWIFTLIB_SINGLE_TARGET_LIBRARY`. If you rely on
`SWIFTLIB_TARGET_LIBRARY`, you get whatever was set in add_swift_target_library.
While these should be the same, I'm trying to remove `SWIFTLIB_TARGET_LIBRARY`
entirely.
2019-08-01 15:36:03 -07:00
Alexander Shaposhnikov
6febe07dec Introduce SWIFT_COMPILE_FLAGS_LINUX 2019-07-31 16:28:04 -07:00
Butta
796d6ade9a [android] Add support for natively building on Android
Check if building on Android through the ANDROID_DATA environment variable, then set
SWIFT_ANDROID_NATIVE_SYSROOT to the default layout for the Termux app, and key all the
include, lib, and other SDK paths off of that. The system libc and a few other libraries
are linked against from /system/lib[64]. Finally, check if lit is running natively on
Android and don't use adb if so.
2019-07-30 00:38:36 +05:30
Alex Langford
a16c71cc86 [CMake] Remove TARGET_LIBRARY option from add_swift_target_library
If you're calling add_swift_target_library, you already know it's a
target library.
2019-07-24 14:55:08 -07:00
Alex Langford
b9e01b6309 [CMake][NFC] Remove unused logic to choose swift component
add_swift_target_library should always have `TARGET_LIBRARY` set. A few
lines down, there is a precondition that makes sure that it is set. This
check and subsequent assignment of `SWIFTLIB_INSTALL_IN_TARGET` should
never get triggered.
2019-07-23 15:12:40 -07:00
Alex Langford
07214e1377 [CMake] Support cmake install components for targets with multiple target files
When installing a target, you could have multiple target files with
different rules for installation. For example, you can specify rules for
`RUNTIME` files, `LIBRARY` files, `ARCHIVE` files, etc. Each of these
can take several options, e.g. `DESTINATION`. When you want to specify
the install component for a target, each of the different target file
rules need to have their own `COMPONENT` field. If not, they end up as
"Unspecified" which means they will not get installed with the
associated swift component.
2019-07-17 13:27:41 -07:00
Saleem Abdulrasool
80b92eb745 Merge pull request #26070 from compnerd/one-more-time-gotta-change-the-flags
build: use `-isystem` rather than `-I` for C++ headers
2019-07-10 15:31:32 -07:00
Saleem Abdulrasool
a2408642f2 build: use -isystem rather than -I for C++ headers
The system headers should be given lower priority than the user
specified headers.  This requires that we include the system C++ headers
as `-isystem`.  Without this, it is not possible to use a custom
toolchain to replace the clang compiler for building the android
runtime.
2019-07-10 13:58:39 -07:00
Puyan Lotfi
1551e014b4 Adding -nostdinc++ to Android build of Swift.
On Android, we explicitly setup the include paths for the C++ headers.
As a result, we do not want to pick up any system headers that the
toolchain may have visible to it. If this flag is not added then clang
will look in the wrong places to get the headers for things like stddef
etc.
2019-07-09 14:11:05 -07:00
Saleem Abdulrasool
140e02d0ef build: dereference a variable when checking (NFC)
Some versions of CMake dereference the variable here and others do not.
Explicitly dereference to ensure that the library name is properly set.
Failure to do so will fail to load the library as the output path
becomes the name.
2019-07-04 10:41:35 -07:00
Saleem Abdulrasool
336566fcfc build: dereference some variables for android x64
These variables need to be dereferenced on some versions of CMake.  This
should fix the android x64 nightlies.
2019-06-29 21:37:17 -07:00
Saleem Abdulrasool
01e195c101 build: add a workaround for android NDK[<21]
The clang in the android NDK (as well as the current stable Clang in
Swift) have a bug with Android x86_64 targets where the CPU's 16-byte
(double-word) CAS instruction feature is disabled resulting in the
double word CAS being lowered to a libcall
(`__sync_val_compare_and_swap_16`) rather than the CPU instruction
(`cmpxchg16b`).  This results in the inability to link the content.
Work around this by enabling the feature manually in the build for now.
2019-06-25 14:20:42 -07: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
1ab0008d23 Merge pull request #25523 from drodriguez/android-fix-test-build
[android] LINKER_LANGUAGE needs to be applied to executables too.
2019-06-18 12:35:12 -07:00
Saleem Abdulrasool
8bb91443a9 build: dereference variable for some versions of CMake
CMake quoting is odd and in some versions this would compare the wrong
strings.
2019-06-17 15:07:04 -07:00
Daniel Rodríguez Troitiño
0a27c88163 [android] LINKER_LANGUAGE needs to be applied to executables too.
A previous change did the same change, but only for libraries. The
executables also need to be build to be linked as C to avoid clang++
automatic linking of C++.
2019-06-17 13:47:08 -07:00
Saleem Abdulrasool
5ef3df7c55 build: link to ICU by full path on Android
Use the variable that holds the path to the ICU libraries to link
against ICU rather than hardcoding the names.  This restores control to
the ICU linking to the way that traditional CMake `find_package` based
linking works.
2019-06-14 18:45:12 -07:00
Saleem Abdulrasool
c1c5ee9fa3 build: use LINKER_LANGUAGE to control linking on Android
Rather than using `-nolibstd++` which is not supported by the android toolchain,
use CMake's `LINKER_LANGAUGE` property on the targets.  Since we explicitly link
against the C++ runtime anyways, this avoids the problem of having to remove the
C++ runtime from the link.
2019-06-14 10:36:13 -07:00
Saleem Abdulrasool
bee99a3f4b build: spell parameter -fuse-ld= properly for Windows
We need to pass `-fuse-ld=` `gold.exe` on Windows when targeting
Android.  Given that we do not have a host toolchain for Linux on
Windows currently, do this unconditionally.  This is required for
cross-compiling from Windows to android.
2019-06-13 22:30:42 -07:00
Saleem Abdulrasool
ad913239ee Merge pull request #25161 from drodriguez/android-backtraces
[android] Basic support for backtraces.
2019-06-10 13:44:51 -07:00
Ross Bayer
8db65b35a4 Merge pull request #25122 from Rostepher/darwin-supported-archs
[Build System: CMake] Darwin Supported Archs and Modules.
2019-06-10 12:03:04 -07:00
Saleem Abdulrasool
fcb0ee59ae build: remove ALL_POSIX_PLATFORMS which is no longer used
Cleanup some CMake logic that we no longer need as the entire code base
now builds on all the targets.
2019-06-05 13:58:14 -07:00
Daniel Rodríguez Troitiño
a7025522a4 [android] Basic support for backtraces.
Android doesn't support the GNU backtrace call, but unwind.h is there to
help. The code is a little bit more complicated than a simple backtrace
call, but it is just a callback and the context struct.

Sadly, it seems that -funwind-tables is needed in every piece of code
that the backtrace needs to traverse, which means that at least the
runtime and the stubs need -funwind-tables. However, the flag has been
enabled for all targets (only on Android), just in case some other code
ends up being in the stack. This might only be necessary for ARM
targets, but currently we only build ARM targets in Android. The Swift
parts of the stack seems to have unwind information and can be unwind.

Another problem at the moment is the symbols from the executable are
normally missing. To get symbol names two things need to happen: the
symbol has to be public (so it is an exported symbol, and not just a
local symbol that dladdr seems to not provide the name), and the linker
has to be invoked with -export-dynamic. Without those two pieces, the
addresses are returned (and match the binary just fine), but no names
are printed.
2019-06-05 13:12:04 -07:00
Daniel Rodríguez Troitiño
9498b14af7 Merge pull request #25098 from vgorloff/macos-to-android-crosscompile
Android Intel 32/64 bit (i.e. Android Simulator) support.
2019-06-04 14:10:55 -07:00
Joe Groff
4ed8de10f9 Revert "Revert "Use autolinking to pull in compatibility libraries."" 2019-06-03 20:10:51 -07:00
Joe Groff
a7cc3a38cc Revert "Use autolinking to pull in compatibility libraries." 2019-06-03 14:18:39 -07:00
Ross Bayer
d9409957e0 [Build System: CMake] Check that targets exist before adding them to the global exports. 2019-06-01 17:48:51 -07:00
Joe Groff
dd91bc2180 Install compatibility archive alongside shared libraries.
Although it's a static archive, its use is only relevant to dynamically linked builds of the
standard library. (If you're statically linking a Swift runtime into your process, you don't
need to worry about compatibility with older runtimes.)
2019-05-31 13:11:20 -07:00
Ross Bayer
029c25a137 [Build System: CMake] Ensure the SDK supported architectures and module architectures lists are mutually exclusive. 2019-05-29 15:28:53 -07:00
Ross Bayer
4ec60332f9 [Build System: CMake] Add new SWIFT_DARWIN_MODULE_ARCHS CMake cache variable which allows users to specify architectures they wish to configure and build _just_ the .swiftmodule content, even if they are not 'supported' via SWIFT_DARWIN_SUPPORTED_ARCHS. 2019-05-29 13:34:05 -07:00
Ross Bayer
1bc306653c [Build System: CMake] Fix the arch-specific target exporting in add_swift_target_library to export targets for all the defined archs rather than _just_ the last one processed in the foreach loop above. 2019-05-29 13:34:05 -07:00