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.
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.
The host value is used as part of the path to the tools. The NDK only
has Darwin, Linux, and Windows prebuilts. Enumerate the hosts fully and
record an error message otherwise.
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.
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.)
Many build systems that support Swift don't use swiftc to drive the linker. To make things
easier for these build systems, also use autolinking to pull in the needed compatibility
libraries. This is less ideal than letting the driver add it at link time, since individual
compile jobs don't know whether they're building an executable or not. Introduce a
`-disable-autolink-runtime-compatibility` flag, which build systems that do drive the linker
with swiftc can pass to avoid autolinking.
rdar://problem/50057445
Ensure that we build all the target libraries with the correct build
configuration. This is needed on Windows where the different MSVC
runtime libraries are ABI incompatible.
These properties are extraneous. They are never queried, and the
`set(...CACHE)` which precedes them will ensure that the value is
cached. This should be functionally equivalent.
On Windows, there are multiple variants of the C runtime that must be
explicitly specified and consistently used from the runtime to the
application. The new `-libc` option allows us to control the linking
phase by correctly embedding the requested library to be linked. It is
made into a required parameter on Windows and will add in the
appropriate flags for the imported C headers as well. This ensures that
the C library is not incorrectly linked.
Preconditions have been moved to the top of the file. All the variables set have been grouped by kind and a few converted to cache variables for better control when building. This should cut down on merge-conflicts as well."
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.
Now that that's stabilized, we don't have to keep them in Swift 4 mode
any longer. (Arguably we don't need the CMake variable at all, but it
may be useful again in the future.)
rdar://problem/49040980
CMake supports the notion of installation components. Right now we have some
custom code for supporting swift components. I think that for installation
purposes, it would be nice to use the CMake component system.
This should be a non-functional change. We should still only be generating
install rules for targets and files in components we want to install, and we
still use the install ninja target to install everything.
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.
This adjusts the windows build for cross-compiling to use the correct
variable. Import libraries will be generated and tracked properly if
the CMAKE_SYSTEM_NAME is set to Windows. It does not matter what the
build system is.
Copy the runtime component into the swift runtime directory. Normally
the runtime directory is not the same as the library directory on
Windows. This copies the runtime component into the build tree into the
runtime directory to permit the tests to find the standard library.
Rather than have the ICU handling be pushed down into the library handling, this
will move it into the CFLAGS calulation which was being augmented previously.
It is a cleanup that makes it easier to reason about the flags handling.
Adjust the `c_compile_flags` variable to ensure that the flags are ordered
correctly. This is of import for the android build which may end up using
invalid header search path ordering otherwise. This ensures that the path
for the ICU includes comes after the C++ headers which is necessary in new
C++ releases which shadow math.h
Move the ICU flag handling to the same area as `_c_compile_variant_flags` which
computes the C compile flags. This allows us to ensure that we order the flags
correctly when they are merged into the `c_compile_flags`.
The CMake variables ${sdk} and ${arch} are only set if
_add_variant_link_flags is invoked from add_swift_target_library calling
_add_swift_library_single. If you get to _add_swift_library_single from
add_swift_host_library, those variables will not be set and subsequent
linking will not find ICU libraries. This was an issue when building
swift host libraries on Android.