swift: update from 5.5.3 to 5.6.1

This commit is contained in:
Butta 2022-02-09 01:18:18 +05:30 committed by buttaface
parent 25167cf73d
commit bb345ed241
40 changed files with 1474 additions and 1642 deletions

View File

@ -2,8 +2,7 @@ TERMUX_PKG_HOMEPAGE=https://github.com/apple/swift-corelibs-libdispatch
TERMUX_PKG_DESCRIPTION="The libdispatch project, for concurrency on multicore hardware"
TERMUX_PKG_LICENSE="Apache-2.0"
TERMUX_PKG_MAINTAINER="@buttaface"
TERMUX_PKG_VERSION="1:5.5"
TERMUX_PKG_REVISION=1
TERMUX_PKG_VERSION="1:5.6.1"
TERMUX_PKG_SRCURL=https://github.com/apple/swift-corelibs-libdispatch/archive/swift-${TERMUX_PKG_VERSION:2}-RELEASE.tar.gz
TERMUX_PKG_SHA256=5efdfa1d2897c598acea42fc00776477bb3713645686774f5ff0818b26649e62
TERMUX_PKG_SHA256=856c9ffcf2ab2bbb28a6e0fa344277fc41aa0771419b283c7c4db69dad2b4cf9
TERMUX_PKG_DEPENDS="libc++, libblocksruntime"

View File

@ -1,27 +0,0 @@
From a632817a5bd5c82e5d571740ccf0772c3dbf9599
Date: Thu, 26 Aug 2021 23:55:41 +0530
Subject: [PATCH] [android] Update headers that were split in NDK 23
NDK 23 split stdatomic.h up and that causes problems when invoked from C++ files,
so use the new bits/stdatomic.h instead as a workaround, as seen in the test for
aosp-mirror/platform_bionic@76e2b15.
---
src/shims/atomic.h | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/shims/atomic.h b/src/shims/atomic.h
index c002e726a..bc232f1fb 100644
--- a/src/shims/atomic.h
+++ b/src/shims/atomic.h
@@ -35,7 +35,11 @@
#if defined(__cplusplus)
#define _Bool bool
#endif
+#if defined(__ANDROID__) && __NDK_MAJOR__ >= 23
+#include <bits/stdatomic.h>
+#else
#include <stdatomic.h>
+#endif
#define memory_order_ordered memory_order_seq_cst
#define memory_order_dependency memory_order_acquire

View File

@ -2,7 +2,7 @@ TERMUX_PKG_HOMEPAGE=https://github.com/apple/swift-llbuild
TERMUX_PKG_DESCRIPTION="A low-level build system, used by the Swift Package Manager"
TERMUX_PKG_LICENSE="Apache-2.0, NCSA"
TERMUX_PKG_MAINTAINER="@buttaface"
TERMUX_PKG_VERSION=5.5.2
TERMUX_PKG_VERSION=5.6.1
TERMUX_PKG_SRCURL=https://github.com/apple/swift-llbuild/archive/swift-${TERMUX_PKG_VERSION}-RELEASE.tar.gz
TERMUX_PKG_SHA256=6767df1c14d09c990e72c2e9ec9c61765610c1fe7801c92894afa36f9928d320
TERMUX_PKG_SHA256=3fe038b9b76a90803205d41f440eec46f21f23f42fd6f15be756b68907d04502
TERMUX_PKG_DEPENDS="libc++, libandroid-spawn, libsqlite"

View File

@ -2,13 +2,13 @@ TERMUX_PKG_HOMEPAGE=https://swift.org/
TERMUX_PKG_DESCRIPTION="Swift is a high-performance system programming language"
TERMUX_PKG_LICENSE="Apache-2.0, NCSA"
TERMUX_PKG_MAINTAINER="@buttaface"
TERMUX_PKG_VERSION=5.5.3
TERMUX_PKG_VERSION=5.6.1
SWIFT_RELEASE="RELEASE"
TERMUX_PKG_SRCURL=https://github.com/apple/swift/archive/swift-$TERMUX_PKG_VERSION-$SWIFT_RELEASE.tar.gz
TERMUX_PKG_SHA256=41c926ae261a2756fe5ff761927aafe297105dc62f676a27c3da477f13251888
TERMUX_PKG_SHA256=39e4e2b7343756e26627b945a384e1b828e38778b34cc5b0f3ecc23f18d22fd6
TERMUX_PKG_HOSTBUILD=true
TERMUX_PKG_DEPENDS="clang, libandroid-glob, libandroid-spawn, libcurl, libicu, libicu-static, libsqlite, libuuid, libxml2, libdispatch, llbuild"
TERMUX_PKG_BUILD_DEPENDS="cmake, ninja, perl, pkg-config, rsync"
TERMUX_PKG_DEPENDS="clang, libandroid-glob, libandroid-posix-semaphore, libandroid-spawn, libcurl, libicu, libicu-static, libsqlite, libuuid, libxml2, libdispatch, llbuild"
TERMUX_PKG_BUILD_DEPENDS="rsync"
TERMUX_PKG_BLACKLISTED_ARCHES="i686"
TERMUX_PKG_NO_STATICSPLIT=true
# Build of swift uses cmake, but the standard
@ -38,36 +38,38 @@ termux_step_post_get_source() {
mv .temp swift
declare -A library_checksums
library_checksums[swift-cmark]=f00df80d917cf6b3e1870a75f7b29bc7ac8b94479c0961167359e4156dcd1220
library_checksums[llvm-project]=d28f71363f6ae5fec59ec3c21e53ab91e3a196c833150329397888259765098b
library_checksums[swift-corelibs-libdispatch]=dc0912c2812953c84eea996358abd6a2dbeb97f334d5c1d4064e077ca43d569f
library_checksums[swift-corelibs-foundation]=aa11982d45f1eb238547be30c1b34409b08ee2de35fcf3a4981992d21839d0fc
library_checksums[swift-corelibs-xctest]=2c08d83a9c051329cadb248dd0dd5cddfe582f00bc1d569dc8dc59433c4906f3
library_checksums[swift-llbuild]=8444b840137f17d465e4080f8437b6b5fe68a01a095b4976e8e3e2f1a629b96a
library_checksums[swift-argument-parser]=9dfcb236f599e309e49af145610957648f8a59d9527b4202bc5bdda0068556d7
library_checksums[swift-cmark]=3a5c35b8018b079d99cae3305c9ede9c940aa298db0af92c418461fb0de289b6
library_checksums[llvm-project]=24343a2a7059b7cfc25c0acc884ebf9296209440ac0fe5948e541b168d818777
library_checksums[swift-corelibs-libdispatch]=856c9ffcf2ab2bbb28a6e0fa344277fc41aa0771419b283c7c4db69dad2b4cf9
library_checksums[swift-corelibs-foundation]=21d28ad500279eb66bb8dc9e33e4c8036e1472f30e82eeb76329b69aa4b622fc
library_checksums[swift-corelibs-xctest]=6a2f6a81a5dd295578b2b80522313e36b4d3e51c828fe8210b1c84c2f66237ca
library_checksums[swift-llbuild]=3fe038b9b76a90803205d41f440eec46f21f23f42fd6f15be756b68907d04502
library_checksums[swift-argument-parser]=a4d4c08cf280615fe6e00752ef60e28e76f07c25eb4706a9269bf38135cd9c3f
library_checksums[Yams]=8bbb28ef994f60afe54668093d652e4d40831c79885fa92b1c2cd0e17e26735a
library_checksums[swift-crypto]=86d6c22c9f89394fd579e967b0d5d0b6ce33cdbf52ba70f82fa313baf70c759f
library_checksums[swift-driver]=47d04b5120eaf508e73ed658b0564fab2fccb9313ef5180afc84d3040c31ccfc
library_checksums[swift-tools-support-core]=bf82f281d1c47a8f7762c0b01f2d772726a9da71fdd867b031e52bd15967504c
library_checksums[swift-package-manager]=6e46827b118f5449cf7c32b7c9eb6060829ff09a94c2278dd4253f7e56a35cac
library_checksums[indexstore-db]=b7c0f46f944e90e1ffa298b96f4cfc5ddeebf67d0935edee9858e0dfe8e30db6
library_checksums[sourcekit-lsp]=ef956db48fa2e80eefabdc4bfb68433b9e8555c6e39ec6b48a9b5b5628d8d5e4
library_checksums[swift-system]=865b8c380455eef27e73109835142920c60ae4c4f4178a3d12ad04acc83f1371
library_checksums[swift-driver]=94c1eba97cdb71594d1f432d80a08d33578c9911f3968a8cb946e9d8bbe4d20f
library_checksums[swift-tools-support-core]=5fecacc1e35e659eee9aeafb0cb84b894f08c9094520fd56eb7e131b9eb5a991
library_checksums[swift-package-manager]=0b375bbd0cc0b9296351064e0a012ca450675ce5021b2a029278463457026382
library_checksums[indexstore-db]=3cf0eddc514f89b86b07bf479f39fc83ded3aa2bfeaaca2b48729142ff976426
library_checksums[sourcekit-lsp]=a6f74d7bf4ee3615d4ac747a4b3747cfa8736b3d07274aeaba27f38886627cd7
for library in "${!library_checksums[@]}"; do \
GH_ORG="apple"
if [ "$library" = "swift-argument-parser" ]; then
GH_ORG="apple"
SRC_VERSION="0.4.3"
SRC_VERSION="1.0.3"
TAR_NAME=$SRC_VERSION
elif [ "$library" = "swift-crypto" ]; then
GH_ORG="apple"
SRC_VERSION="1.1.5"
TAR_NAME=$SRC_VERSION
elif [ "$library" = "swift-system" ]; then
SRC_VERSION="1.1.1"
TAR_NAME=$SRC_VERSION
elif [ "$library" = "Yams" ]; then
GH_ORG="jpsim"
SRC_VERSION="4.0.2"
TAR_NAME=$SRC_VERSION
else
GH_ORG="apple"
SRC_VERSION=$SWIFT_RELEASE
TAR_NAME=swift-$TERMUX_PKG_VERSION-$SWIFT_RELEASE
fi
@ -89,7 +91,7 @@ termux_step_post_get_source() {
termux_download \
https://download.swift.org/swift-$TERMUX_PKG_VERSION-release/ubuntu2004/swift-$TERMUX_PKG_VERSION-$SWIFT_RELEASE/$SWIFT_BIN.tar.gz \
$TERMUX_PKG_CACHEDIR/$SWIFT_BIN.tar.gz \
68c69d7978ff90332580c5de489aff96df84bc0cf67d94ecef41f6848f68db91
2b4f22d4a8b59fe8e050f0b7f020f8d8f12553cbda56709b2340a4a3bb90cfea
fi
}
@ -114,36 +116,21 @@ termux_step_host_build() {
# Natively compile llvm-tblgen and some other files needed later.
SWIFT_BUILD_ROOT=$TERMUX_PKG_HOSTBUILD_DIR $TERMUX_PKG_SRCDIR/swift/utils/build-script \
-R --no-assertions -j $TERMUX_MAKE_PROCESSES $SWIFT_PATH_FLAGS \
$SKIP_BUILD --build-toolchain-only \
$SKIP_BUILD --skip-early-swift-driver --build-toolchain-only \
--host-cc=$CLANG --host-cxx=$CLANGXX
tar xf $TERMUX_PKG_CACHEDIR/$SWIFT_BIN.tar.gz -C $TERMUX_PKG_HOSTBUILD_DIR
if [ "$TERMUX_ARCH" == "aarch64" ]; then
rm $TERMUX_PKG_HOSTBUILD_DIR/swift-linux-x86_64/lib/swift/FrameworkABIBaseline
cp -r $SWIFT_BIN/usr/lib/swift $TERMUX_PKG_HOSTBUILD_DIR/swift-linux-x86_64/lib
ln -sf $SWIFT_BINDIR/../lib/clang/10.0.0 $TERMUX_PKG_HOSTBUILD_DIR/swift-linux-x86_64/lib/swift/clang
patchelf --set-rpath \$ORIGIN $TERMUX_PKG_HOSTBUILD_DIR/swift-linux-x86_64/lib/swift/linux/libicu{uc,i18n}swift.so.65.1
ln -sf $SWIFT_BINDIR/../lib/clang/13.0.0 $TERMUX_PKG_HOSTBUILD_DIR/swift-linux-x86_64/lib/swift/clang
fi
fi
}
termux_step_pre_configure() {
cd llbuild
# A single patch needed from the existing llbuild package
patch -p1 < $TERMUX_PKG_BUILDER_DIR/../llbuild/lib-llvm-Support-CmakeLists.txt.patch
cd ../llvm-project
cd llvm-project
patch -p1 < $TERMUX_PKG_BUILDER_DIR/../libllvm/clang-lib-Driver-ToolChain.cpp.patch
patch -p1 < $TERMUX_PKG_BUILDER_DIR/clang-lib-Driver-ToolChains-Linux.cpp.diff
cd ../swift-corelibs-libdispatch
patch -p1 < $TERMUX_PKG_BUILDER_DIR/../libdispatch/src-shims-atomic.h.patch
cd ..
if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ]; then
sed "s%\@TERMUX_PREFIX\@%${TERMUX_PREFIX}%g" \
$TERMUX_PKG_BUILDER_DIR/swiftpm-driver-lsp-termux-flags | \
sed "s%\@CCTERMUX_HOST_PLATFORM\@%${CCTERMUX_HOST_PLATFORM}%g" | patch -p1
fi
}
termux_step_make() {
@ -162,16 +149,12 @@ termux_step_make() {
SWIFT_BUILD_FLAGS="$SWIFT_BUILD_FLAGS --android
--android-ndk $TERMUX_STANDALONE_TOOLCHAIN --android-arch $SWIFT_ARCH
--android-icu-uc $TERMUX_PREFIX/lib/libicuuc.so
--android-icu-uc-include $TERMUX_PREFIX/include/
--android-icu-i18n $TERMUX_PREFIX/lib/libicui18n.so
--android-icu-i18n-include $TERMUX_PREFIX/include/
--android-icu-data $TERMUX_PREFIX/lib/libicudata.so --build-toolchain-only
--skip-local-build --skip-local-host-install
--build-toolchain-only --skip-local-build --skip-local-host-install
--cross-compile-hosts=android-$SWIFT_ARCH
--cross-compile-deps-path=$(dirname $TERMUX_PREFIX)
$SWIFT_TOOLCHAIN
--native-clang-tools-path=$SWIFT_BINDIR"
--native-clang-tools-path=$SWIFT_BINDIR
--cross-compile-append-host-target-to-destdir=False"
fi
SWIFT_BUILD_ROOT=$TERMUX_PKG_BUILDDIR $TERMUX_PKG_SRCDIR/swift/utils/build-script \

View File

@ -1,33 +0,0 @@
diff --git a/llvm-project/clang/runtime/CMakeLists.txt b/llvm-project/clang/runtime/CMakeLists.txt
index 61b1c60bf590..5b0d10a67699 100644
--- a/llvm-project/clang/runtime/CMakeLists.txt
+++ b/llvm-project/clang/runtime/CMakeLists.txt
@@ -75,6 +75,7 @@ if(LLVM_BUILD_EXTERNAL_COMPILER_RT AND EXISTS ${COMPILER_RT_SRC_ROOT}/)
CMAKE_ARGS ${CLANG_COMPILER_RT_CMAKE_ARGS}
-DCMAKE_C_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang
-DCMAKE_CXX_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++
+ -DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY
-DCMAKE_ASM_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
@@ -84,6 +85,7 @@ if(LLVM_BUILD_EXTERNAL_COMPILER_RT AND EXISTS ${COMPILER_RT_SRC_ROOT}/)
-DCOMPILER_RT_EXEC_OUTPUT_DIR=${LLVM_RUNTIME_OUTPUT_INTDIR}
-DCOMPILER_RT_INSTALL_PATH:STRING=lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}
-DCOMPILER_RT_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
+ -DCOMPILER_RT_USE_BUILTINS_LIBRARY=ON
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
-DLLVM_LIBDIR_SUFFIX=${LLVM_LIBDIR_SUFFIX}
-DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_RUNTIME_OUTPUT_INTDIR}
diff --git a/llvm-project/compiler-rt/cmake/Modules/HandleCompilerRT.cmake b/llvm-project/compiler-rt/cmake/Modules/HandleCompilerRT.cmake
index ac9e0871489d..b495cbfb5c2e 100644
--- a/llvm-project/compiler-rt/cmake/Modules/HandleCompilerRT.cmake
+++ b/llvm-project/compiler-rt/cmake/Modules/HandleCompilerRT.cmake
@@ -31,7 +31,7 @@ function(find_compiler_rt_library name target variable)
# If the cache variable is not defined, invoke clang and then
# set it with cache_compiler_rt_library.
set(CLANG_COMMAND ${CMAKE_CXX_COMPILER} ${SANITIZER_COMMON_FLAGS}
- "--rtlib=compiler-rt" "-print-libgcc-file-name")
+ "--rtlib=compiler-rt" "-print-libgcc-file-name" "-resource-dir=$ENV{PREFIX}/lib/clang/$ENV{TERMUX_CLANG_VERSION}/")
if(target)
list(APPEND CLANG_COMMAND "--target=${target}")
endif()

View File

@ -1,43 +0,0 @@
commit 82ee1f5c31a618d3fb167953e0516dce28b52263
Date: Thu May 7 15:29:46 2020 +0530
[CMake] fix runpath for ELF platforms
Remove the absolute path to the host toolchain's stdlib from plutil, and add
it as a CMake BUILD_PATH, so that it's removed upon installation.
diff --git a/swift-corelibs-foundation/Sources/Tools/plutil/CMakeLists.txt b/swift-corelibs-foundation/Sources/Tools/plutil/CMakeLists.txt
index 7f2913b3..3c9163c1 100644
--- a/swift-corelibs-foundation/Sources/Tools/plutil/CMakeLists.txt
+++ b/swift-corelibs-foundation/Sources/Tools/plutil/CMakeLists.txt
@@ -2,6 +2,30 @@ add_executable(plutil
main.swift)
target_link_libraries(plutil PRIVATE
Foundation)
+
+# On ELF platforms, remove the absolute rpath to the host toolchain's stdlib, then add it
+# back temporarily as a BUILD_RPATH just for the tests.
+if(NOT CMAKE_SYSTEM_NAME MATCHES "Darwin|Windows")
+ target_link_options(plutil PRIVATE "SHELL:-no-toolchain-stdlib-rpath")
+
+ # This assumes the host is the target, pass a target flag when cross-compiling.
+ execute_process(
+ COMMAND ${CMAKE_Swift_COMPILER} -print-target-info
+ OUTPUT_VARIABLE output
+ ERROR_VARIABLE error_output
+ RESULT_VARIABLE result
+ )
+ if(NOT ${result} EQUAL 0)
+ message(FATAL_ERROR "Error getting target info with\n"
+ " `${CMAKE_Swift_COMPILER} -print-target-info`\n"
+ "Error:\n"
+ " ${error_output}")
+ endif()
+
+ string(REGEX MATCH "\"runtimeLibraryPaths\": \\[\n\ +\"([^\"]+)\"" path ${output})
+ set_target_properties(plutil PROPERTIES BUILD_RPATH ${CMAKE_MATCH_1})
+endif()
+
set_target_properties(plutil PROPERTIES
INSTALL_RPATH "$ORIGIN/../lib/swift/$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>")

View File

@ -1,15 +1,18 @@
--- a/clang/lib/Driver/ToolChains/Linux.cpp 2019-12-21 22:30:03.676720096 +0000
+++ b/clang/lib/Driver/ToolChains/Linux.cpp 2019-12-21 22:34:42.941719383 +0000
@@ -374,7 +374,7 @@
// those searched.
// FIXME: It's not clear whether we should use the driver's installed
// directory ('Dir' below) or the ResourceDir.
- if (StringRef(D.Dir).startswith(SysRoot)) {
+ if (StringRef(D.Dir).startswith(SysRoot) && !IsAndroid) {
addPathIfExists(D, D.Dir + "/../lib/" + MultiarchTriple, Paths);
addPathIfExists(D, D.Dir + "/../" + OSLibDir, Paths);
}
@@ -403,7 +403,7 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
diff --git a/llvm-project/clang/lib/Driver/ToolChains/Linux.cpp b/llvm-project/clang/lib/Driver/ToolChains/Linux.cpp
--- a/llvm-project/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/llvm-project/clang/lib/Driver/ToolChains/Linux.cpp
@@ -162,8 +162,8 @@
// FIXME: This is a bit of a hack. We should really unify this code for
// reasoning about oslibdir spellings with the lib dir spellings in the
// GCCInstallationDetector, but that is a more significant refactoring.
- if (Triple.getArch() == llvm::Triple::x86 || Triple.isPPC32() ||
- Triple.getArch() == llvm::Triple::sparc)
+ if (!Triple.isAndroid() && (Triple.getArch() == llvm::Triple::x86 || Triple.isPPC32() ||
+ Triple.getArch() == llvm::Triple::sparc))
return "lib32";
if (Triple.getArch() == llvm::Triple::x86_64 && Triple.isX32())
@@ -287,7 +287,7 @@
if (Triple.getVendor() == llvm::Triple::OpenEmbedded &&
Triple.isArch64Bit())
addPathIfExists(D, SysRoot + "/usr/" + OSLibDir, Paths);
@ -18,7 +21,7 @@
addPathIfExists(D, SysRoot + "/usr/lib/../" + OSLibDir, Paths);
if (IsRISCV) {
StringRef ABIName = tools::riscv::getRISCVABI(Args, Triple);
@@ -447,11 +447,19 @@
@@ -302,11 +302,19 @@
// searched.
// FIXME: It's not clear whether we should use the driver's installed
// directory ('Dir' below) or the ResourceDir.

View File

@ -0,0 +1,13 @@
diff --git a/llbuild/lib/BuildSystem/BuildSystem.cpp b/llbuild/lib/BuildSystem/BuildSystem.cpp
index 297dee34..40df58ca 100644
--- a/llbuild/lib/BuildSystem/BuildSystem.cpp
+++ b/llbuild/lib/BuildSystem/BuildSystem.cpp
@@ -3269,7 +3269,7 @@ class ArchiveShellCommand : public ExternalCommand {
if (const char *ar = std::getenv("AR"))
args.push_back(std::string(ar));
else
- args.push_back("ar");
+ args.push_back("llvm-ar");
args.push_back("cr");
args.push_back(archiveName);
args.insert(args.end(), archiveInputs.begin(), archiveInputs.end());

View File

@ -1,44 +0,0 @@
commit a478b0a199f4928041390d1f35dd5e226936b42c
Author: Ryan Prichard <rprichard@google.com>
Date: Tue Mar 9 14:20:45 2021 -0800
[Android] Default to --rtlib=compiler-rt
By default, the driver uses the compiler-rt builtins and links with
-l:libunwind.a.
Restore the previous behavior by passing --rtlib=libgcc.
Reviewed By: danalbert
Differential Revision: https://reviews.llvm.org/D96404
diff --git a/llvm-project/clang/lib/Driver/ToolChains/Linux.cpp b/llvm-project/clang/lib/Driver/ToolChains/Linux.cpp
index 93a56be6a7a4..ad98013dd4f0 100644
--- a/llvm-project/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/llvm-project/clang/lib/Driver/ToolChains/Linux.cpp
@@ -363,6 +363,12 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
}
}
+ToolChain::RuntimeLibType Linux::GetDefaultRuntimeLibType() const {
+ if (getTriple().isAndroid())
+ return ToolChain::RLT_CompilerRT;
+ return Generic_ELF::GetDefaultRuntimeLibType();
+}
+
ToolChain::CXXStdlibType Linux::GetDefaultCXXStdlibType() const {
if (getTriple().isAndroid())
return ToolChain::CST_Libcxx;
diff --git a/llvm-project/clang/lib/Driver/ToolChains/Linux.h b/llvm-project/clang/lib/Driver/ToolChains/Linux.h
index a45236bc10d3..05e01a208456 100644
--- a/llvm-project/clang/lib/Driver/ToolChains/Linux.h
+++ b/llvm-project/clang/lib/Driver/ToolChains/Linux.h
@@ -35,6 +35,7 @@ public:
llvm::opt::ArgStringList &CC1Args) const override;
void AddIAMCUIncludeArgs(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const override;
+ RuntimeLibType GetDefaultRuntimeLibType() const override;
CXXStdlibType GetDefaultCXXStdlibType() const override;
bool isPIEDefault() const override;
bool isNoExecStackDefault() const override;

View File

@ -1,13 +0,0 @@
diff --git a/llvm-project/clang/tools/IndexStore/CMakeLists.txt b/llvm-project/clang/tools/IndexStore/CMakeLists.txt
index 1bcfc0734785..ddb77c91b22d 100644
--- a/llvm-project/clang/tools/IndexStore/CMakeLists.txt
+++ b/llvm-project/clang/tools/IndexStore/CMakeLists.txt
@@ -65,7 +65,7 @@ if (LLVM_INSTALL_TOOLCHAIN_ONLY)
endif()
endif()
-set(INDEXSTORE_HEADERS_INSTALL_DESTINATION "local/include")
+set(INDEXSTORE_HEADERS_INSTALL_DESTINATION "include")
install(DIRECTORY ../../include/indexstore
COMPONENT IndexStore

View File

@ -1,105 +0,0 @@
diff --git a/sourcekit-lsp/Utilities/build-script-helper.py b/sourcekit-lsp/Utilities/build-script-helper.py
index 58f8676..7fa6a46 100755
--- a/sourcekit-lsp/Utilities/build-script-helper.py
+++ b/sourcekit-lsp/Utilities/build-script-helper.py
@@ -5,6 +5,7 @@ from __future__ import print_function
import argparse
import os
import platform
+import re
import shutil
import subprocess
import sys
@@ -50,25 +51,29 @@ def get_swiftpm_options(args):
os.path.join(args.toolchain, 'lib', 'swift', 'Block'),
]
- if 'ANDROID_DATA' in os.environ:
- swiftpm_args += [
- '-Xlinker', '-rpath', '-Xlinker', '$ORIGIN/../lib/swift/android',
- # SwiftPM will otherwise try to compile against GNU strerror_r on
- # Android and fail.
- '-Xswiftc', '-Xcc', '-Xswiftc', '-U_GNU_SOURCE',
- ]
- else:
- # Library rpath for swift, dispatch, Foundation, etc. when installing
- swiftpm_args += [
- '-Xlinker', '-rpath', '-Xlinker', '$ORIGIN/../lib/swift/linux',
- ]
+ if 'ANDROID_DATA' in os.environ or (args.cross_compile_host and re.match(
+ 'android-', args.cross_compile_host)):
+ swiftpm_args += [
+ '-Xlinker', '-landroid-spawn',
+ '-Xlinker', '-rpath', '-Xlinker', '$ORIGIN/../lib/swift/android',
+ # SwiftPM will otherwise try to compile against GNU strerror_r on
+ # Android and fail.
+ '-Xswiftc', '-Xcc', '-Xswiftc', '-U_GNU_SOURCE',
+ ]
+ elif platform.system() == 'Linux':
+ # Library rpath for swift, dispatch, Foundation, etc. when installing
+ swiftpm_args += [
+ '-Xlinker', '-rpath', '-Xlinker', '$ORIGIN/../lib/swift/linux',
+ ]
+
+ if args.cross_compile_host:
+ swiftpm_args += ['--destination', args.cross_compile_config]
return swiftpm_args
-def install(swiftpm_bin_path, toolchain):
- toolchain_bin = os.path.join(toolchain, 'bin')
- for exe in ['sourcekit-lsp']:
- install_binary(exe, swiftpm_bin_path, toolchain_bin, toolchain)
+def install(swiftpm_bin_path, prefixes, toolchain):
+ for prefix in prefixes:
+ install_binary('sourcekit-lsp', swiftpm_bin_path, os.path.join(prefix, 'bin'), toolchain)
def install_binary(exe, source_dir, install_dir, toolchain):
cmd = ['rsync', '-a', os.path.join(source_dir, exe), install_dir]
@@ -112,6 +116,8 @@ def handle_invocation(swift_exec, args):
print('Cleaning ' + args.build_path)
shutil.rmtree(args.build_path, ignore_errors=True)
+ env['SWIFT_EXEC'] = '%sc' % (swift_exec)
+
if args.action == 'build':
swiftpm('build', swift_exec, swiftpm_args, env)
elif args.action == 'test':
@@ -131,7 +137,7 @@ def handle_invocation(swift_exec, args):
bin_path = swiftpm_bin_path(swift_exec, swiftpm_args, env)
swiftpm_args += ['-Xswiftc', '-no-toolchain-stdlib-rpath']
swiftpm('build', swift_exec, swiftpm_args, env)
- install(bin_path, args.toolchain)
+ install(bin_path, args.install_prefixes if not None else [args.toolchain], args.toolchain)
else:
assert False, 'unknown action \'{}\''.format(args.action)
@@ -148,6 +154,8 @@ def main():
parser.add_argument('--sanitize', action='append', help='build using the given sanitizer(s) (address|thread|undefined)')
parser.add_argument('--sanitize-all', action='store_true', help='build using every available sanitizer in sub-directories of build path')
parser.add_argument('--verbose', '-v', action='store_true', help='enable verbose output')
+ parser.add_argument('--cross-compile-host', help='cross-compile for another host instead')
+ parser.add_argument('--cross-compile-config', help='an SPM JSON destination file containing Swift cross-compilation flags')
subparsers = parser.add_subparsers(title='subcommands', dest='action', metavar='action')
build_parser = subparsers.add_parser('build', help='build the package')
@@ -159,6 +167,7 @@ def main():
install_parser = subparsers.add_parser('install', help='build the package')
add_common_args(install_parser)
+ install_parser.add_argument('--prefix', dest='install_prefixes', nargs='*', metavar='PATHS', help="paths to install sourcekit-lsp, default: 'toolchain/bin'")
args = parser.parse_args(sys.argv[1:])
@@ -175,6 +184,11 @@ def main():
else:
swift_exec = 'swift'
+ if args.cross_compile_host and re.match('android-', args.cross_compile_host):
+ print('Cross-compiling for %s' % args.cross_compile_host)
+ elif args.cross_compile_host:
+ error("cannot cross-compile for %s" % args.cross_compile_host)
+
handle_invocation(swift_exec, args)
if args.sanitize_all:
base = args.build_path

View File

@ -0,0 +1,78 @@
diff --git a/llbuild/lib/llvm/Support/CMakeLists.txt b/llbuild/lib/llvm/Support/CMakeLists.txt
index 8e79e18..a844183 100644
--- a/llbuild/lib/llvm/Support/CMakeLists.txt
+++ b/llbuild/lib/llvm/Support/CMakeLists.txt
@@ -65,5 +65,5 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
endif()
if(${CMAKE_SYSTEM_NAME} MATCHES "Android|Darwin|Linux")
- target_link_libraries(llvmSupport PRIVATE curses)
+ target_link_libraries(llvmSupport PRIVATE android-spawn curses)
endif()
diff --git a/sourcekit-lsp/Utilities/build-script-helper.py b/sourcekit-lsp/Utilities/build-script-helper.py
index a64795c..d48876d 100755
--- a/sourcekit-lsp/Utilities/build-script-helper.py
+++ b/sourcekit-lsp/Utilities/build-script-helper.py
@@ -54,6 +54,7 @@ def get_swiftpm_options(args):
if 'ANDROID_DATA' in os.environ or (args.cross_compile_host and re.match(
'android-', args.cross_compile_host)):
swiftpm_args += [
+ '-Xlinker', '-landroid-spawn',
'-Xlinker', '-rpath', '-Xlinker', '$ORIGIN/../lib/swift/android',
# SwiftPM will otherwise try to compile against GNU strerror_r on
# Android and fail.
diff --git a/swift-corelibs-foundation/Sources/Foundation/CMakeLists.txt b/swift-corelibs-foundation/Sources/Foundation/CMakeLists.txt
index 016bf294..cd534f16 100644
--- a/swift-corelibs-foundation/Sources/Foundation/CMakeLists.txt
+++ b/swift-corelibs-foundation/Sources/Foundation/CMakeLists.txt
@@ -166,6 +166,13 @@ if(CMAKE_SYSTEM_NAME STREQUAL Windows)
$<TARGET_OBJECTS:CoreFoundationResources>)
elseif(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
target_link_options(Foundation PRIVATE "SHELL:-no-toolchain-stdlib-rpath")
+ if(${CMAKE_SYSTEM_NAME} STREQUAL Android)
+ target_link_libraries(Foundation PRIVATE android-spawn)
+ if(CMAKE_FIND_ROOT_PATH)
+ target_include_directories(Foundation PUBLIC ${CMAKE_FIND_ROOT_PATH}/usr/include)
+ target_link_directories(Foundation PUBLIC ${CMAKE_FIND_ROOT_PATH}/usr/lib)
+ endif()
+ endif()
endif()
diff --git a/swift-driver/Utilities/build-script-helper.py b/swift-driver/Utilities/build-script-helper.py
index 18f22fb0..bc2b1308 100755
--- a/swift-driver/Utilities/build-script-helper.py
+++ b/swift-driver/Utilities/build-script-helper.py
@@ -103,6 +103,7 @@ def get_swiftpm_options(args):
if 'ANDROID_DATA' in os.environ or (args.cross_compile_hosts and re.match(
'android-', args.cross_compile_hosts[0])):
swiftpm_args += [
+ '-Xlinker', '-landroid-spawn',
'-Xlinker', '-rpath', '-Xlinker', '$ORIGIN/../lib/swift/android',
# SwiftPM will otherwise try to compile against GNU strerror_r on
# Android and fail.
diff --git a/swift-tools-support-core/Sources/TSCBasic/CMakeLists.txt b/swift-tools-support-core/Sources/TSCBasic/CMakeLists.txt
index bbc43d98..bc5ee576 100644
--- a/swift-tools-support-core/Sources/TSCBasic/CMakeLists.txt
+++ b/swift-tools-support-core/Sources/TSCBasic/CMakeLists.txt
@@ -53,7 +53,7 @@ target_link_libraries(TSCBasic PUBLIC
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
if(Foundation_FOUND)
target_link_libraries(TSCBasic PUBLIC
- Foundation)
+ Foundation android-spawn)
endif()
endif()
target_link_libraries(TSCBasic PRIVATE
diff --git a/swiftpm/Utilities/bootstrap b/swiftpm/Utilities/bootstrap
index 085056de..1ded1a90 100755
--- a/swiftpm/Utilities/bootstrap
+++ b/swiftpm/Utilities/bootstrap
@@ -764,6 +764,7 @@ def get_swiftpm_flags(args):
if 'ANDROID_DATA' in os.environ or (args.cross_compile_hosts and re.match(
'android-', args.cross_compile_hosts)):
build_flags.extend(["-Xswiftc", "-Xcc", "-Xswiftc", "-U_GNU_SOURCE"])
+ build_flags.extend(["-Xlinker", "-landroid-spawn"])
if platform.system() == "OpenBSD":
build_flags.extend(["-Xcc", "-I/usr/local/include"])

View File

@ -0,0 +1,257 @@
From 0cc8bc79283a776a3ce60f2e4e476e2ec5b84b8d
From: Pavel Yaskevich <pyaskevich@apple.com>
Date: Fri, 11 Feb 2022 12:55:37 -0800
Subject: [PATCH] [CSClosure] SE-0326: Type-checker statement conditions
individually
Instead of referencing whole statement condition, break it down to
individual elements and solve them separately.
Resolves: rdar://88720312
---
include/swift/AST/ASTNode.h | 4 +--
include/swift/AST/Stmt.h | 4 +--
include/swift/AST/TypeAlignments.h | 4 +++
include/swift/Sema/ConstraintLocator.h | 2 +-
lib/AST/ASTNode.cpp | 26 ++++++---------
lib/Sema/CSClosure.cpp | 45 ++++++++++++++------------
lib/Sema/ConstraintSystem.cpp | 4 +--
7 files changed, 44 insertions(+), 45 deletions(-)
diff --git a/swift/include/swift/AST/ASTNode.h b/swift/include/swift/AST/ASTNode.h
index ac208f1bf06d7..5724ac649b0a8 100644
--- a/swift/include/swift/AST/ASTNode.h
+++ b/swift/include/swift/AST/ASTNode.h
@@ -43,11 +43,9 @@ namespace swift {
enum class PatternKind : uint8_t;
enum class StmtKind;
- using StmtCondition = llvm::MutableArrayRef<StmtConditionElement>;
-
struct ASTNode
: public llvm::PointerUnion<Expr *, Stmt *, Decl *, Pattern *, TypeRepr *,
- StmtCondition *, CaseLabelItem *> {
+ StmtConditionElement *, CaseLabelItem *> {
// Inherit the constructors from PointerUnion.
using PointerUnion::PointerUnion;
diff --git a/swift/include/swift/AST/Stmt.h b/swift/include/swift/AST/Stmt.h
index dab00742450f2..d4820894a169e 100644
--- a/swift/include/swift/AST/Stmt.h
+++ b/swift/include/swift/AST/Stmt.h
@@ -395,7 +395,7 @@ class alignas(8) PoundAvailableInfo final :
/// the "x" binding, one for the "y" binding, one for the where clause, one for
/// "z"'s binding. A simple "if" statement is represented as a single binding.
///
-class StmtConditionElement {
+class alignas(1 << PatternAlignInBits) StmtConditionElement {
/// If this is a pattern binding, it may be the first one in a declaration, in
/// which case this is the location of the var/let/case keyword. If this is
/// the second pattern (e.g. for 'y' in "var x = ..., y = ...") then this
@@ -818,7 +818,7 @@ class ForEachStmt : public LabeledStmt {
};
/// A pattern and an optional guard expression used in a 'case' statement.
-class CaseLabelItem {
+class alignas(1 << PatternAlignInBits) CaseLabelItem {
enum class Kind {
/// A normal pattern
Normal = 0,
diff --git a/swift/include/swift/AST/TypeAlignments.h b/swift/include/swift/AST/TypeAlignments.h
index 1c0f5e3b86846..911c29494ff19 100644
--- a/swift/include/swift/AST/TypeAlignments.h
+++ b/swift/include/swift/AST/TypeAlignments.h
@@ -61,6 +61,7 @@ namespace swift {
class TypeRepr;
class ValueDecl;
class CaseLabelItem;
+ class StmtConditionElement;
/// We frequently use three tag bits on all of these types.
constexpr size_t AttrAlignInBits = 3;
@@ -155,6 +156,9 @@ LLVM_DECLARE_TYPE_ALIGNMENT(swift::TypeRepr, swift::TypeReprAlignInBits)
LLVM_DECLARE_TYPE_ALIGNMENT(swift::CaseLabelItem, swift::PatternAlignInBits)
+LLVM_DECLARE_TYPE_ALIGNMENT(swift::StmtConditionElement,
+ swift::PatternAlignInBits)
+
static_assert(alignof(void*) >= 2, "pointer alignment is too small");
#endif
diff --git a/swift/include/swift/Sema/ConstraintLocator.h b/swift/include/swift/Sema/ConstraintLocator.h
index 74d4d87df9552..c1e19ab12ac4a 100644
--- a/swift/include/swift/Sema/ConstraintLocator.h
+++ b/swift/include/swift/Sema/ConstraintLocator.h
@@ -1036,7 +1036,7 @@ class LocatorPathElt::ClosureBodyElement final
if (auto *repr = node.dyn_cast<TypeRepr *>())
return repr;
- if (auto *cond = node.dyn_cast<StmtCondition *>())
+ if (auto *cond = node.dyn_cast<StmtConditionElement *>())
return cond;
if (auto *caseItem = node.dyn_cast<CaseLabelItem *>())
diff --git a/swift/lib/AST/ASTNode.cpp b/swift/lib/AST/ASTNode.cpp
index bce57fb943dee..a9b0d3ae3342d 100644
--- a/swift/lib/AST/ASTNode.cpp
+++ b/swift/lib/AST/ASTNode.cpp
@@ -35,15 +35,8 @@ SourceRange ASTNode::getSourceRange() const {
return P->getSourceRange();
if (const auto *T = this->dyn_cast<TypeRepr *>())
return T->getSourceRange();
- if (const auto *C = this->dyn_cast<StmtCondition *>()) {
- if (C->empty())
- return SourceRange();
-
- auto first = C->front();
- auto last = C->back();
-
- return {first.getStartLoc(), last.getEndLoc()};
- }
+ if (const auto *C = this->dyn_cast<StmtConditionElement *>())
+ return C->getSourceRange();
if (const auto *I = this->dyn_cast<CaseLabelItem *>()) {
return I->getSourceRange();
}
@@ -85,7 +78,7 @@ bool ASTNode::isImplicit() const {
return P->isImplicit();
if (const auto *T = this->dyn_cast<TypeRepr*>())
return false;
- if (const auto *C = this->dyn_cast<StmtCondition *>())
+ if (const auto *C = this->dyn_cast<StmtConditionElement *>())
return false;
if (const auto *I = this->dyn_cast<CaseLabelItem *>())
return false;
@@ -103,10 +96,9 @@ void ASTNode::walk(ASTWalker &Walker) {
P->walk(Walker);
else if (auto *T = this->dyn_cast<TypeRepr*>())
T->walk(Walker);
- else if (auto *C = this->dyn_cast<StmtCondition *>()) {
- for (auto &elt : *C)
- elt.walk(Walker);
- } else if (auto *I = this->dyn_cast<CaseLabelItem *>()) {
+ else if (auto *C = this->dyn_cast<StmtConditionElement *>())
+ C->walk(Walker);
+ else if (auto *I = this->dyn_cast<CaseLabelItem *>()) {
if (auto *P = I->getPattern())
P->walk(Walker);
@@ -127,9 +119,9 @@ void ASTNode::dump(raw_ostream &OS, unsigned Indent) const {
P->dump(OS, Indent);
else if (auto T = dyn_cast<TypeRepr*>())
T->print(OS);
- else if (auto C = dyn_cast<StmtCondition *>()) {
- OS.indent(Indent) << "(statement conditions)";
- } else if (auto *I = dyn_cast<CaseLabelItem *>()) {
+ else if (auto *C = dyn_cast<StmtConditionElement *>())
+ OS.indent(Indent) << "(statement condition)";
+ else if (auto *I = dyn_cast<CaseLabelItem *>()) {
OS.indent(Indent) << "(case label item)";
} else
llvm_unreachable("unsupported AST node");
diff --git a/swift/lib/Sema/CSClosure.cpp b/swift/lib/Sema/CSClosure.cpp
index 6bcd97622ebc4..6f9e59a1513e9 100644
--- a/swift/lib/Sema/CSClosure.cpp
+++ b/swift/lib/Sema/CSClosure.cpp
@@ -531,6 +531,15 @@ class ClosureConstraintGenerator
"Unsupported statement: Fallthrough");
}
+ void visitStmtCondition(LabeledConditionalStmt *S,
+ SmallVectorImpl<ElementInfo> &elements,
+ ConstraintLocator *locator) {
+ auto *condLocator =
+ cs.getConstraintLocator(locator, ConstraintLocator::Condition);
+ for (auto &condition : S->getCond())
+ elements.push_back(makeElement(&condition, condLocator));
+ }
+
void visitIfStmt(IfStmt *ifStmt) {
assert(isSupportedMultiStatementClosure() &&
"Unsupported statement: If");
@@ -538,11 +547,7 @@ class ClosureConstraintGenerator
SmallVector<ElementInfo, 4> elements;
// Condition
- {
- auto *condLoc =
- cs.getConstraintLocator(locator, ConstraintLocator::Condition);
- elements.push_back(makeElement(ifStmt->getCondPointer(), condLoc));
- }
+ visitStmtCondition(ifStmt, elements, locator);
// Then Branch
{
@@ -565,24 +570,24 @@ private:
if (!isSupportedMultiStatementClosure())
llvm_unreachable("Unsupported statement: Guard");
- createConjunction(cs,
- {makeElement(guardStmt->getCondPointer(),
- cs.getConstraintLocator(
- locator, ConstraintLocator::Condition)),
- makeElement(guardStmt->getBody(), locator)},
- locator);
+ SmallVector<ElementInfo, 4> elements;
+
+ visitStmtCondition(guardStmt, elements, locator);
+ elements.push_back(makeElement(guardStmt->getBody(), locator));
+
+ createConjunction(cs, elements, locator);
}
void visitWhileStmt(WhileStmt *whileStmt) {
if (!isSupportedMultiStatementClosure())
llvm_unreachable("Unsupported statement: Guard");
- createConjunction(cs,
- {makeElement(whileStmt->getCondPointer(),
- cs.getConstraintLocator(
- locator, ConstraintLocator::Condition)),
- makeElement(whileStmt->getBody(), locator)},
- locator);
+ SmallVector<ElementInfo, 4> elements;
+
+ visitStmtCondition(whileStmt, elements, locator);
+ elements.push_back(makeElement(whileStmt->getBody(), locator));
+
+ createConjunction(cs, elements, locator);
}
void visitDoStmt(DoStmt *doStmt) {
@@ -970,8 +975,8 @@ ConstraintSystem::simplifyClosureBodyElementConstraint(
return SolutionKind::Solved;
} else if (auto *stmt = element.dyn_cast<Stmt *>()) {
generator.visit(stmt);
- } else if (auto *cond = element.dyn_cast<StmtCondition *>()) {
- if (generateConstraints(*cond, closure))
+ } else if (auto *cond = element.dyn_cast<StmtConditionElement *>()) {
+ if (generateConstraints({*cond}, closure))
return SolutionKind::Error;
} else if (auto *pattern = element.dyn_cast<Pattern *>()) {
generator.visitPattern(pattern, context);
@@ -1571,7 +1576,7 @@ void ConjunctionElement::findReferencedVariables(
TypeVariableRefFinder refFinder(cs, locator->getAnchor(), typeVars);
- if (element.is<Decl *>() || element.is<StmtCondition *>() ||
+ if (element.is<Decl *>() || element.is<StmtConditionElement *>() ||
element.is<Expr *>() || element.isStmt(StmtKind::Return))
element.walk(refFinder);
}
diff --git a/swift/lib/Sema/ConstraintSystem.cpp b/swift/lib/Sema/ConstraintSystem.cpp
index 5523828730804..22cbe9a94e280 100644
--- a/swift/lib/Sema/ConstraintSystem.cpp
+++ b/swift/lib/Sema/ConstraintSystem.cpp
@@ -6050,8 +6050,8 @@ SourceLoc constraints::getLoc(ASTNode anchor) {
return S->getStartLoc();
} else if (auto *P = anchor.dyn_cast<Pattern *>()) {
return P->getLoc();
- } else if (auto *C = anchor.dyn_cast<StmtCondition *>()) {
- return C->front().getStartLoc();
+ } else if (auto *C = anchor.dyn_cast<StmtConditionElement *>()) {
+ return C->getStartLoc();
} else {
auto *I = anchor.get<CaseLabelItem *>();
return I->getStartLoc();

View File

@ -21,9 +21,9 @@ index fc037d6fb44..443b5e766c1 100644
--- a/swift/utils/swift_build_support/swift_build_support/host_specific_configuration.py
+++ b/swift/utils/swift_build_support/swift_build_support/host_specific_configuration.py
@@ -15,6 +15,7 @@ import sys
import sys
from argparse import ArgumentError
from . import compiler_stage
+from .cmake import CMakeOptions
from .targets import StdlibDeploymentTarget
@ -42,9 +42,9 @@ index b11313fab87..fe2e8982300 100644
--- a/swift/utils/swift_build_support/swift_build_support/products/cmark.py
+++ b/swift/utils/swift_build_support/swift_build_support/products/cmark.py
@@ -12,6 +12,8 @@
# ----------------------------------------------------------------------------
from . import cmake_product
from . import earlyswiftdriver
+from ..host_specific_configuration \
+ import HostSpecificConfiguration
@ -90,7 +90,7 @@ index 05966defe28..133761ba91d 100644
- options += '-DCMAKE_SYSTEM_PROCESSOR=%s ' % (args.android_arch if not
- args.android_arch == 'armv7'
- else 'armv7-a')
- options += '-DCMAKE_ANDROID_STANDALONE_TOOLCHAIN:PATH=%s' % (args.android_ndk)
- options += '-DCMAKE_ANDROID_NDK:PATH=%s' % (args.android_ndk)
+ options = cmake.CMakeOptions()
+ options.define('CMAKE_SYSTEM_NAME', 'Android')
+ options.define('CMAKE_SYSTEM_VERSION' , args.android_api_level)

View File

@ -1,3 +1,49 @@
diff --git a/llvm-project/clang/runtime/CMakeLists.txt b/llvm-project/clang/runtime/CMakeLists.txt
index 61b1c60bf590..5b0d10a67699 100644
--- a/llvm-project/clang/runtime/CMakeLists.txt
+++ b/llvm-project/clang/runtime/CMakeLists.txt
@@ -75,6 +75,7 @@ if(LLVM_BUILD_EXTERNAL_COMPILER_RT AND EXISTS ${COMPILER_RT_SRC_ROOT}/)
CMAKE_ARGS ${CLANG_COMPILER_RT_CMAKE_ARGS}
-DCMAKE_C_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang
-DCMAKE_CXX_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++
+ -DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY
-DCMAKE_ASM_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
@@ -84,6 +85,7 @@ if(LLVM_BUILD_EXTERNAL_COMPILER_RT AND EXISTS ${COMPILER_RT_SRC_ROOT}/)
-DCOMPILER_RT_EXEC_OUTPUT_DIR=${LLVM_RUNTIME_OUTPUT_INTDIR}
-DCOMPILER_RT_INSTALL_PATH:STRING=lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}
-DCOMPILER_RT_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
+ -DCOMPILER_RT_USE_BUILTINS_LIBRARY=ON
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
-DLLVM_LIBDIR_SUFFIX=${LLVM_LIBDIR_SUFFIX}
-DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_RUNTIME_OUTPUT_INTDIR}
diff --git a/llvm-project/clang/tools/IndexStore/CMakeLists.txt b/llvm-project/clang/tools/IndexStore/CMakeLists.txt
index 1bcfc0734785..ddb77c91b22d 100644
--- a/llvm-project/clang/tools/IndexStore/CMakeLists.txt
+++ b/llvm-project/clang/tools/IndexStore/CMakeLists.txt
@@ -65,7 +65,7 @@ if (LLVM_INSTALL_TOOLCHAIN_ONLY)
endif()
endif()
-set(INDEXSTORE_HEADERS_INSTALL_DESTINATION "local/include")
+set(INDEXSTORE_HEADERS_INSTALL_DESTINATION "include")
install(DIRECTORY ../../include/indexstore
COMPONENT IndexStore
diff --git a/llvm-project/compiler-rt/cmake/Modules/HandleCompilerRT.cmake b/llvm-project/compiler-rt/cmake/Modules/HandleCompilerRT.cmake
index ac9e0871489d..b495cbfb5c2e 100644
--- a/llvm-project/compiler-rt/cmake/Modules/HandleCompilerRT.cmake
+++ b/llvm-project/compiler-rt/cmake/Modules/HandleCompilerRT.cmake
@@ -31,7 +31,7 @@ function(find_compiler_rt_library name target variable)
# If the cache variable is not defined, invoke clang and then
# set it with cache_compiler_rt_library.
set(CLANG_COMMAND ${CMAKE_CXX_COMPILER} ${SANITIZER_COMMON_FLAGS}
- "--rtlib=compiler-rt" "-print-libgcc-file-name")
+ "--rtlib=compiler-rt" "-print-libgcc-file-name" "-resource-dir=$ENV{PREFIX}/lib/clang/$ENV{TERMUX_CLANG_VERSION}/")
if(target)
list(APPEND CLANG_COMMAND "--target=${target}")
endif()
diff --git a/swift/CMakeLists.txt b/swift/CMakeLists.txt
index b7503ecdd6..c643c2c9a5 100644
--- a/swift/CMakeLists.txt
@ -21,6 +67,38 @@ index b7503ecdd6..c643c2c9a5 100644
include(Libdispatch)
endif()
diff --git a/swift/cmake/modules/AddSwift.cmake b/swift/cmake/modules/AddSwift.cmake
index a448bcb23c4..0ddbac17a52 100644
--- a/swift/cmake/modules/AddSwift.cmake
+++ b/swift/cmake/modules/AddSwift.cmake
@@ -706,7 +706,7 @@
elseif(${LIBSWIFT_BUILD_MODE} STREQUAL "CROSSCOMPILE")
set(sdk_option "-sdk" "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${SWIFT_HOST_VARIANT_ARCH}_PATH}")
get_filename_component(swift_exec_bin_dir ${ALS_SWIFT_EXEC} DIRECTORY)
- set(sdk_option ${sdk_option} "-resource-dir" "${swift_exec_bin_dir}/../lib/swift")
+ set(sdk_option ${sdk_option} "-resource-dir" "${SWIFT_BINARY_DIR}/lib/swift")
endif()
get_versioned_target_triple(target ${SWIFT_HOST_VARIANT_SDK}
${SWIFT_HOST_VARIANT_ARCH} "${deployment_version}")
@@ -758,6 +758,9 @@
add_library(${name} STATIC ${all_obj_files})
set_target_properties(${name} PROPERTIES LINKER_LANGUAGE CXX)
set_property(GLOBAL APPEND PROPERTY SWIFT_BUILDTREE_EXPORTS ${name})
+ if(${LIBSWIFT_BUILD_MODE} STREQUAL "CROSSCOMPILE")
+ add_dependencies(${name} swift-stdlib-android-${SWIFT_HOST_VARIANT_ARCH})
+ endif()
endfunction()
macro(add_swift_tool_subdirectory name)
@@ -922,7 +923,7 @@ function(add_swift_host_tool executable)
# installed host toolchain.
get_filename_component(swift_bin_dir ${SWIFT_EXEC_FOR_LIBSWIFT} DIRECTORY)
get_filename_component(swift_dir ${swift_bin_dir} DIRECTORY)
- set(host_lib_dir "${swift_dir}/lib/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}")
+ set(host_lib_dir "${SWIFT_BINARY_DIR}/lib/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}")
target_link_libraries(${executable} PRIVATE ${swiftrt})
target_link_libraries(${executable} PRIVATE "swiftCore")
diff --git a/swift/localization/CMakeLists.txt b/swift/localization/CMakeLists.txt
index 07a3585a66c..461a98b6856 100644
--- a/swift/localization/CMakeLists.txt
@ -35,6 +113,19 @@ index 07a3585a66c..461a98b6856 100644
PATTERN "*.yaml"
)
+endif()
diff --git a/swift/stdlib/cmake/modules/SwiftSource.cmake b/swift/stdlib/cmake/modules/SwiftSource.cmake
index 4bc312f7f89..d71f6408d9f 100644
--- a/swift/stdlib/cmake/modules/SwiftSource.cmake
+++ b/swift/stdlib/cmake/modules/SwiftSource.cmake
@@ -708,7 +708,7 @@ function(_compile_swift_files
endif()
set(swift_compiler_tool_dep)
- if(SWIFT_INCLUDE_TOOLS)
+ if(SWIFT_INCLUDE_TOOLS AND NOT ${LIBSWIFT_BUILD_MODE} STREQUAL "CROSSCOMPILE")
# Depend on the binary itself, in addition to the symlink.
set(swift_compiler_tool_dep "swift-frontend${target_suffix}")
endif()
diff --git a/swift/stdlib/public/Concurrency/CMakeLists.txt b/swift/stdlib/public/Concurrency/CMakeLists.txt
index 3313f56c8a6..59804ff6228 100644
--- a/swift/stdlib/public/Concurrency/CMakeLists.txt
@ -48,8 +139,8 @@ index 3313f56c8a6..59804ff6228 100644
+ #list(APPEND swift_concurrency_link_libraries
+ # dispatch)
endif()
endif()
elseif("${SWIFT_CONCURRENCY_GLOBAL_EXECUTOR}" STREQUAL "singlethreaded" OR
"${SWIFT_CONCURRENCY_GLOBAL_EXECUTOR}" STREQUAL "hooked")
@@ -120,6 +120,7 @@ add_swift_target_library(swift_Concurrency ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} I
SWIFT_MODULE_DEPENDS_WINDOWS CRT
@ -59,42 +150,18 @@ index 3313f56c8a6..59804ff6228 100644
C_COMPILE_FLAGS
-Dswift_Concurrency_EXPORTS ${SWIFT_RUNTIME_CONCURRENCY_C_FLAGS}
diff --git a/swift/stdlib/public/Platform/CMakeLists.txt b/swift/stdlib/public/Platform/CMakeLists.txt
index 8ded40c5791..c811000b1d1 100644
index f958d4ce899..ac6d7248606 100644
--- a/swift/stdlib/public/Platform/CMakeLists.txt
+++ b/swift/stdlib/public/Platform/CMakeLists.txt
@@ -97,6 +97,7 @@ foreach(sdk ${SWIFT_SDKS})
OUTPUT "${glibc_modulemap_out}"
FLAGS
"-DCMAKE_SDK=${sdk}"
+ "-DTERMUX_INCLUDE_PATH=${SWIFT_ANDROID_NATIVE_SYSROOT}/usr/include"
"-DGLIBC_INCLUDE_PATH=${SWIFT_SDK_${sdk}_ARCH_${arch}_LIBC_INCLUDE_DIRECTORY}"
"-DGLIBC_ARCH_INCLUDE_PATH=${SWIFT_SDK_${sdk}_ARCH_${arch}_LIBC_ARCHITECTURE_INCLUDE_DIRECTORY}")
@@ -106,18 +107,19 @@ foreach(sdk ${SWIFT_SDKS})
# with its own native sysroot, create a native modulemap without a sysroot
# prefix. This is the one we'll install instead.
if(NOT "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${arch}_PATH}" STREQUAL "/" AND
- NOT (${sdk} STREQUAL ANDROID AND NOT "${SWIFT_ANDROID_NATIVE_SYSROOT}" STREQUAL ""))
+ (${sdk} STREQUAL ANDROID AND NOT "${SWIFT_ANDROID_NATIVE_SYSROOT}" STREQUAL ""))
set(glibc_sysroot_relative_modulemap_out "${module_dir}/sysroot-relative-modulemaps/glibc.modulemap")
- string(REPLACE "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${arch}_PATH}"
- "" absolute_libc_include_path "${SWIFT_SDK_${sdk}_ARCH_${arch}_LIBC_INCLUDE_DIRECTORY}")
- string(REPLACE "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${arch}_PATH}"
- "" absolute_libc_arch_include_path ${SWIFT_SDK_${sdk}_ARCH_${arch}_LIBC_ARCHITECTURE_INCLUDE_DIRECTORY})
+ string(REPLACE "${SWIFT_SDK_${sdk}_ARCH_${arch}_PATH}/usr"
+ "${SWIFT_ANDROID_NATIVE_SYSROOT}/usr" absolute_libc_include_path "${SWIFT_SDK_${sdk}_ARCH_${arch}_LIBC_INCLUDE_DIRECTORY}")
+ string(REPLACE "${SWIFT_SDK_${sdk}_ARCH_${arch}_PATH}/usr"
+ "${SWIFT_ANDROID_NATIVE_SYSROOT}/usr" absolute_libc_arch_include_path ${SWIFT_SDK_${sdk}_ARCH_${arch}_LIBC_ARCHITECTURE_INCLUDE_DIRECTORY})
handle_gyb_source_single(glibc_modulemap_native_target
SOURCE "${glibc_modulemap_source}"
OUTPUT "${glibc_sysroot_relative_modulemap_out}"
FLAGS "-DCMAKE_SDK=${sdk}"
+ "-DTERMUX_INCLUDE_PATH=${SWIFT_ANDROID_NATIVE_SYSROOT}/usr/include"
"-DGLIBC_INCLUDE_PATH=${absolute_libc_include_path}"
"-DGLIBC_ARCH_INCLUDE_PATH=${absolute_libc_arch_include_path}")
@@ -92,7 +92,7 @@ add_swift_target_library(swiftGlibc ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_O
${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}
${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
${swift_platform_compile_flags}
- LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
+ LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS};-landroid-posix-semaphore"
TARGET_SDKS "${swiftGlibc_target_sdks}"
INSTALL_IN_COMPONENT sdk-overlay
DEPENDS glibc_modulemap)
diff --git a/swift/stdlib/public/SwiftShims/CMakeLists.txt b/swift/stdlib/public/SwiftShims/CMakeLists.txt
index 23ac72bcda5..23aecfc9bc5 100644
--- a/swift/stdlib/public/SwiftShims/CMakeLists.txt
@ -152,3 +219,37 @@ index 42dda212164..2338df9072a 100644
target_link_libraries(libSwiftSyntaxParser PRIVATE
swiftParse)
set_target_properties(libSwiftSyntaxParser
diff --git a/swift-corelibs-xctest/CMakeLists.txt b/swift-corelibs-xctest/CMakeLists.txt
index 531e7c0..589930f 100644
--- a/swift-corelibs-xctest/CMakeLists.txt
+++ b/swift-corelibs-xctest/CMakeLists.txt
@@ -58,6 +58,7 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
Foundation)
if(NOT CMAKE_SYSTEM_NAME STREQUAL Windows)
target_link_options(XCTest PRIVATE "SHELL:-no-toolchain-stdlib-rpath")
+ set_target_properties(XCTest PROPERTIES INSTALL_RPATH "$ORIGIN")
endif()
endif()
set_target_properties(XCTest PROPERTIES
diff --git a/swift-crypto/Sources/CCryptoBoringSSL/CMakeLists.txt b/swift-crypto/Sources/CCryptoBoringSSL/CMakeLists.txt
index 1a890d6..639126c 100644
--- a/swift-crypto/Sources/CCryptoBoringSSL/CMakeLists.txt
+++ b/swift-crypto/Sources/CCryptoBoringSSL/CMakeLists.txt
@@ -337,7 +337,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL Darwin AND CMAKE_SYSTEM_PROCESSOR MATCHES "amd64|x
crypto/fipsmodule/vpaes-x86_64.mac.x86_64.S
crypto/fipsmodule/x86_64-mont.mac.x86_64.S
crypto/fipsmodule/x86_64-mont5.mac.x86_64.S)
-elseif(CMAKE_SYSTEM_NAME STREQUAL Linux AND CMAKE_SYSTEM_PROCESSOR MATCHES "amd64|x86_64")
+elseif(CMAKE_SYSTEM_NAME MATCHES "Linux|Android" AND CMAKE_SYSTEM_PROCESSOR MATCHES "amd64|x86_64")
target_sources(CCryptoBoringSSL PRIVATE
crypto/chacha/chacha-x86_64.linux.x86_64.S
crypto/cipher_extra/aes128gcmsiv-x86_64.linux.x86_64.S
@@ -368,7 +368,7 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin AND CMAKE_SYSTEM_PROCESSOR MATCHES "arm
crypto/fipsmodule/sha256-armv8.ios.aarch64.S
crypto/fipsmodule/sha512-armv8.ios.aarch64.S
crypto/fipsmodule/vpaes-armv8.ios.aarch64.S)
-elseif(CMAKE_SYSTEM_NAME STREQUAL Linux AND CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|aarch64")
+elseif(CMAKE_SYSTEM_NAME MATCHES "Linux|Android" AND CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|aarch64")
target_sources(CCryptoBoringSSL PRIVATE
crypto/chacha/chacha-armv8.linux.aarch64.S
crypto/fipsmodule/aesv8-armx64.linux.aarch64.S

View File

@ -3,7 +3,7 @@ index fe2e8982300..b413d47b843 100644
--- a/swift/utils/swift_build_support/swift_build_support/products/cmark.py
+++ b/swift/utils/swift_build_support/swift_build_support/products/cmark.py
@@ -14,6 +14,7 @@ from . import cmake_product
from . import cmake_product
from . import earlyswiftdriver
from ..host_specific_configuration \
import HostSpecificConfiguration
+import os

View File

@ -1,8 +1,22 @@
From 7b2256f97b59192046eab312838f467def880605
Date: Sun, 9 Jan 2022 21:45:13 +0530
Subject: [PATCH] [android] Move the string and other tags in pointers to the
second byte because Android enabled memory tagging
Starting with Android 11, AArch64 placed a tag in the top byte of pointers to
allocations, which has been slowly rolling out to more devices and collides
with Swift's tags. Moving these tags to the second byte works around this
problem.
---
lib/IRGen/MetadataRequest.cpp | 28 ++++++++++--
lib/IRGen/SwiftTargetInfo.cpp | 15 +++++--
stdlib/public/SwiftShims/System.h | 9 ++++
diff --git a/swift/lib/IRGen/MetadataRequest.cpp b/swift/lib/IRGen/MetadataRequest.cpp
index 0a83d8bb6ec..57af3ee003a 100644
index 370b5bab779e2..d96e7b0d0f576 100644
--- a/swift/lib/IRGen/MetadataRequest.cpp
+++ b/swift/lib/IRGen/MetadataRequest.cpp
@@ -2677,9 +2677,16 @@ emitMetadataAccessByMangledName(IRGenFunction &IGF, CanType type,
@@ -2681,9 +2681,16 @@ emitMetadataAccessByMangledName(IRGenFunction &IGF, CanType type,
unsigned mangledStringSize;
std::tie(mangledString, mangledStringSize) =
IGM.getTypeRef(type, CanGenericSignature(), MangledTypeRefRole::Metadata);
@ -22,7 +36,7 @@ index 0a83d8bb6ec..57af3ee003a 100644
// Get or create the cache variable if necessary.
auto cache = IGM.getAddrOfTypeMetadataDemanglingCacheVariable(type,
@@ -2749,6 +2756,21 @@ emitMetadataAccessByMangledName(IRGenFunction &IGF, CanType type,
@@ -2753,6 +2760,21 @@ emitMetadataAccessByMangledName(IRGenFunction &IGF, CanType type,
auto contBB = subIGF.createBasicBlock("");
llvm::Value *comparison = subIGF.Builder.CreateICmpSLT(load,
llvm::ConstantInt::get(IGM.Int64Ty, 0));
@ -45,34 +59,43 @@ index 0a83d8bb6ec..57af3ee003a 100644
llvm::ConstantInt::get(IGM.Int1Ty, 0));
subIGF.Builder.CreateCondBr(comparison, isUnfilledBB, contBB);
diff --git a/swift/lib/IRGen/SwiftTargetInfo.cpp b/swift/lib/IRGen/SwiftTargetInfo.cpp
index 97b70d6d75c0a..b2b2e70d3434e 100644
--- a/swift/lib/IRGen/SwiftTargetInfo.cpp
+++ b/swift/lib/IRGen/SwiftTargetInfo.cpp
@@ -36,8 +36,12 @@ static void setToMask(SpareBitVector &bits, unsigned size, uint64_t mask) {
@@ -36,10 +36,17 @@ static void setToMask(SpareBitVector &bits, unsigned size, uint64_t mask) {
/// Configures target-specific information for arm64 platforms.
static void configureARM64(IRGenModule &IGM, const llvm::Triple &triple,
SwiftTargetInfo &target) {
- setToMask(target.PointerSpareBits, 64,
- SWIFT_ABI_ARM64_SWIFT_SPARE_BITS_MASK);
+ if (triple.isAndroid())
- setToMask(target.ObjCPointerReservedBits, 64,
- SWIFT_ABI_ARM64_OBJC_RESERVED_BITS_MASK);
+ if (triple.isAndroid()) {
+ setToMask(target.PointerSpareBits, 64,
+ SWIFT_ABI_ANDROID_ARM64_SWIFT_SPARE_BITS_MASK);
+ else
+ setToMask(target.ObjCPointerReservedBits, 64,
+ SWIFT_ABI_ANDROID_ARM64_OBJC_RESERVED_BITS_MASK);
+ } else {
+ setToMask(target.PointerSpareBits, 64,
+ SWIFT_ABI_ARM64_SWIFT_SPARE_BITS_MASK);
setToMask(target.ObjCPointerReservedBits, 64,
SWIFT_ABI_ARM64_OBJC_RESERVED_BITS_MASK);
+ setToMask(target.ObjCPointerReservedBits, 64,
+ SWIFT_ABI_ARM64_OBJC_RESERVED_BITS_MASK);
+ }
setToMask(target.IsObjCPointerBit, 64, SWIFT_ABI_ARM64_IS_OBJC_BIT);
if (triple.isOSDarwin()) {
diff --git a/swift/stdlib/public/SwiftShims/System.h b/swift/stdlib/public/SwiftShims/System.h
index 8fe54f6bda..a70acfd7be 100644
index 978ec41f1eafb..7ec3961fa0fc3 100644
--- a/swift/stdlib/public/SwiftShims/System.h
+++ b/swift/stdlib/public/SwiftShims/System.h
@@ -152,10 +152,18 @@
@@ -152,10 +152,19 @@
/// Darwin reserves the low 4GB of address space.
#define SWIFT_ABI_DARWIN_ARM64_LEAST_VALID_POINTER 0x100000000ULL
+// Android AArch64 reserves the top byte for pointer tagging since Android 11,
+// so shift this tag to the second byte.
+// so shift the spare bits tag to the second byte and zero the ObjC tag.
+#define SWIFT_ABI_ANDROID_ARM64_SWIFT_SPARE_BITS_MASK 0x00F0000000000007ULL
+#define SWIFT_ABI_ANDROID_ARM64_OBJC_RESERVED_BITS_MASK 0x0000000000000000ULL
+
+#if defined(__ANDROID__) && defined(__aarch64__)
+#define SWIFT_ABI_ARM64_SWIFT_SPARE_BITS_MASK SWIFT_ABI_ANDROID_ARM64_SWIFT_SPARE_BITS_MASK

View File

@ -1,15 +0,0 @@
diff --git a/swift-corelibs-foundation/Sources/Foundation/CMakeLists.txt b/swift-corelibs-foundation/Sources/Foundation/CMakeLists.txt
index 016bf294..cd534f16 100644
--- a/swift-corelibs-foundation/Sources/Foundation/CMakeLists.txt
+++ b/swift-corelibs-foundation/Sources/Foundation/CMakeLists.txt
@@ -166,6 +166,10 @@ if(CMAKE_SYSTEM_NAME STREQUAL Windows)
$<TARGET_OBJECTS:CoreFoundationResources>)
elseif(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
target_link_options(Foundation PRIVATE "SHELL:-no-toolchain-stdlib-rpath")
+ if(${CMAKE_SYSTEM_NAME} STREQUAL Android)
+ target_link_libraries(Foundation PRIVATE android-spawn)
+ target_link_directories(Foundation PUBLIC ${CMAKE_FIND_ROOT_PATH}/usr/lib)
+ endif()
endif()

View File

@ -1,36 +0,0 @@
commit 729e25d92d05a8c4a8136e831ec6123bbf7f2654
Author: Evan Wilde <ewilde@apple.com>
Date: Thu Aug 19 11:57:34 2021 -0700
Removing unused refcount variable
The rebranch branch is failing to build due to an unused refcount
variable in runtime.c. The variable is only used by an os_assert and
nowhere else. I've removed it and instead put the check directly in the
assert.
diff --git a/swift-corelibs-libdispatch/src/BlocksRuntime/runtime.c b/swift-corelibs-libdispatch/src/BlocksRuntime/runtime.c
index bfec1a0..4b7d4bf 100644
--- a/swift-corelibs-libdispatch/src/BlocksRuntime/runtime.c
+++ b/swift-corelibs-libdispatch/src/BlocksRuntime/runtime.c
@@ -468,18 +468,16 @@ static void _Block_byref_assign_copy(void *dest, const void *arg, const int flag
// Old compiler SPI
static void _Block_byref_release(const void *arg) {
struct Block_byref *byref = (struct Block_byref *)arg;
- int32_t refcount;
// dereference the forwarding pointer since the compiler isn't doing this anymore (ever?)
byref = byref->forwarding;
-
+
// To support C++ destructors under GC we arrange for there to be a finalizer for this
// by using an isa that directs the code to a finalizer that calls the byref_destroy method.
if ((byref->flags & BLOCK_BYREF_NEEDS_FREE) == 0) {
return; // stack or GC or global
}
- refcount = byref->flags & BLOCK_REFCOUNT_MASK;
- os_assert(refcount);
+ os_assert(byref->flags & BLOCK_REFCOUNT_MASK);
if (latching_decr_int_should_deallocate(&byref->flags)) {
if (byref->flags & BLOCK_BYREF_HAS_COPY_DISPOSE) {
struct Block_byref_2 *byref2 = (struct Block_byref_2 *)(byref+1);

View File

@ -1,12 +0,0 @@
diff --git a/swift-corelibs-xctest/CMakeLists.txt b/swift-corelibs-xctest/CMakeLists.txt
index 531e7c0..589930f 100644
--- a/swift-corelibs-xctest/CMakeLists.txt
+++ b/swift-corelibs-xctest/CMakeLists.txt
@@ -58,6 +58,7 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
Foundation)
if(NOT CMAKE_SYSTEM_NAME STREQUAL Windows)
target_link_options(XCTest PRIVATE "SHELL:-no-toolchain-stdlib-rpath")
+ set_target_properties(XCTest PROPERTIES INSTALL_RPATH "$ORIGIN")
endif()
endif()
set_target_properties(XCTest PROPERTIES

View File

@ -0,0 +1,86 @@
From 3e7717673dcbb73b41a26ae5f70fd48620cca072
Date: Mon, 20 Dec 2021 20:47:55 +0530
Subject: [PATCH] [build] Add a flag that allows disabling appending the host
target's name to the install-destdir for a cross-compiled toolchain
This is useful if you're cross-compiling the toolchain for a single host and don't
want your specified install path modified.
---
utils/build-script-impl | 7 +++++--
utils/build_swift/build_swift/driver_arguments.py | 6 ++++++
.../swift_build_support/build_script_invocation.py | 2 ++
.../swift_build_support/products/product.py | 6 ++++--
5 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/swift/utils/build-script-impl b/swift/utils/build-script-impl
index a9a77e2fb370d..6d0709d82de7e 100755
--- a/swift/utils/build-script-impl
+++ b/swift/utils/build-script-impl
@@ -249,6 +249,7 @@ KNOWN_SETTINGS=(
cross-compile-with-host-tools "" "set to use the clang we build for the host to then build the cross-compile hosts"
cross-compile-install-prefixes "" "semicolon-separated list of install prefixes to use for the cross-compiled hosts. The list expands, so if there are more cross-compile hosts than prefixes, unmatched hosts use the last prefix in the list"
cross-compile-deps-path "" "path for CMake to look for cross-compiled library dependencies, such as libXML2"
+ cross-compile-append-host-target-to-destdir "1" "turns on appending the host target name of each cross-compiled toolchain to its install-destdir, to keep them separate from the natively-built toolchain"
skip-merge-lipo-cross-compile-tools "" "set to skip running merge-lipo after installing cross-compiled host Swift tools"
coverage-db "" "If set, coverage database to use when prioritizing testing"
skip-local-host-install "" "If we are cross-compiling multiple targets, skip an install pass locally if the hosts match"
@@ -1133,8 +1134,10 @@ function get_host_install_destdir() {
if [[ $(should_include_host_in_lipo ${host}) ]]; then
# If this is one of the hosts we should lipo, install in to a temporary subdirectory.
local host_install_destdir="${BUILD_DIR}/intermediate-install/${host}"
- elif [[ "${host}" == "merged-hosts" ]]; then
- # This assumes that all hosts are merged to the lipo.
+ elif [[ "${host}" == "merged-hosts" ]] ||
+ [[ "$(true_false ${CROSS_COMPILE_APPEND_HOST_TARGET_TO_DESTDIR})" == "FALSE" ]]; then
+ # This assumes that all hosts are merged to the lipo, or the build
+ # was told not to append anything.
local host_install_destdir="${INSTALL_DESTDIR}"
else
local host_install_destdir="${INSTALL_DESTDIR}/${host}"
diff --git a/swift/utils/build_swift/build_swift/driver_arguments.py b/swift/utils/build_swift/build_swift/driver_arguments.py
index e10ef74dcefc1..ecbaa4a9dd5f4 100644
--- a/swift/utils/build_swift/build_swift/driver_arguments.py
+++ b/swift/utils/build_swift/build_swift/driver_arguments.py
@@ -568,6 +568,12 @@ def create_argument_parser():
'library dependencies of the corelibs and other Swift repos, '
'such as the libcurl dependency of FoundationNetworking')
+ option('--cross-compile-append-host-target-to-destdir', toggle_true,
+ default=True,
+ help="Append each cross-compilation host target's name as a subdirectory "
+ "for each cross-compiled toolchain's destdir, useful when building "
+ "multiple toolchains and can be disabled if only cross-compiling one.")
+
option('--stdlib-deployment-targets', store,
type=argparse.ShellSplitType(),
default=None,
diff --git a/swift/utils/swift_build_support/swift_build_support/build_script_invocation.py b/swift/utils/swift_build_support/swift_build_support/build_script_invocation.py
index d6faa0a7ba6c9..3ae3002f5d906 100644
--- a/swift/utils/swift_build_support/swift_build_support/build_script_invocation.py
+++ b/swift/utils/swift_build_support/swift_build_support/build_script_invocation.py
@@ -124,6 +124,8 @@ def convert_to_impl_arguments(self):
"--lldb-assertions", str(
args.lldb_assertions).lower(),
"--cmake-generator", args.cmake_generator,
+ "--cross-compile-append-host-target-to-destdir", str(
+ args.cross_compile_append_host_target_to_destdir).lower(),
"--build-jobs", str(args.build_jobs),
"--common-cmake-options=%s" % ' '.join(
pipes.quote(opt) for opt in cmake.common_options()),
diff --git a/swift/utils/swift_build_support/swift_build_support/products/product.py b/swift/utils/swift_build_support/swift_build_support/products/product.py
index 2f02322ba1d92..9fc258789639b 100644
--- a/swift/utils/swift_build_support/swift_build_support/products/product.py
+++ b/swift/utils/swift_build_support/swift_build_support/products/product.py
@@ -230,8 +230,10 @@ def host_install_destdir(self, host_target):
# install in to a temporary subdirectory.
return '%s/intermediate-install/%s' % \
(os.path.dirname(self.build_dir), host_target)
- elif host_target == "merged-hosts":
- # This assumes that all hosts are merged to the lipo.
+ elif host_target == "merged-hosts" or \
+ not self.args.cross_compile_append_host_target_to_destdir:
+ # This assumes that all hosts are merged to the lipo, or the build
+ # was told not to append anything.
return self.args.install_destdir
else:
return '%s/%s' % (self.args.install_destdir, host_target)

View File

@ -0,0 +1,27 @@
diff --git a/swift-driver/Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift b/swift-driver/Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift
index 06a29d8..5cbfddd 100644
--- a/swift-driver/Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift
+++ b/swift-driver/Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift
@@ -133,8 +137,7 @@ extension GenericUnixToolchain {
isShared: hasRuntimeArgs
)
- if hasRuntimeArgs && targetTriple.environment != .android &&
- toolchainStdlibRpath {
+ if hasRuntimeArgs && toolchainStdlibRpath {
// FIXME: We probably shouldn't be adding an rpath here unless we know
// ahead of time the standard library won't be copied.
for path in runtimePaths {
diff --git a/swift/lib/Driver/UnixToolChains.cpp b/swift/lib/Driver/UnixToolChains.cpp
index bdc63d1ca72..971e5ded1e2 100644
--- a/swift/lib/Driver/UnixToolChains.cpp
+++ b/swift/lib/Driver/UnixToolChains.cpp
@@ -133,7 +133,7 @@ bool toolchains::GenericUnix::addRuntimeRPath(const llvm::Triple &T,
// copied into the bundle.
return Args.hasFlag(options::OPT_toolchain_stdlib_rpath,
options::OPT_no_toolchain_stdlib_rpath,
- !T.isAndroid());
+ true);
}
ToolChain::InvocationInfo

View File

@ -1,116 +0,0 @@
diff --git a/swift-driver/Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift b/swift-driver/Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift
index 06a29d8..5cbfddd 100644
--- a/swift-driver/Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift
+++ b/swift-driver/Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift
@@ -14,6 +14,7 @@ import SwiftOptions
extension GenericUnixToolchain {
private func defaultLinker(for targetTriple: Triple) -> String? {
+ if targetTriple.environment == .android { return "lld" }
switch targetTriple.arch {
case .arm, .aarch64, .armeb, .thumb, .thumbeb:
// BFD linker has issues wrt relocation of the protocol conformance
@@ -133,8 +137,7 @@ extension GenericUnixToolchain {
isShared: hasRuntimeArgs
)
- if hasRuntimeArgs && targetTriple.environment != .android &&
- toolchainStdlibRpath {
+ if hasRuntimeArgs && toolchainStdlibRpath {
// FIXME: We probably shouldn't be adding an rpath here unless we know
// ahead of time the standard library won't be copied.
for path in runtimePaths {
diff --git a/swift-driver/Utilities/build-script-helper.py b/swift-driver/Utilities/build-script-helper.py
index e986475..83916c3 100755
--- a/swift-driver/Utilities/build-script-helper.py
+++ b/swift-driver/Utilities/build-script-helper.py
@@ -11,6 +11,7 @@ import shutil
import subprocess
import sys
import errno
+import re
if platform.system() == 'Darwin':
shared_lib_ext = '.dylib'
@@ -96,8 +97,13 @@ def get_swiftpm_options(args):
os.path.join(args.toolchain, 'lib', 'swift', 'Block'),
]
- if 'ANDROID_DATA' in os.environ:
+ if args.cross_compile_hosts:
+ swiftpm_args += [ '--destination', args.cross_compile_config ]
+
+ if 'ANDROID_DATA' in os.environ or (args.cross_compile_hosts and re.match(
+ 'android-', args.cross_compile_hosts[0])):
swiftpm_args += [
+ '-Xlinker', '-landroid-spawn',
'-Xlinker', '-rpath', '-Xlinker', '$ORIGIN/../lib/swift/android',
# SwiftPM will otherwise try to compile against GNU strerror_r on
# Android and fail.
@@ -177,8 +185,13 @@ def handle_invocation(args):
if args.sysroot:
env['SDKROOT'] = args.sysroot
+ env['SWIFT_EXEC'] = '%sc' % (swift_exec)
+
if args.action == 'build':
- build_using_cmake(args, toolchain_bin, args.build_path, targets)
+ if args.cross_compile_hosts and not re.match('-macosx', args.cross_compile_hosts[0]):
+ swiftpm('build', swift_exec, swiftpm_args, env)
+ else:
+ build_using_cmake(args, toolchain_bin, args.build_path, targets)
elif args.action == 'clean':
print('Cleaning ' + args.build_path)
@@ -188,7 +201,6 @@ def handle_invocation(args):
tool_path = os.path.join(toolchain_bin, tool)
if os.path.exists(tool_path):
env['SWIFT_DRIVER_' + tool.upper().replace('-','_') + '_EXEC'] = '%s' % (tool_path)
- env['SWIFT_EXEC'] = '%sc' % (swift_exec)
test_args = swiftpm_args
test_args += ['-Xswiftc', '-enable-testing']
if should_test_parallel():
@@ -205,16 +217,17 @@ def handle_invocation(args):
else:
bin_path = swiftpm_bin_path(swift_exec, swiftpm_args, env)
swiftpm('build', swift_exec, swiftpm_args, env)
- non_darwin_install(bin_path, args.toolchain, args.verbose)
+ non_darwin_install(args, bin_path)
else:
assert False, 'unknown action \'{}\''.format(args.action)
# Installation flow for non-darwin platforms, only copies over swift-driver and swift-help
# TODO: Unify CMake-based installation flow used on Darwin with this
-def non_darwin_install(swiftpm_bin_path, toolchain, verbose):
- toolchain_bin = os.path.join(toolchain, 'bin')
- for exe in executables_to_install:
- install_binary(exe, swiftpm_bin_path, toolchain_bin, verbose)
+def non_darwin_install(args, swiftpm_bin_path):
+ for prefix in args.install_prefixes:
+ prefix_bin = os.path.join(prefix, 'bin')
+ for exe in executables_to_install:
+ install_binary(exe, swiftpm_bin_path, prefix_bin, args.verbose)
def install(args, build_dir, targets):
# Construct and install universal swift-driver, swift-help executables
@@ -581,6 +594,10 @@ def main():
nargs='*',
help='List of cross compile hosts targets.',
default=[])
+ parser.add_argument(
+ '--cross-compile-config',
+ metavar='PATH',
+ help="A JSON SPM config file with Swift flags for cross-compilation")
parser.add_argument('--ninja-bin', metavar='PATH', help='ninja binary to use for testing')
parser.add_argument('--cmake-bin', metavar='PATH', help='cmake binary to use for building')
parser.add_argument('--build-path', metavar='PATH', default='.build', help='build in the given path')
@@ -617,9 +634,6 @@ def main():
else:
args.sysroot = None
- if args.cross_compile_hosts and not all('apple-macos' in target for target in args.cross_compile_hosts):
- error('Cross-compilation is currently only supported for the Darwin platform.')
-
if args.cross_compile_hosts and args.local_compiler_build:
error('Cross-compilation is currently not supported for the local compiler installation')

View File

@ -1,13 +0,0 @@
diff --git a/swift/lib/Driver/UnixToolChains.cpp b/swift/lib/Driver/UnixToolChains.cpp
index bdc63d1ca72..971e5ded1e2 100644
--- a/swift/lib/Driver/UnixToolChains.cpp
+++ b/swift/lib/Driver/UnixToolChains.cpp
@@ -133,7 +133,7 @@ bool toolchains::GenericUnix::addRuntimeRPath(const llvm::Triple &T,
// copied into the bundle.
return Args.hasFlag(options::OPT_toolchain_stdlib_rpath,
options::OPT_no_toolchain_stdlib_rpath,
- !T.isAndroid());
+ true);
}
ToolChain::InvocationInfo

View File

@ -1,50 +0,0 @@
diff --git a/llbuild/lib/BuildSystem/BuildSystem.cpp b/llbuild/lib/BuildSystem/BuildSystem.cpp
index 297dee34..40df58ca 100644
--- a/llbuild/lib/BuildSystem/BuildSystem.cpp
+++ b/llbuild/lib/BuildSystem/BuildSystem.cpp
@@ -3269,7 +3269,7 @@ class ArchiveShellCommand : public ExternalCommand {
if (const char *ar = std::getenv("AR"))
args.push_back(std::string(ar));
else
- args.push_back("ar");
+ args.push_back("llvm-ar");
args.push_back("cr");
args.push_back(archiveName);
args.insert(args.end(), archiveInputs.begin(), archiveInputs.end());
diff --git a/swift/lib/Driver/UnixToolChains.cpp b/swift/lib/Driver/UnixToolChains.cpp
index 1dc32acfd83..d01445c2ef5 100644
--- a/swift/lib/Driver/UnixToolChains.cpp
+++ b/swift/lib/Driver/UnixToolChains.cpp
@@ -384,9 +386,12 @@ toolchains::GenericUnix::constructInvocation(const StaticLinkJobAction &job,
ArgStringList Arguments;
+ const char *AR;
// Configure the toolchain.
- const char *AR =
- context.OI.LTOVariant != OutputInfo::LTOKind::None ? "llvm-ar" : "ar";
+ if (getTriple().isAndroid())
+ AR = "llvm-ar";
+ else
+ AR = context.OI.LTOVariant != OutputInfo::LTOKind::None ? "llvm-ar" : "ar";
Arguments.push_back("crs");
Arguments.push_back(
diff --git a/swift-driver/Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift b/swift-driver/Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift
index a08e3fa1..11d87b85 100644
--- a/swift-driver/Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift
+++ b/swift-driver/Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift
@@ -291,7 +291,12 @@ extension GenericUnixToolchain {
commandLine.append(contentsOf: inputs.filter { $0.type == .object }
.map { .path($0.file) })
- return try getToolPath(.staticLinker(lto))
+ if targetTriple.environment == .android {
+ // Always use the LTO archiver llvm-ar for Android
+ return try getToolPath(.staticLinker(.llvmFull))
+ } else {
+ return try getToolPath(.staticLinker(lto))
+ }
}
}

View File

@ -1,431 +0,0 @@
Date: Wed Aug 25 19:31:48 2021 +0530
[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.
diff --git a/swift/CMakeLists.txt b/swift/CMakeLists.txt
index 73fc7fe0ebc..5487dbc83cd 100644
--- a/swift/CMakeLists.txt
+++ b/swift/CMakeLists.txt
@@ -180,6 +180,8 @@ set(CLANG_COMPILER_VERSION "" CACHE STRING
# build environment.
if(LLVM_USE_LINKER)
set(SWIFT_USE_LINKER_default "${LLVM_USE_LINKER}")
+elseif(${SWIFT_HOST_VARIANT_SDK} STREQUAL ANDROID)
+ set(SWIFT_USE_LINKER_default "lld")
elseif(CMAKE_SYSTEM_NAME STREQUAL Windows AND NOT CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)
set(SWIFT_USE_LINKER_default "lld")
elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
@@ -306,8 +308,8 @@ set(SWIFT_ANDROID_API_LEVEL "" CACHE STRING
set(SWIFT_ANDROID_NDK_PATH "" CACHE STRING
"Path to the directory that contains the Android NDK tools that are executable on the build machine")
-set(SWIFT_ANDROID_NDK_GCC_VERSION "" CACHE STRING
- "The GCC version to use when building for Android. Currently only 4.9 is supported.")
+set(SWIFT_ANDROID_NDK_CLANG_VERSION "12.0.8" CACHE STRING
+ "The Clang version to use when building for Android.")
set(SWIFT_ANDROID_DEPLOY_DEVICE_PATH "" CACHE STRING
"Path on an Android device where build products will be pushed. These are used when running the test suite against the device")
diff --git a/swift/cmake/modules/AddSwift.cmake b/swift/cmake/modules/AddSwift.cmake
index 4cd77fca0fe..e51a966da38 100644
--- a/swift/cmake/modules/AddSwift.cmake
+++ b/swift/cmake/modules/AddSwift.cmake
@@ -145,12 +145,9 @@ function(_add_host_variant_c_compile_link_flags name)
endif()
if(SWIFT_HOST_VARIANT_SDK STREQUAL ANDROID)
- # lld can handle targeting the android build. However, if lld is not
- # enabled, then fallback to the linker included in the android NDK.
- if(NOT SWIFT_USE_LINKER STREQUAL "lld")
- swift_android_tools_path(${SWIFT_HOST_VARIANT_ARCH} tools_path)
- target_compile_options(${name} PRIVATE -B${tools_path})
- endif()
+ # Make sure the Android NDK lld is used.
+ swift_android_tools_path(${SWIFT_HOST_VARIANT_ARCH} tools_path)
+ target_compile_options(${name} PRIVATE $<$<COMPILE_LANGUAGE:C,CXX,OBJC,OBJCXX>:-B${tools_path}>)
endif()
if(SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_APPLE_PLATFORMS)
@@ -384,11 +381,6 @@ function(_add_host_variant_link_flags target)
cxx_link_libraries)
target_link_libraries(${target} PRIVATE
${cxx_link_libraries})
-
- swift_android_libgcc_for_arch_cross_compile(${SWIFT_HOST_VARIANT_ARCH}
- ${SWIFT_HOST_VARIANT_ARCH}_LIB)
- target_link_directories(${target} PRIVATE
- ${${SWIFT_HOST_VARIANT_ARCH}_LIB})
else()
# If lto is enabled, we need to add the object path flag so that the LTO code
# generator leaves the intermediate object file in a place where it will not
diff --git a/swift/cmake/modules/AddSwiftUnittests.cmake b/swift/cmake/modules/AddSwiftUnittests.cmake
index ca0ae47288e..54a3138bec7 100644
--- a/swift/cmake/modules/AddSwiftUnittests.cmake
+++ b/swift/cmake/modules/AddSwiftUnittests.cmake
@@ -32,9 +32,6 @@ function(add_swift_unittest test_dirname)
COMMAND "${SWIFT_SOURCE_DIR}/utils/swift-rpathize.py"
"$<TARGET_FILE:${test_dirname}>")
elseif("${SWIFT_HOST_VARIANT}" STREQUAL "android")
- swift_android_libgcc_for_arch_cross_compile(${SWIFT_HOST_VARIANT_ARCH} android_system_libs)
- set_property(TARGET "${test_dirname}" APPEND PROPERTY LINK_DIRECTORIES
- "${android_system_libs}")
set_property(TARGET "${test_dirname}" APPEND PROPERTY LINK_LIBRARIES "log")
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64")
diff --git a/swift/cmake/modules/SwiftAndroidSupport.cmake b/swift/cmake/modules/SwiftAndroidSupport.cmake
index c56404ca88e..44f0775dd76 100644
--- a/swift/cmake/modules/SwiftAndroidSupport.cmake
+++ b/swift/cmake/modules/SwiftAndroidSupport.cmake
@@ -1,28 +1,7 @@
-function(swift_android_prebuilt_host_name prebuilt_var_name)
- # Get the prebuilt suffix to create the correct toolchain path when using the NDK
- if(CMAKE_HOST_SYSTEM_NAME STREQUAL Darwin)
- set(${prebuilt_var_name} darwin-x86_64 PARENT_SCOPE)
- elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL Linux)
- set(${prebuilt_var_name} linux-x86_64 PARENT_SCOPE)
- elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)
- set(${prebuilt_var_name} Windows-x86_64 PARENT_SCOPE)
- else()
- message(SEND_ERROR "cannot cross-compile to android from ${CMAKE_HOST_SYSTEM_NAME}")
- endif()
-endfunction()
-
-function(swift_android_libgcc_for_arch_cross_compile arch var)
- set(paths)
- if(NOT "${SWIFT_ANDROID_NDK_PATH}" STREQUAL "")
- list(APPEND paths "${SWIFT_SDK_ANDROID_ARCH_${arch}_PATH}/../lib/gcc/${SWIFT_SDK_ANDROID_ARCH_${arch}_NDK_TRIPLE}/${SWIFT_ANDROID_NDK_GCC_VERSION}.x")
- endif()
- set(${var} ${paths} PARENT_SCOPE)
-endfunction()
-
function(swift_android_sysroot sysroot_var_name)
if(NOT "${SWIFT_ANDROID_NDK_PATH}" STREQUAL "")
- swift_android_prebuilt_host_name(prebuilt_build)
- set(${sysroot_var_name} "${SWIFT_ANDROID_NDK_PATH}/toolchains/llvm/prebuilt/${prebuilt_build}/sysroot" PARENT_SCOPE)
+ string(TOLOWER ${CMAKE_HOST_SYSTEM_NAME} platform)
+ set(${sysroot_var_name} "${SWIFT_ANDROID_NDK_PATH}/toolchains/llvm/prebuilt/${platform}-x86_64/sysroot" PARENT_SCOPE)
elseif(NOT "${SWIFT_ANDROID_NATIVE_SYSROOT}" STREQUAL "")
set(${sysroot_var_name} "${SWIFT_ANDROID_NATIVE_SYSROOT}" PARENT_SCOPE)
else()
@@ -32,19 +11,8 @@ endfunction()
function(swift_android_tools_path arch path_var_name)
if(NOT "${SWIFT_ANDROID_NDK_PATH}" STREQUAL "")
- swift_android_prebuilt_host_name(prebuilt_build)
- if("${arch}" STREQUAL "i686")
- set(ndk_prebuilt_path
- "${SWIFT_ANDROID_NDK_PATH}/toolchains/x86-${SWIFT_ANDROID_NDK_GCC_VERSION}/prebuilt/${prebuilt_build}")
- elseif("${arch}" STREQUAL "x86_64")
- set(ndk_prebuilt_path
- "${SWIFT_ANDROID_NDK_PATH}/toolchains/x86_64-${SWIFT_ANDROID_NDK_GCC_VERSION}/prebuilt/${prebuilt_build}")
- else()
- set(ndk_prebuilt_path
- "${SWIFT_ANDROID_NDK_PATH}/toolchains/${SWIFT_SDK_ANDROID_ARCH_${arch}_NDK_TRIPLE}-${SWIFT_ANDROID_NDK_GCC_VERSION}/prebuilt/${prebuilt_build}")
- endif()
-
- set(${path_var_name} "${ndk_prebuilt_path}/${SWIFT_SDK_ANDROID_ARCH_${arch}_NDK_TRIPLE}/bin" PARENT_SCOPE)
+ string(TOLOWER ${CMAKE_HOST_SYSTEM_NAME} platform)
+ set(${path_var_name} "${SWIFT_ANDROID_NDK_PATH}/toolchains/llvm/prebuilt/${platform}-x86_64/bin" PARENT_SCOPE)
elseif(NOT "${SWIFT_ANDROID_NATIVE_SYSROOT}" STREQUAL "")
set(${path_var_name} "${SWIFT_ANDROID_NATIVE_SYSROOT}/usr/bin" PARENT_SCOPE)
else()
diff --git a/swift/lib/Driver/UnixToolChains.cpp b/swift/lib/Driver/UnixToolChains.cpp
index 1dc32acfd83..313b04ae3d4 100644
--- a/swift/lib/Driver/UnixToolChains.cpp
+++ b/swift/lib/Driver/UnixToolChains.cpp
@@ -85,6 +85,9 @@ ToolChain::InvocationInfo toolchains::GenericUnix::constructInvocation(
}
std::string toolchains::GenericUnix::getDefaultLinker() const {
+ if (getTriple().isAndroid())
+ return "lld";
+
switch (getTriple().getArch()) {
case llvm::Triple::arm:
case llvm::Triple::aarch64:
diff --git a/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake b/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake
index 57288b33049..73ab70240e3 100644
--- a/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake
+++ b/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake
@@ -94,12 +94,9 @@ function(_add_target_variant_c_compile_link_flags)
endif()
if("${CFLAGS_SDK}" STREQUAL "ANDROID")
- # lld can handle targeting the android build. However, if lld is not
- # enabled, then fallback to the linker included in the android NDK.
- if(NOT SWIFT_USE_LINKER STREQUAL "lld")
- swift_android_tools_path(${CFLAGS_ARCH} tools_path)
- list(APPEND result "-B" "${tools_path}")
- endif()
+ # Make sure the Android NDK lld is used.
+ swift_android_tools_path(${CFLAGS_ARCH} tools_path)
+ list(APPEND result "-B" "${tools_path}")
endif()
if("${CFLAGS_SDK}" IN_LIST SWIFT_APPLE_PLATFORMS)
@@ -389,8 +386,8 @@ function(_add_target_variant_link_flags)
MACCATALYST_BUILD_FLAVOR "${LFLAGS_MACCATALYST_BUILD_FLAVOR}")
if("${LFLAGS_SDK}" STREQUAL "LINUX")
list(APPEND link_libraries "pthread" "dl")
- if("${SWIFT_HOST_VARIANT_ARCH}" MATCHES "armv6|armv7|i686")
- list(APPEND link_libraries PRIVATE "atomic")
+ if("${LFLAGS_ARCH}" MATCHES "armv6|armv7|i686")
+ list(APPEND link_libraries "atomic")
endif()
elseif("${LFLAGS_SDK}" STREQUAL "FREEBSD")
list(APPEND link_libraries "pthread")
@@ -417,6 +414,11 @@ function(_add_target_variant_link_flags)
list(APPEND link_libraries "dl" "log")
# We need to add the math library, which is linked implicitly by libc++
list(APPEND result "-lm")
+ if(NOT "${SWIFT_ANDROID_NDK_PATH}" STREQUAL "")
+ list(APPEND result "-rtlib=compiler-rt")
+ list(APPEND result "-l:libunwind.a")
+ list(APPEND result "-resource-dir=${SWIFT_SDK_ANDROID_ARCH_${LFLAGS_ARCH}_PATH}/../lib64/clang/${SWIFT_ANDROID_NDK_CLANG_VERSION}")
+ endif()
# link against the custom C++ library
swift_android_cxx_libraries_for_arch(${LFLAGS_ARCH} cxx_link_libraries)
@@ -428,11 +431,6 @@ function(_add_target_variant_link_flags)
list(APPEND link_libraries
${SWIFT_ANDROID_${LFLAGS_ARCH}_ICU_I18N}
${SWIFT_ANDROID_${LFLAGS_ARCH}_ICU_UC})
-
- swift_android_libgcc_for_arch_cross_compile(${LFLAGS_ARCH} ${LFLAGS_ARCH}_LIB)
- foreach(path IN LISTS ${LFLAGS_ARCH}_LIB)
- list(APPEND library_search_directories ${path})
- endforeach()
else()
# If lto is enabled, we need to add the object path flag so that the LTO code
# generator leaves the intermediate object file in a place where it will not
@@ -460,10 +458,17 @@ function(_add_target_variant_link_flags)
endif()
if(SWIFT_USE_LINKER AND NOT SWIFT_COMPILER_IS_MSVC_LIKE)
+ # The linker is normally chosen based on the host, but the Android NDK only
+ # uses lld now.
+ if("${LFLAGS_SDK}" STREQUAL "ANDROID")
+ set(linker "lld")
+ else()
+ set(linker "${SWIFT_USE_LINKER}")
+ endif()
if(CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)
- list(APPEND result "-fuse-ld=${SWIFT_USE_LINKER}.exe")
+ list(APPEND result "-fuse-ld=${linker}.exe")
else()
- list(APPEND result "-fuse-ld=${SWIFT_USE_LINKER}")
+ list(APPEND result "-fuse-ld=${linker}")
endif()
endif()
diff --git a/swift/stdlib/public/runtime/CMakeLists.txt b/swift/stdlib/public/runtime/CMakeLists.txt
index fdb5472a6d1..85aaf68bc9a 100644
--- a/swift/stdlib/public/runtime/CMakeLists.txt
+++ b/swift/stdlib/public/runtime/CMakeLists.txt
@@ -228,7 +228,7 @@ foreach(sdk ${SWIFT_SDKS})
endif()
set(libpthread -lpthread)
set(android_libraries)
- if(sdk STREQUAL ANDROID)
+ if(${sdk} STREQUAL ANDROID)
set(android_libraries -llog)
set(libpthread)
endif()
diff --git a/swift/test/AutoDiff/validation-test/reflection.swift b/swift/test/AutoDiff/validation-test/reflection.swift
index e938506bab6..70a558508c7 100644
--- a/swift/test/AutoDiff/validation-test/reflection.swift
+++ b/swift/test/AutoDiff/validation-test/reflection.swift
@@ -1,4 +1,5 @@
// REQUIRES: no_asan
+// UNSUPPORTED: OS=linux-android, OS=linux-androideabi
// RUN: %empty-directory(%t)
import _Differentiation
diff --git a/swift/test/LinkerSections/function_sections-lld.swift b/swift/test/LinkerSections/function_sections-lld.swift
new file mode 100644
index 00000000000..80d2755c7e3
--- /dev/null
+++ b/swift/test/LinkerSections/function_sections-lld.swift
@@ -0,0 +1,8 @@
+// REQUIRES: OS=linux-androideabi || OS=linux-android
+// RUN: %empty-directory(%t)
+// RUN: %target-build-swift -Xfrontend -function-sections -emit-module -emit-library -static -parse-stdlib %S/Inputs/FunctionSections.swift
+// RUN: %target-build-swift -Xlinker --gc-sections -Xlinker -Map=%t/../../FunctionSections.map -I%t/../.. -L%t/../.. -lFunctionSections %S/Inputs/FunctionSectionsUse.swift
+// RUN: %FileCheck %s < %t/../../FunctionSections.map
+
+// CHECK-NOT: .text.$s16FunctionSections5func2yyF
+// CHECK: .text.$s16FunctionSections5func1yyF
diff --git a/swift/test/LinkerSections/function_sections.swift b/swift/test/LinkerSections/function_sections.swift
index eb01d59563e..a2cf2a39a5c 100644
--- a/swift/test/LinkerSections/function_sections.swift
+++ b/swift/test/LinkerSections/function_sections.swift
@@ -1,4 +1,4 @@
-// REQUIRES: OS=linux-gnu || OS=linux-androideabi || OS=linux-android || OS=freebsd
+// REQUIRES: OS=linux-gnu || OS=freebsd
// RUN: %empty-directory(%t)
// RUN: %target-build-swift -Xfrontend -function-sections -emit-module -emit-library -static -parse-stdlib %S/Inputs/FunctionSections.swift
// RUN: %target-build-swift -Xlinker --gc-sections -Xlinker -Map=%t/../../FunctionSections.map -I%t/../.. -L%t/../.. -lFunctionSections %S/Inputs/FunctionSectionsUse.swift
diff --git a/swift/test/Reflection/capture_descriptors.sil b/swift/test/Reflection/capture_descriptors.sil
index 8857015f814..ef71fc31dc6 100644
--- a/swift/test/Reflection/capture_descriptors.sil
+++ b/swift/test/Reflection/capture_descriptors.sil
@@ -3,6 +3,7 @@
// SR-12893
// XFAIL: openbsd
+// UNSUPPORTED: OS=linux-android, OS=linux-androideabi
// RUN: %empty-directory(%t)
// RUN: %target-build-swift %s -emit-module -emit-library -module-name capture_descriptors -o %t/capture_descriptors%{target-shared-library-suffix} -L%t/../../.. -lBlocksRuntime
diff --git a/swift/test/Reflection/typeref_decoding_imported.swift b/swift/test/Reflection/typeref_decoding_imported.swift
index 634f024c2a3..4d2c7bcc8a7 100644
--- a/swift/test/Reflection/typeref_decoding_imported.swift
+++ b/swift/test/Reflection/typeref_decoding_imported.swift
@@ -16,6 +16,7 @@
// RUN: %target-swift-reflection-dump -binary-filename %t/%target-library-name(TypesToReflect) | %FileCheck %s --check-prefix=CHECK-%target-ptrsize --check-prefix=CHECK-%target-cpu
// UNSUPPORTED: CPU=arm64e
+// UNSUPPORTED: OS=linux-android, OS=linux-androideabi
// CHECK-32: FIELDS:
// CHECK-32: =======
diff --git a/swift/test/lit.site.cfg.in b/swift/test/lit.site.cfg.in
index b9ed0d10833..da6618507ec 100644
--- a/swift/test/lit.site.cfg.in
+++ b/swift/test/lit.site.cfg.in
@@ -42,8 +42,8 @@ config.swift_frontend_test_options = "@SWIFT_FRONTEND_TEST_OPTIONS@"
config.darwin_xcrun_toolchain = "@SWIFT_DARWIN_XCRUN_TOOLCHAIN@"
# --- android ---
+config.android_linker_name = "lld"
config.android_ndk_path = "@SWIFT_ANDROID_NDK_PATH@"
-config.android_ndk_gcc_version = "@SWIFT_ANDROID_NDK_GCC_VERSION@"
config.android_api_level = "@SWIFT_ANDROID_API_LEVEL@"
# --- Windows ---
@@ -127,12 +127,6 @@ if "@SWIFT_ENABLE_SOURCEKIT_TESTS@" == "TRUE":
if "@SWIFT_HAVE_LIBXML2@" == "TRUE":
config.available_features.add('libxml2')
-if "@SWIFT_USE_LINKER@" == "lld":
- config.android_linker_name = "lld"
-else:
- # even if SWIFT_USE_LINKER isn't set, we cannot use BFD for Android
- config.android_linker_name = "gold"
-
if '@SWIFT_INCLUDE_TOOLS@' == 'TRUE':
config.available_features.add('swift_tools_extra')
diff --git a/swift/utils/build-script-impl b/swift/utils/build-script-impl
index 3971ac0c5e1..93efa3811eb 100755
--- a/swift/utils/build-script-impl
+++ b/swift/utils/build-script-impl
@@ -95,7 +95,6 @@ KNOWN_SETTINGS=(
android-icu-uc "" "Path to libicuuc.so"
android-icu-uc-include "" "Path to a directory containing headers for libicuuc"
android-ndk "" "An absolute path to the NDK that will be used as a libc implementation for Android builds"
- android-ndk-gcc-version "" "The GCC version to use when building for Android. Currently only 4.9 is supported"
## Darwin Options
darwin-crash-reporter-client "" "whether to enable CrashReporter integration"
@@ -516,6 +515,7 @@ function set_build_options_for_host() {
# variable.
if [[ "${PREFIX}" ]] ; then
llvm_cmake_options+=(
+ -DCLANG_DEFAULT_LINKER:STRING="lld"
-DDEFAULT_SYSROOT:STRING="$(dirname ${PREFIX})"
)
fi
@@ -1892,7 +1891,6 @@ for host in "${ALL_HOSTS[@]}"; do
cmake_options=(
"${cmake_options[@]}"
-DSWIFT_ANDROID_NDK_PATH:STRING="${ANDROID_NDK}"
- -DSWIFT_ANDROID_NDK_GCC_VERSION:STRING="${ANDROID_NDK_GCC_VERSION}"
-DSWIFT_ANDROID_${ANDROID_ARCH}_ICU_UC:STRING="${ANDROID_ICU_UC}"
-DSWIFT_ANDROID_${ANDROID_ARCH}_ICU_UC_INCLUDE:STRING="${ANDROID_ICU_UC_INCLUDE}"
-DSWIFT_ANDROID_${ANDROID_ARCH}_ICU_I18N:STRING="${ANDROID_ICU_I18N}"
diff --git a/swift/utils/build_swift/build_swift/driver_arguments.py b/swift/utils/build_swift/build_swift/driver_arguments.py
index 569fd401821..dbe5597b0a9 100644
--- a/swift/utils/build_swift/build_swift/driver_arguments.py
+++ b/swift/utils/build_swift/build_swift/driver_arguments.py
@@ -1154,15 +1154,6 @@ def create_argument_parser():
help='The Android API level to target when building for Android. '
'Currently only 21 or above is supported')
- option('--android-ndk-gcc-version', store,
- choices=['4.8', '4.9'],
- default='4.9',
- help='The GCC version to use when building for Android. Currently '
- 'only 4.9 is supported. %(default)s is also the default '
- 'value. This option may be used when experimenting with '
- 'versions of the Android NDK not officially supported by '
- 'Swift')
-
option('--android-icu-uc', store_path,
help='Path to libicuuc.so')
option('--android-icu-uc-include', store_path,
diff --git a/swift/utils/build_swift/tests/expected_options.py b/swift/utils/build_swift/tests/expected_options.py
index 4004159d296..b4a942a4ad7 100644
--- a/swift/utils/build_swift/tests/expected_options.py
+++ b/swift/utils/build_swift/tests/expected_options.py
@@ -48,7 +48,6 @@ EXPECTED_DEFAULTS = {
'android_icu_uc_include': None,
'android_icu_data': None,
'android_ndk': None,
- 'android_ndk_gcc_version': '4.9',
'android_arch': 'armv7',
'assertions': True,
'benchmark': False,
@@ -651,8 +650,6 @@ EXPECTED_OPTIONS = [
DisableOption('--skip-build-clang-tools-extra',
dest='build_clang_tools_extra'),
- ChoicesOption('--android-ndk-gcc-version',
- choices=['4.8', '4.9']),
ChoicesOption('--compiler-vendor',
choices=['none', 'apple']),
ChoicesOption('--swift-analyze-code-coverage',
diff --git a/swift/validation-test/lit.site.cfg.in b/swift/validation-test/lit.site.cfg.in
index 962c633f191..9da09c7bd39 100644
--- a/swift/validation-test/lit.site.cfg.in
+++ b/swift/validation-test/lit.site.cfg.in
@@ -36,8 +36,8 @@ config.swift_frontend_test_options = "@SWIFT_FRONTEND_TEST_OPTIONS@"
config.darwin_xcrun_toolchain = "@SWIFT_DARWIN_XCRUN_TOOLCHAIN@"
# --- Android Configuration ---
+config.android_linker_name = "lld"
config.android_ndk_path = "@SWIFT_ANDROID_NDK_PATH@"
-config.android_ndk_gcc_version = "@SWIFT_ANDROID_NDK_GCC_VERSION@"
config.android_api_level = "@SWIFT_ANDROID_API_LEVEL@"
# --- Windows MSVC Configuration ---
@@ -110,12 +110,6 @@ if "@CMAKE_GENERATOR@" == "Xcode":
config.available_features.add("CMAKE_GENERATOR=@CMAKE_GENERATOR@")
-if "@SWIFT_USE_LINKER@" == "lld":
- config.android_linker_name = "lld"
-else:
- # even if SWIFT_USE_LINKER isn't set, we cannot use BFD for Android
- config.android_linker_name = "gold"
-
# Let the main config do the real work.
config.test_exec_root = os.path.dirname(os.path.realpath(__file__))
lit_config.load_config(config, "@SWIFT_SOURCE_DIR@/validation-test/lit.cfg")
diff --git a/swift/utils/swift_build_support/swift_build_support/build_script_invocation.py b/swift/utils/swift_build_support/swift_build_support/build_script_invocation.py
index 1e8e70d42a5..2ea2450825a 100644
--- a/swift/utils/swift_build_support/swift_build_support/build_script_invocation.py
+++ b/swift/utils/swift_build_support/swift_build_support/build_script_invocation.py
@@ -306,7 +306,6 @@ class BuildScriptInvocation(object):
"--android-arch", args.android_arch,
"--android-ndk", args.android_ndk,
"--android-api-level", args.android_api_level,
- "--android-ndk-gcc-version", args.android_ndk_gcc_version,
"--android-icu-uc", args.android_icu_uc,
"--android-icu-uc-include", args.android_icu_uc_include,
"--android-icu-i18n", args.android_icu_i18n,

View File

@ -0,0 +1,518 @@
From 5eb29d99dd3e3944da43b29c0eafb8608202ddba
Date: Tue, 11 May 2021 01:10:50 +0530
Subject: [PATCH] [android] Switch to new single-header modulemap for Bionic
too
---
stdlib/public/Platform/CMakeLists.txt | 4 +-
stdlib/public/Platform/SwiftGlibc.h.gyb | 1 -
stdlib/public/Platform/bionic.modulemap.gyb | 393 ------------------
stdlib/public/Platform/glibc.modulemap.gyb | 4 +-
stdlib/public/SwiftShims/LibcShims.h | 2 +-
test/Interop/C/libc/include-signal.swift | 4 +-
.../Cxx/class/memory-layout-silgen.swift | 3 -
test/Interop/Cxx/libc/include-glibc.swift | 2 +-
8 files changed, 7 insertions(+), 406 deletions(-)
delete mode 100644 stdlib/public/Platform/bionic.modulemap.gyb
diff --git a/swift/stdlib/public/Platform/CMakeLists.txt b/swift/stdlib/public/Platform/CMakeLists.txt
index 9d6fccd4082ca..6ae5209186fd3 100644
--- a/swift/stdlib/public/Platform/CMakeLists.txt
+++ b/swift/stdlib/public/Platform/CMakeLists.txt
@@ -130,9 +130,7 @@ foreach(sdk ${SWIFT_SDKS})
set(module_dir "${SWIFTLIB_DIR}/${arch_subdir}")
set(module_dir_static "${SWIFTSTATICLIB_DIR}/${arch_subdir}")
- if(${sdk} STREQUAL ANDROID)
- set(glibc_modulemap_source "bionic.modulemap.gyb")
- elseif(${sdk} STREQUAL OPENBSD)
+ if(${sdk} STREQUAL OPENBSD)
set(glibc_modulemap_source "libc-openbsd.modulemap.gyb")
else()
set(glibc_modulemap_source "glibc.modulemap.gyb")
diff --git a/swift/stdlib/public/Platform/SwiftGlibc.h.gyb b/swift/stdlib/public/Platform/SwiftGlibc.h.gyb
index 3391eaee29934..78c725bae8c73 100644
--- a/swift/stdlib/public/Platform/SwiftGlibc.h.gyb
+++ b/swift/stdlib/public/Platform/SwiftGlibc.h.gyb
@@ -28,7 +28,6 @@ headers = [
'tgmath.h',
'time.h',
'utmp.h',
- 'utmpx.h',
# POSIX
'aio.h',
diff --git a/swift/stdlib/public/Platform/bionic.modulemap.gyb b/swift/stdlib/public/Platform/bionic.modulemap.gyb
deleted file mode 100644
index e44f9082653a6..0000000000000
--- a/swift/stdlib/public/Platform/bionic.modulemap.gyb
+++ /dev/null
@@ -1,393 +0,0 @@
-//===--- bionic.modulemap -------------------------------------------------===//
-//
-// This source file is part of the Swift.org open source project
-//
-// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
-// Licensed under Apache License v2.0 with Runtime Library Exception
-//
-// See https://swift.org/LICENSE.txt for license information
-// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
-//
-//===----------------------------------------------------------------------===//
-
-/// This is a semi-complete modulemap that maps bionics's headers in a roughly
-/// similar way to the Darwin SDK modulemap. We do not take care to list every
-/// single header which may be included by a particular submodule, so there can
-/// still be issues if imported into the same context as one in which someone
-/// included those headers directly.
-///
-/// It's not named just Bionic so that it doesn't conflict in the event of a
-/// future official bionic modulemap.
-module SwiftGlibc [system] {
-
- link "dl"
-
- // C standard library
- module C {
- module features {
- header "${GLIBC_INCLUDE_PATH}/features.h"
- export *
- }
-
- module complex {
- header "${GLIBC_INCLUDE_PATH}/complex.h"
- export *
- }
-
- module pty {
- header "${GLIBC_INCLUDE_PATH}/pty.h"
- export *
- }
- module utmp {
- header "${GLIBC_INCLUDE_PATH}/utmp.h"
- export *
- }
-
- module ctype {
- header "${GLIBC_INCLUDE_PATH}/ctype.h"
- export *
- }
- module errno {
- header "${GLIBC_INCLUDE_PATH}/errno.h"
- export *
- }
-
- module fenv {
- header "${GLIBC_INCLUDE_PATH}/fenv.h"
- export *
- }
-
- // note: supplied by compiler
- // module float {
- // header "${GLIBC_INCLUDE_PATH}/float.h"
- // export *
- // }
-
- module inttypes {
- header "${GLIBC_INCLUDE_PATH}/inttypes.h"
- export *
- }
-
- // note: potentially supplied by compiler
- // module iso646 {
- // header "${GLIBC_INCLUDE_PATH}/iso646.h"
- // export *
- // }
- // module limits {
- // header "${GLIBC_INCLUDE_PATH}/limits.h"
- // export *
- // }
-
- module locale {
- header "${GLIBC_INCLUDE_PATH}/locale.h"
- export *
- }
- module math {
- link "m"
- header "${GLIBC_INCLUDE_PATH}/math.h"
- export *
- }
- module setjmp {
- header "${GLIBC_INCLUDE_PATH}/setjmp.h"
- export *
- }
- module signal {
- header "${GLIBC_INCLUDE_PATH}/signal.h"
- export *
- }
-
- // note: supplied by the compiler
- // module stdarg {
- // header "${GLIBC_INCLUDE_PATH}/stdarg.h"
- // export *
- // }
- // module stdbool {
- // header "${GLIBC_INCLUDE_PATH}/stdbool.h"
- // export *
- // }
- // module stddef {
- // header "${GLIBC_INCLUDE_PATH}/stddef.h"
- // export *
- // }
- // module stdint {
- // header "${GLIBC_INCLUDE_PATH}/stdint.h"
- // export *
- // }
-
- module stdio {
- header "${GLIBC_INCLUDE_PATH}/stdio.h"
- export *
- }
- module stdlib {
- header "${GLIBC_INCLUDE_PATH}/stdlib.h"
- export *
- export stddef
- }
- module string {
- header "${GLIBC_INCLUDE_PATH}/string.h"
- export *
- }
-
- // note: supplied by the compiler
- // explicit module tgmath {
- // header "${GLIBC_INCLUDE_PATH}/tgmath.h"
- // export *
- // }
-
- module time {
- header "${GLIBC_INCLUDE_PATH}/time.h"
- export *
- }
- }
-
- // POSIX
- module POSIX {
- module wait {
- header "${GLIBC_INCLUDE_PATH}/wait.h"
- export *
- }
-
- module cpio {
- header "${GLIBC_INCLUDE_PATH}/cpio.h"
- export *
- }
- module nl_types {
- header "${GLIBC_INCLUDE_PATH}/nl_types.h"
- export *
- }
-
- module ftw {
- header "${GLIBC_INCLUDE_PATH}/ftw.h"
- export *
- }
- module glob {
- header "${GLIBC_INCLUDE_PATH}/glob.h"
- export *
- }
- module iconv {
- header "${GLIBC_INCLUDE_PATH}/iconv.h"
- export *
- }
- module langinfo {
- header "${GLIBC_INCLUDE_PATH}/langinfo.h"
- export *
- }
- module netdb {
- header "${GLIBC_INCLUDE_PATH}/netdb.h"
- export *
- }
- module ifaddrs {
- header "${GLIBC_INCLUDE_PATH}/ifaddrs.h"
- export *
- }
- module search {
- header "${GLIBC_INCLUDE_PATH}/search.h"
- export *
- }
- module spawn {
- header "${GLIBC_INCLUDE_PATH}/spawn.h"
- export *
- }
- module syslog {
- header "${GLIBC_INCLUDE_PATH}/syslog.h"
- export *
- }
- module tar {
- header "${GLIBC_INCLUDE_PATH}/tar.h"
- export *
- }
-
- module arpa {
- module inet {
- header "${GLIBC_INCLUDE_PATH}/arpa/inet.h"
- export *
- }
- export *
- }
- module dirent {
- header "${GLIBC_INCLUDE_PATH}/dirent.h"
- export *
- }
- module dlfcn {
- header "${GLIBC_INCLUDE_PATH}/dlfcn.h"
- export *
- }
- module fcntl {
- header "${GLIBC_INCLUDE_PATH}/fcntl.h"
- export *
- }
- module fnmatch {
- header "${GLIBC_INCLUDE_PATH}/fnmatch.h"
- export *
- }
- module grp {
- header "${GLIBC_INCLUDE_PATH}/grp.h"
- export *
- }
- module ioctl {
- header "${GLIBC_ARCH_INCLUDE_PATH}/sys/ioctl.h"
- export *
- }
- module libgen {
- header "${GLIBC_INCLUDE_PATH}/libgen.h"
- export *
- }
- module net {
- module if {
- header "${GLIBC_INCLUDE_PATH}/net/if.h"
- export *
- }
- }
- module netinet {
- module in {
- header "${GLIBC_INCLUDE_PATH}/netinet/in.h"
- export *
-
- exclude header "${GLIBC_INCLUDE_PATH}/netinet6/in6.h"
- }
- module tcp {
- header "${GLIBC_INCLUDE_PATH}/netinet/tcp.h"
- export *
- }
- }
- module poll {
- header "${GLIBC_INCLUDE_PATH}/poll.h"
- export *
- }
- module pthread {
- header "${GLIBC_INCLUDE_PATH}/pthread.h"
- export *
- }
- module pwd {
- header "${GLIBC_INCLUDE_PATH}/pwd.h"
- export *
- }
- module regex {
- header "${GLIBC_INCLUDE_PATH}/regex.h"
- export *
- }
- module sched {
- header "${GLIBC_INCLUDE_PATH}/sched.h"
- export *
- }
- module semaphore {
- header "${GLIBC_INCLUDE_PATH}/semaphore.h"
- export *
- }
- module strings {
- header "${GLIBC_INCLUDE_PATH}/strings.h"
- export *
- }
-
- module sys {
- export *
-
- module cdefs {
- header "${GLIBC_ARCH_INCLUDE_PATH}/sys/cdefs.h"
- export *
- }
- module file {
- header "${GLIBC_ARCH_INCLUDE_PATH}/sys/file.h"
- export *
- }
- module sem {
- header "${GLIBC_ARCH_INCLUDE_PATH}/sys/sem.h"
- export *
- }
- module shm {
- header "${GLIBC_ARCH_INCLUDE_PATH}/sys/shm.h"
- export *
- }
- module inotify {
- header "${GLIBC_ARCH_INCLUDE_PATH}/sys/inotify.h"
- export *
- }
- module statvfs {
- header "${GLIBC_ARCH_INCLUDE_PATH}/sys/statvfs.h"
- export *
- }
-
- module ipc {
- header "${GLIBC_ARCH_INCLUDE_PATH}/sys/ipc.h"
- export *
- }
- module mman {
- header "${GLIBC_ARCH_INCLUDE_PATH}/sys/mman.h"
- export *
- }
- module msg {
- header "${GLIBC_ARCH_INCLUDE_PATH}/sys/msg.h"
- export *
- }
- module resource {
- header "${GLIBC_ARCH_INCLUDE_PATH}/sys/resource.h"
- export *
- }
- module select {
- header "${GLIBC_ARCH_INCLUDE_PATH}/sys/select.h"
- export *
- }
- module sendfile {
- header "${GLIBC_ARCH_INCLUDE_PATH}/sys/sendfile.h"
- export *
- }
- module socket {
- header "${GLIBC_ARCH_INCLUDE_PATH}/sys/socket.h"
- export *
- }
- module stat {
- header "${GLIBC_ARCH_INCLUDE_PATH}/sys/stat.h"
- export *
- }
- module time {
- header "${GLIBC_ARCH_INCLUDE_PATH}/sys/time.h"
- export *
- }
- module times {
- header "${GLIBC_ARCH_INCLUDE_PATH}/sys/times.h"
- export *
- }
- module types {
- header "${GLIBC_ARCH_INCLUDE_PATH}/sys/types.h"
- export *
- }
- module uio {
- header "${GLIBC_ARCH_INCLUDE_PATH}/sys/uio.h"
- export *
- }
- module un {
- header "${GLIBC_ARCH_INCLUDE_PATH}/sys/un.h"
- export *
- }
- module user {
- header "${GLIBC_ARCH_INCLUDE_PATH}/sys/user.h"
- export *
- }
- module utsname {
- header "${GLIBC_ARCH_INCLUDE_PATH}/sys/utsname.h"
- export *
- }
- module wait {
- header "${GLIBC_ARCH_INCLUDE_PATH}/sys/wait.h"
- export *
- }
- }
- module sysexits {
- header "${GLIBC_INCLUDE_PATH}/sysexits.h"
- export *
- }
- module termios {
- header "${GLIBC_INCLUDE_PATH}/termios.h"
- export *
- }
- module unistd {
- header "${GLIBC_INCLUDE_PATH}/unistd.h"
- export *
- }
- module utime {
- header "${GLIBC_INCLUDE_PATH}/utime.h"
- export *
- }
- }
-}
-
diff --git a/swift/stdlib/public/Platform/glibc.modulemap.gyb b/swift/stdlib/public/Platform/glibc.modulemap.gyb
index 455dd111e2ce3..8f77e1028001c 100644
--- a/swift/stdlib/public/Platform/glibc.modulemap.gyb
+++ b/swift/stdlib/public/Platform/glibc.modulemap.gyb
@@ -19,7 +19,7 @@
/// It's not named just Glibc so that it doesn't conflict in the event of a
/// future official glibc modulemap.
module SwiftGlibc [system] {
-% if CMAKE_SDK == "LINUX":
+% if CMAKE_SDK in ["LINUX", "ANDROID"]:
link "m"
% end
% if CMAKE_SDK in ["LINUX", "FREEBSD", "CYGWIN"]:
@@ -43,7 +43,7 @@ module SwiftGlibc [system] {
export *
}
-% if CMAKE_SDK != "WASI":
+% if CMAKE_SDK != "WASI" and CMAKE_SDK != "ANDROID":
module CUUID [system] {
header "${GLIBC_INCLUDE_PATH}/uuid/uuid.h"
link "uuid"
diff --git a/swift/stdlib/public/SwiftShims/LibcShims.h b/swift/stdlib/public/SwiftShims/LibcShims.h
index 7dfde65ae46a8..82a43efa06e10 100644
--- a/swift/stdlib/public/SwiftShims/LibcShims.h
+++ b/swift/stdlib/public/SwiftShims/LibcShims.h
@@ -68,7 +68,7 @@ static inline __swift_size_t _swift_stdlib_strlen_unsigned(const unsigned char *
SWIFT_READONLY
static inline int _swift_stdlib_memcmp(const void *s1, const void *s2,
__swift_size_t n) {
-#if defined(__APPLE__)
+#if defined(__APPLE__) || defined(__ANDROID__)
extern int memcmp(const void * _Nullable, const void * _Nullable, __swift_size_t);
#else
extern int memcmp(const void *, const void *, __swift_size_t);
diff --git a/swift/test/Interop/C/libc/include-signal.swift b/swift/test/Interop/C/libc/include-signal.swift
index 3b420364f3ce8..83029c9b3b530 100644
--- a/swift/test/Interop/C/libc/include-signal.swift
+++ b/swift/test/Interop/C/libc/include-signal.swift
@@ -28,6 +28,6 @@
// See https://forums.swift.org/t/problems-with-swiftglibc-and-proposed-fix/37594
// for further details.
-// REQUIRES: OS=linux-gnu
+// REQUIRES: OS=linux-gnu || OS=linux-android
-import IncludeSignal
\ No newline at end of file
+import IncludeSignal
diff --git a/swift/test/Interop/Cxx/class/memory-layout-silgen.swift b/swift/test/Interop/Cxx/class/memory-layout-silgen.swift
index a0301a03af7f3..35d3f2797ad32 100644
--- a/swift/test/Interop/Cxx/class/memory-layout-silgen.swift
+++ b/swift/test/Interop/Cxx/class/memory-layout-silgen.swift
@@ -1,8 +1,5 @@
// RUN: %target-swiftxx-frontend -I %S/Inputs -emit-ir -o - %s | %FileCheck %s
-// XFAIL: OS=linux-android
-// XFAIL: OS=linux-androideabi
-
import MemoryLayout
var v = PrivateMemberLayout()
diff --git a/swift/test/Interop/Cxx/libc/include-glibc.swift b/swift/test/Interop/Cxx/libc/include-glibc.swift
index 116dc88895783..b36e7379d22b0 100644
--- a/swift/test/Interop/Cxx/libc/include-glibc.swift
+++ b/swift/test/Interop/Cxx/libc/include-glibc.swift
@@ -1,7 +1,7 @@
// RUN: %target-run-simple-swift(-Xfrontend -enable-cxx-interop)
// REQUIRES: executable_test
-// REQUIRES: OS=linux-gnu
+// REQUIRES: OS=linux-gnu || OS=linux-android
import Glibc
import StdlibUnittest

View File

@ -1,9 +1,34 @@
From 7b2256f97b59192046eab312838f467def880605
Date: Sun, 9 Jan 2022 21:45:13 +0530
Subject: [PATCH] [android] Move the string and other tags in pointers to the
second byte because Android enabled memory tagging
Starting with Android 11, AArch64 placed a tag in the top byte of pointers to
allocations, which has been slowly rolling out to more devices and collides
with Swift's tags. Moving these tags to the second byte works around this
problem.
---
stdlib/public/SwiftShims/HeapObject.h | 10 +++++
stdlib/public/core/KeyPath.swift | 10 +++++
stdlib/public/core/SmallString.swift | 9 ++++
stdlib/public/core/StringObject.swift | 64 ++++++++++++++++++++++++++-
stdlib/public/runtime/HeapObject.cpp | 5 +++
diff --git a/swift/stdlib/public/SwiftShims/HeapObject.h b/swift/stdlib/public/SwiftShims/HeapObject.h
index 5e165fd3d4..978f1b2293 100644
index 3933b0b8d40e2..f45e8774951b3 100644
--- a/swift/stdlib/public/SwiftShims/HeapObject.h
+++ b/swift/stdlib/public/SwiftShims/HeapObject.h
@@ -161,8 +161,13 @@ static_assert(alignof(HeapObject) == alignof(void*),
@@ -157,12 +157,22 @@ static_assert(alignof(HeapObject) == alignof(void*),
#endif
#define _swift_abi_SwiftSpareBitsMask \
(__swift_uintptr_t) SWIFT_ABI_ARM64_SWIFT_SPARE_BITS_MASK
+#if defined(__ANDROID__)
+#define _swift_abi_ObjCReservedBitsMask \
+ (__swift_uintptr_t) SWIFT_ABI_ANDROID_ARM64_OBJC_RESERVED_BITS_MASK
+#else
#define _swift_abi_ObjCReservedBitsMask \
(__swift_uintptr_t) SWIFT_ABI_ARM64_OBJC_RESERVED_BITS_MASK
+#endif
#define _swift_abi_ObjCReservedLowBits \
(unsigned) SWIFT_ABI_ARM64_OBJC_NUM_RESERVED_LOW_BITS
+#if defined(__ANDROID__)
@ -16,57 +41,30 @@ index 5e165fd3d4..978f1b2293 100644
#elif defined(__powerpc64__)
diff --git a/swift/stdlib/public/core/Builtin.swift b/swift/stdlib/public/core/Builtin.swift
index 8a7bb33243..65be72766e 100644
--- a/swift/stdlib/public/core/Builtin.swift
+++ b/swift/stdlib/public/core/Builtin.swift
@@ -397,7 +397,13 @@ internal var _objectPointerIsObjCBit: UInt {
#else
@inlinable
internal var _objectPointerIsObjCBit: UInt {
- @inline(__always) get { return 0x4000_0000_0000_0000 }
+ @inline(__always) get {
+#if os(Android) && arch(arm64)
+ return 0x0040_0000_0000_0000
+#else
+ return 0x4000_0000_0000_0000
+#endif
+ }
}
#endif
diff --git a/swift/stdlib/public/core/KeyPath.swift b/swift/stdlib/public/core/KeyPath.swift
index 2d8f039742..3501f31c83 100644
index 2d8f03974253b..3501f31c83a9e 100644
--- a/swift/stdlib/public/core/KeyPath.swift
+++ b/swift/stdlib/public/core/KeyPath.swift
@@ -1764,7 +1764,12 @@ internal struct KeyPathBuffer {
@@ -1764,7 +1764,7 @@ internal struct KeyPathBuffer {
internal mutating func pushRaw(size: Int, alignment: Int)
-> UnsafeMutableRawBufferPointer {
var baseAddress = buffer.baseAddress.unsafelyUnwrapped
+#if os(Android) && arch(arm64)
+ // Android AArch64 may tag the first byte so remove it before checking alignment.
+ var misalign = (0x00FF_FFFF_FFFF_FFFF & Int(bitPattern: baseAddress)) % alignment
+#else
var misalign = Int(bitPattern: baseAddress) % alignment
+#endif
- var misalign = Int(bitPattern: baseAddress) % alignment
+ var misalign = Int(bitPattern: baseAddress) & (alignment - 1)
if misalign != 0 {
misalign = alignment - misalign
baseAddress = baseAddress.advanced(by: misalign)
@@ -3242,7 +3247,12 @@ internal struct InstantiateKeyPathBuffer: KeyPathPatternVisitor {
@@ -3242,7 +3242,7 @@ internal struct InstantiateKeyPathBuffer: KeyPathPatternVisitor {
) {
let alignment = MemoryLayout<T>.alignment
var baseAddress = destData.baseAddress.unsafelyUnwrapped
+#if os(Android) && arch(arm64)
+ // Android AArch64 may tag the first byte so remove it before checking alignment.
+ var misalign = (0x00FF_FFFF_FFFF_FFFF & Int(bitPattern: baseAddress)) % alignment
+#else
var misalign = Int(bitPattern: baseAddress) % alignment
+#endif
- var misalign = Int(bitPattern: baseAddress) % alignment
+ var misalign = Int(bitPattern: baseAddress) & (alignment - 1)
if misalign != 0 {
misalign = alignment - misalign
baseAddress = baseAddress.advanced(by: misalign)
diff --git a/swift/stdlib/public/core/SmallString.swift b/swift/stdlib/public/core/SmallString.swift
index df46b4e8bf..ac0969b570 100644
index df46b4e8bf449..ac0969b57041e 100644
--- a/swift/stdlib/public/core/SmallString.swift
+++ b/swift/stdlib/public/core/SmallString.swift
@@ -23,6 +23,9 @@
@ -101,7 +99,7 @@ index df46b4e8bf..ac0969b570 100644
}
diff --git a/swift/stdlib/public/core/StringObject.swift b/swift/stdlib/public/core/StringObject.swift
index b087e87f51..93f243ddd9 100644
index b087e87f51eb7..88ff7fbf08980 100644
--- a/swift/stdlib/public/core/StringObject.swift
+++ b/swift/stdlib/public/core/StringObject.swift
@@ -56,6 +56,11 @@
@ -178,19 +176,7 @@ index b087e87f51..93f243ddd9 100644
}
// Discriminator for large, mortal (i.e. managed), swift-native strings
@@ -381,7 +409,11 @@ extension _StringObject.Nibbles {
internal static func largeMortal() -> UInt64 { return 0x0000_0000_0000_0000 }
internal static func largeCocoa(providesFastUTF8: Bool) -> UInt64 {
+#if os(Android) && arch(arm64)
+ return providesFastUTF8 ? 0x0040_0000_0000_0000 : 0x0050_0000_0000_0000
+#else
return providesFastUTF8 ? 0x4000_0000_0000_0000 : 0x5000_0000_0000_0000
+#endif
}
}
@@ -397,7 +429,11 @@ extension _StringObject {
@@ -397,7 +425,11 @@ extension _StringObject {
@inlinable @inline(__always)
internal var isImmortal: Bool {
@ -202,7 +188,7 @@ index b087e87f51..93f243ddd9 100644
}
@inlinable @inline(__always)
@@ -405,7 +441,11 @@ extension _StringObject {
@@ -405,7 +437,11 @@ extension _StringObject {
@inlinable @inline(__always)
internal var isSmall: Bool {
@ -214,7 +200,7 @@ index b087e87f51..93f243ddd9 100644
}
@inlinable @inline(__always)
@@ -419,7 +459,11 @@ extension _StringObject {
@@ -419,7 +455,11 @@ extension _StringObject {
// - Non-Cocoa shared strings
@inlinable @inline(__always)
internal var providesFastUTF8: Bool {
@ -226,7 +212,7 @@ index b087e87f51..93f243ddd9 100644
}
@inlinable @inline(__always)
@@ -429,16 +473,26 @@ extension _StringObject {
@@ -429,16 +469,26 @@ extension _StringObject {
// conforms to `_AbstractStringStorage`
@inline(__always)
internal var hasStorage: Bool {
@ -253,7 +239,7 @@ index b087e87f51..93f243ddd9 100644
let result = bits & 0x2000_0000_0000_0000 != 0
_internalInvariant(!result || hasStorage, "native storage needs storage")
return result
@@ -466,7 +520,11 @@ extension _StringObject {
@@ -466,7 +516,11 @@ extension _StringObject {
@inline(__always)
internal var largeIsCocoa: Bool {
_internalInvariant(isLarge)
@ -265,7 +251,7 @@ index b087e87f51..93f243ddd9 100644
}
// Whether this string is in one of our fastest representations:
@@ -535,7 +593,11 @@ extension _StringObject {
@@ -535,7 +589,11 @@ extension _StringObject {
@inlinable
internal static func getSmallCount(fromRaw x: UInt64) -> Int {
@ -277,7 +263,7 @@ index b087e87f51..93f243ddd9 100644
}
@inlinable @inline(__always)
@@ -546,7 +608,11 @@ extension _StringObject {
@@ -546,7 +604,11 @@ extension _StringObject {
@inlinable
internal static func getSmallIsASCII(fromRaw x: UInt64) -> Bool {
@ -290,7 +276,7 @@ index b087e87f51..93f243ddd9 100644
@inlinable @inline(__always)
internal var smallIsASCII: Bool {
diff --git a/swift/stdlib/public/runtime/HeapObject.cpp b/swift/stdlib/public/runtime/HeapObject.cpp
index 0a27620622..69b4350f7d 100644
index 7f6f6ddbdaee1..d1ab476740acd 100644
--- a/swift/stdlib/public/runtime/HeapObject.cpp
+++ b/swift/stdlib/public/runtime/HeapObject.cpp
@@ -66,6 +66,10 @@ static inline bool isValidPointerForNativeRetain(const void *p) {
@ -300,7 +286,7 @@ index 0a27620622..69b4350f7d 100644
+#elif defined(__ANDROID__) && defined(__aarch64__)
+ // Check the top of the second byte instead, since Android AArch64 reserves
+ // the top byte for its own pointer tagging since Android 11.
+ return (intptr_t)p << 8 > 0;
+ return (intptr_t)((uintptr_t)p << 8) > 0;
#elif defined(__x86_64__) || defined(__arm64__) || defined(__aarch64__) || defined(_M_ARM64) || defined(__s390x__) || (defined(__powerpc64__) && defined(__LITTLE_ENDIAN__))
// On these platforms, except s390x, the upper half of address space is reserved for the
// kernel, so we can assume that pointer values in this range are invalid.

View File

@ -1,41 +0,0 @@
diff --git a/swift/stdlib/public/Platform/bionic.modulemap.gyb b/swift/stdlib/public/Platform/bionic.modulemap.gyb
index e44f9082653..da77854eb75 100644
--- a/swift/stdlib/public/Platform/bionic.modulemap.gyb
+++ b/swift/stdlib/public/Platform/bionic.modulemap.gyb
@@ -161,11 +161,11 @@ module SwiftGlibc [system] {
export *
}
module glob {
- header "${GLIBC_INCLUDE_PATH}/glob.h"
+ header "${TERMUX_INCLUDE_PATH}/glob.h"
export *
}
module iconv {
- header "${GLIBC_INCLUDE_PATH}/iconv.h"
+ header "${TERMUX_INCLUDE_PATH}/iconv.h"
export *
}
module langinfo {
@@ -185,7 +185,7 @@ module SwiftGlibc [system] {
export *
}
module spawn {
- header "${GLIBC_INCLUDE_PATH}/spawn.h"
+ header "${TERMUX_INCLUDE_PATH}/spawn.h"
export *
}
module syslog {
@@ -291,11 +291,11 @@ module SwiftGlibc [system] {
export *
}
module sem {
- header "${GLIBC_ARCH_INCLUDE_PATH}/sys/sem.h"
+ header "${GLIBC_ARCH_INCLUDE_PATH}/linux/sem.h"
export *
}
module shm {
- header "${GLIBC_ARCH_INCLUDE_PATH}/sys/shm.h"
+ header "${GLIBC_ARCH_INCLUDE_PATH}/linux/shm.h"
export *
}
module inotify {

View File

@ -1,40 +0,0 @@
commit 7d8933abcb83aa9ce9b420b564f17da75d3a7d07
Date: Mon Jul 26 22:13:58 2021 +0530
TSCBasic: FILE is an opaque struct since Android 7 (#243)
diff --git a/swift-tools-support-core/Sources/TSCBasic/WritableByteStream.swift b/swift-tools-support-core/Sources/TSCBasic/WritableByteStream.swift
index 06af150..cdfdb4c 100644
--- a/swift-tools-support-core/Sources/TSCBasic/WritableByteStream.swift
+++ b/swift-tools-support-core/Sources/TSCBasic/WritableByteStream.swift
@@ -66,6 +66,12 @@ public extension WritableByteStream {
// Public alias to the old name to not introduce API compatibility.
public typealias OutputByteStream = WritableByteStream
+#if os(Android)
+public typealias FILEPointer = OpaquePointer
+#else
+public typealias FILEPointer = UnsafeMutablePointer<FILE>
+#endif
+
extension WritableByteStream {
/// Write a sequence of bytes to the buffer.
public func write<S: Sequence>(sequence: S) where S.Iterator.Element == UInt8 {
@@ -670,7 +676,7 @@ public class FileOutputByteStream: _WritableByteStreamBase {
public final class LocalFileOutputByteStream: FileOutputByteStream {
/// The pointer to the file.
- let filePointer: UnsafeMutablePointer<FILE>
+ let filePointer: FILEPointer
/// Set to an error value if there were any IO error during writing.
private var error: FileSystemError?
@@ -682,7 +688,7 @@ public final class LocalFileOutputByteStream: FileOutputByteStream {
private let path: AbsolutePath?
/// Instantiate using the file pointer.
- public init(filePointer: UnsafeMutablePointer<FILE>, closeOnDeinit: Bool = true, buffered: Bool = true) throws {
+ public init(filePointer: FILEPointer, closeOnDeinit: Bool = true, buffered: Bool = true) throws {
self.filePointer = filePointer
self.closeOnDeinit = closeOnDeinit
self.path = nil

View File

@ -1,13 +0,0 @@
diff --git a/swift-tools-support-core/Sources/TSCBasic/CMakeLists.txt b/swift-tools-support-core/Sources/TSCBasic/CMakeLists.txt
index bbc43d98..bc5ee576 100644
--- a/swift-tools-support-core/Sources/TSCBasic/CMakeLists.txt
+++ b/swift-tools-support-core/Sources/TSCBasic/CMakeLists.txt
@@ -53,7 +53,7 @@ target_link_libraries(TSCBasic PUBLIC
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
if(Foundation_FOUND)
target_link_libraries(TSCBasic PUBLIC
- Foundation)
+ Foundation android-spawn)
endif()
endif()
target_link_libraries(TSCBasic PRIVATE

View File

@ -2,15 +2,6 @@ diff --git a/swift/utils/build-script-impl b/swift/utils/build-script-impl
index b1d060328bc..218c9215260 100755
--- a/swift/utils/build-script-impl
+++ b/swift/utils/build-script-impl
@@ -1060,7 +1064,7 @@ function get_host_install_destdir() {
# This assumes that all hosts are merged to the lipo.
local host_install_destdir="${INSTALL_DESTDIR}"
else
- local host_install_destdir="${INSTALL_DESTDIR}/${host}"
+ local host_install_destdir="${INSTALL_DESTDIR}"
fi
else
local host_install_destdir="${INSTALL_DESTDIR}"
@@ -1652,6 +1688,13 @@ for host in "${ALL_HOSTS[@]}"; do
-DLLVM_NATIVE_BUILD=$(build_directory "${LOCAL_HOST}" llvm)
)
@ -26,9 +17,9 @@ index b1d060328bc..218c9215260 100755
;;
@@ -1854,6 +1854,9 @@ for host in "${ALL_HOSTS[@]}"; do
cmake_options=(
"${cmake_options[@]}"
-DLLVM_TABLEGEN=$(build_directory "${LOCAL_HOST}" llvm)/bin/llvm-tblgen
-DSWIFT_INCLUDE_TEST_BINARIES:BOOL=FALSE
+ -DCMAKE_FIND_ROOT_PATH:PATH="${CROSS_COMPILE_DEPS_PATH}"
+ -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER
+ -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY

View File

@ -1,22 +1,8 @@
From 652c51f7c8fb1a90bcec89b060ae923b974c8332
Date: Thu, 15 Apr 2021 02:27:15 +0530
Subject: [PATCH] [build] Allow cross-compiling build-script products for
non-Darwin hosts too
To that end, move the --cross-compile-deps-path flag from build-script-impl to a
publicly documented build-script flag and use it for build-script products'
library dependencies too. Generate a SPM destination JSON file that can be used
both for cross-compiling these build-script products and by users for their own
Swift packages.
Also, make using a prebuilt toolchain explicit and pass an install prefix in to
swift-driver.
diff --git a/swift/utils/build_swift/build_swift/driver_arguments.py b/swift/utils/build_swift/build_swift/driver_arguments.py
index 850c30dce3d86..fcd2f52f349be 100644
index cf2b19a4d7b44..1c153688146d6 100644
--- a/swift/utils/build_swift/build_swift/driver_arguments.py
+++ b/swift/utils/build_swift/build_swift/driver_arguments.py
@@ -558,6 +558,11 @@ def create_argument_parser():
@@ -563,6 +563,11 @@ def create_argument_parser():
help='A space separated list of targets to cross-compile host '
'Swift tools for. Can be used multiple times.')
@ -29,10 +15,10 @@ index 850c30dce3d86..fcd2f52f349be 100644
type=argparse.ShellSplitType(),
default=None,
diff --git a/swift/utils/build_swift/tests/expected_options.py b/swift/utils/build_swift/tests/expected_options.py
index bc0041beea192..fa15ca93bb897 100644
index 31e9a637e982f..e4a748119518d 100644
--- a/swift/utils/build_swift/tests/expected_options.py
+++ b/swift/utils/build_swift/tests/expected_options.py
@@ -128,6 +128,7 @@
@@ -131,6 +131,7 @@
'cmark_build_variant': 'Debug',
'compiler_vendor': defaults.COMPILER_VENDOR,
'coverage_db': None,
@ -40,7 +26,7 @@ index bc0041beea192..fa15ca93bb897 100644
'cross_compile_hosts': [],
'darwin_deployment_version_ios':
defaults.DARWIN_DEPLOYMENT_VERSION_IOS,
@@ -673,6 +674,7 @@ class BuildScriptImplOption(_BaseOption):
@@ -694,6 +695,7 @@ class BuildScriptImplOption(_BaseOption):
PathOption('--clang-profile-instr-use'),
PathOption('--cmake'),
PathOption('--coverage-db'),
@ -49,10 +35,10 @@ index bc0041beea192..fa15ca93bb897 100644
PathOption('--host-cxx'),
PathOption('--host-libtool'),
diff --git a/swift/utils/swift_build_support/swift_build_support/build_script_invocation.py b/swift/utils/swift_build_support/swift_build_support/build_script_invocation.py
index fb1237dd6d6..be697fda761 100644
index 0b127d46c4890..0e9908b72989b 100644
--- a/swift/utils/swift_build_support/swift_build_support/build_script_invocation.py
+++ b/swift/utils/swift_build_support/swift_build_support/build_script_invocation.py
@@ -181,6 +181,10 @@ class BuildScriptInvocation(object):
@@ -181,6 +181,10 @@ def convert_to_impl_arguments(self):
if args.cross_compile_hosts:
impl_args += [
"--cross-compile-hosts", " ".join(args.cross_compile_hosts)]
@ -63,28 +49,98 @@ index fb1237dd6d6..be697fda761 100644
if args.test_paths:
impl_args += ["--test-paths", " ".join(args.test_paths)]
@@ -666,9 +670,14 @@ class BuildScriptInvocation(object):
# Core Lipo...
self._execute_merged_host_lipo_core_action()
@@ -664,12 +668,14 @@ def execute(self):
self._execute_impl(pipeline, all_hosts, perform_epilogue_opts)
else:
assert(index != last_impl_index)
- # Once we have performed our last impl pipeline, we no longer
- # support cross compilation.
- #
- # This just maintains current behavior.
if index > last_impl_index:
- self._execute(pipeline, [self.args.host_target])
+ non_darwin_cross_compile_hostnames = [
+ target for target in self.args.cross_compile_hosts if not
+ StdlibDeploymentTarget.get_target_for_name(
+ target).platform.is_darwin
+ ]
+ self._execute(pipeline, [self.args.host_target] +
+ non_darwin_cross_compile_hostnames)
else:
self._execute(pipeline, all_host_names)
+ non_darwin_cross_compile_hostnames = [
+ target for target in self.args.cross_compile_hosts if not
+ StdlibDeploymentTarget.get_target_for_name(target).platform.is_darwin]
# Non-build-script-impl products...
- # Note: currently only supports building for the host.
- for host_target in [self.args.host_target]:
+ # Note: currently only supports cross-compiling for non-Darwin hosts.
+ for host_target in [self.args.host_target] + non_darwin_cross_compile_hostnames:
@@ -727,6 +733,8 @@ def _execute_impl(self, pipeline, all_hosts, should_run_epilogue_operations):
def _execute(self, pipeline, all_host_names):
for host_target in all_host_names:
+ if self.args.skip_local_build and host_target == self.args.host_target:
+ continue
for product_class in product_classes:
if product_class.is_build_script_impl_product():
continue
for product_class in pipeline:
# Execute clean, build, test, install
self.execute_product_build_steps(product_class, host_target)
diff --git a/swift/utils/swift_build_support/swift_build_support/products/benchmarks.py b/swift/utils/swift_build_support/swift_build_support/products/benchmarks.py
index df3134ecb4194..0ec3f4c897e28 100644
--- a/swift/utils/swift_build_support/swift_build_support/products/benchmarks.py
+++ b/swift/utils/swift_build_support/swift_build_support/products/benchmarks.py
@@ -104,9 +104,7 @@ def _get_toolchain_path(host_target, product, args):
# this logic initially was inside run_build_script_helper
# and was factored out so it can be used in testing as well
- toolchain_path = swiftpm.SwiftPM.get_install_destdir(args,
- host_target,
- product.build_dir)
+ toolchain_path = product.host_install_destdir(host_target)
if platform.system() == 'Darwin':
# The prefix is an absolute path, so concatenate without os.path.
toolchain_path += \
diff --git a/swift/utils/swift_build_support/swift_build_support/products/indexstoredb.py b/swift/utils/swift_build_support/swift_build_support/products/indexstoredb.py
index 28838a443e8dd..af187e9e612ce 100644
--- a/swift/utils/swift_build_support/swift_build_support/products/indexstoredb.py
+++ b/swift/utils/swift_build_support/swift_build_support/products/indexstoredb.py
@@ -80,13 +80,8 @@ def run_build_script_helper(action, host_target, product, args,
script_path = os.path.join(
product.source_dir, 'Utilities', 'build-script-helper.py')
- install_destdir = args.install_destdir
- if swiftpm.SwiftPM.has_cross_compile_hosts(args):
- install_destdir = swiftpm.SwiftPM.get_install_destdir(args,
- host_target,
- product.build_dir)
- toolchain_path = targets.toolchain_path(install_destdir,
- args.install_prefix)
+ install_destdir = product.host_install_destdir(host_target)
+ toolchain_path = product.native_toolchain_path(host_target)
is_release = product.is_release()
configuration = 'release' if is_release else 'debug'
helper_cmd = [
@@ -110,4 +105,22 @@ def run_build_script_helper(action, host_target, product, args,
elif args.enable_tsan:
helper_cmd.extend(['--sanitize', 'thread'])
+ if not product.is_darwin_host(
+ host_target) and product.is_cross_compile_target(host_target):
+ helper_cmd.extend(['--cross-compile-host', host_target])
+ build_toolchain_path = install_destdir + args.install_prefix
+ resource_dir = '%s/lib/swift' % build_toolchain_path
+ helper_cmd += [
+ '--cross-compile-config',
+ targets.StdlibDeploymentTarget.get_target_for_name(host_target).platform
+ .swiftpm_config(args, output_dir=build_toolchain_path,
+ swift_toolchain=toolchain_path,
+ resource_path=resource_dir)
+ ]
+
+ if action == 'install' and product.product_name() == "sourcekitlsp":
+ helper_cmd.extend([
+ '--prefix', install_destdir + args.install_prefix
+ ])
+
shell.call(helper_cmd)
diff --git a/swift/utils/swift_build_support/swift_build_support/products/product.py b/swift/utils/swift_build_support/swift_build_support/products/product.py
index fd202b8cf1738..741353f15ce45 100644
index 405f479546171..2f02322ba1d92 100644
--- a/swift/utils/swift_build_support/swift_build_support/products/product.py
+++ b/swift/utils/swift_build_support/swift_build_support/products/product.py
@@ -195,15 +195,17 @@ def install_toolchain_path(self, host_target):
@@ -195,18 +195,23 @@ def install_toolchain_path(self, host_target):
"""toolchain_path() -> string
Returns the path to the toolchain that is being created as part of this
@ -98,45 +154,69 @@ index fd202b8cf1738..741353f15ce45 100644
if self.args.cross_compile_hosts:
- build_root = os.path.dirname(self.build_dir)
- install_destdir = '%s/intermediate-install/%s' % (build_root, host_target)
+ if targets.StdlibDeploymentTarget.get_target_for_name(
+ host_target).platform.is_darwin:
+ build_root = os.path.dirname(self.build_dir)
+ install_destdir = '%s/intermediate-install/%s' % (build_root,
+ host_target)
+ if self.is_darwin_host(host_target):
+ install_destdir = self.host_install_destdir(host_target)
+ else:
+ install_destdir = os.path.join(install_destdir, self.args.host_target)
return targets.toolchain_path(install_destdir,
self.args.install_prefix)
+ def native_toolchain_path(self, host_target):
+ if self.args.native_swift_tools_path is not None:
+ return os.path.split(self.args.native_swift_tools_path)[0]
+ else:
+ return self.install_toolchain_path(host_target)
+
def is_darwin_host(self, host_target):
return host_target.startswith("macosx") or \
host_target.startswith("iphone") or \
diff --git a/swift/utils/swift_build_support/swift_build_support/products/skstresstester.py b/swift/utils/swift_build_support/swift_build_support/products/skstresstester.py
index 5e753a5624b8f..ea673f0bde5d2 100644
--- a/swift/utils/swift_build_support/swift_build_support/products/skstresstester.py
+++ b/swift/utils/swift_build_support/swift_build_support/products/skstresstester.py
@@ -100,9 +100,7 @@ def should_install(self, host_target):
return self.args.install_skstresstester
def install(self, host_target):
- install_destdir = swiftpm.SwiftPM.get_install_destdir(self.args,
- host_target,
- self.build_dir)
+ install_destdir = self.host_install_destdir(host_target)
install_prefix = install_destdir + self.args.install_prefix
self.run_build_script_helper('install', host_target, [
'--prefix', install_prefix
diff --git a/swift/utils/swift_build_support/swift_build_support/products/swiftdriver.py b/swift/utils/swift_build_support/swift_build_support/products/swiftdriver.py
index 3bd5755de35be..c30b032886d0a 100644
index 3bd5755de35be..a3f04b08c0157 100644
--- a/swift/utils/swift_build_support/swift_build_support/products/swiftdriver.py
+++ b/swift/utils/swift_build_support/swift_build_support/products/swiftdriver.py
@@ -91,8 +91,10 @@ def run_build_script_helper(action, host_target, product, args):
install_destdir = swiftpm.SwiftPM.get_install_destdir(args,
host_target,
product.build_dir)
@@ -86,13 +86,8 @@ def run_build_script_helper(action, host_target, product, args):
script_path = os.path.join(
product.source_dir, 'Utilities', 'build-script-helper.py')
- install_destdir = args.install_destdir
- if swiftpm.SwiftPM.has_cross_compile_hosts(args):
- install_destdir = swiftpm.SwiftPM.get_install_destdir(args,
- host_target,
- product.build_dir)
- toolchain_path = targets.toolchain_path(install_destdir,
- args.install_prefix)
+ if args.native_swift_tools_path is not None:
+ toolchain_path = os.path.split(args.native_swift_tools_path)[0]
+ else:
+ toolchain_path = product.install_toolchain_path(host_target)
+ install_destdir = product.host_install_destdir(host_target)
+ toolchain_path = product.native_toolchain_path(host_target)
# Pass Dispatch directory down if we built it
dispatch_build_dir = os.path.join(
@@ -134,7 +136,29 @@ def run_build_script_helper(action, host_target, product, args):
helper_cmd += [
'--lit-test-dir', lit_test_dir
@@ -134,10 +129,26 @@ def run_build_script_helper(action, host_target, product, args):
]
+ # Pass Cross compile host info
+ if swiftpm.SwiftPM.has_cross_compile_hosts(args):
+ if targets.StdlibDeploymentTarget.get_target_for_name(
+ host_target).platform.is_darwin:
# Pass Cross compile host info
if swiftpm.SwiftPM.has_cross_compile_hosts(args):
- helper_cmd += ['--cross-compile-hosts']
- for cross_compile_host in args.cross_compile_hosts:
- helper_cmd += [cross_compile_host]
+ if product.is_darwin_host(host_target):
+ helper_cmd += ['--cross-compile-hosts']
+ for cross_compile_host in args.cross_compile_hosts:
+ helper_cmd += [cross_compile_host]
+ elif host_target != args.host_target:
+ elif product.is_cross_compile_target(host_target):
+ helper_cmd += ['--cross-compile-hosts', host_target]
+ build_toolchain_path = install_destdir + args.install_prefix
+ resource_dir = '%s/lib/swift' % build_toolchain_path
@ -156,7 +236,7 @@ index 3bd5755de35be..c30b032886d0a 100644
+
shell.call(helper_cmd)
diff --git a/swift/utils/swift_build_support/swift_build_support/products/swiftpm.py b/swift/utils/swift_build_support/swift_build_support/products/swiftpm.py
index 4a97f377ef408..47a893a98ca16 100644
index 4a97f377ef408..57047a439c31d 100644
--- a/swift/utils/swift_build_support/swift_build_support/products/swiftpm.py
+++ b/swift/utils/swift_build_support/swift_build_support/products/swiftpm.py
@@ -23,6 +23,7 @@
@ -167,36 +247,32 @@ index 4a97f377ef408..47a893a98ca16 100644
class SwiftPM(product.Product):
@@ -44,7 +45,11 @@ def should_build(self, host_target):
@@ -44,7 +45,8 @@ def should_build(self, host_target):
def run_bootstrap_script(self, action, host_target, additional_params=[]):
script_path = os.path.join(
self.source_dir, 'Utilities', 'bootstrap')
- toolchain_path = self.install_toolchain_path(host_target)
+
+ if self.args.native_swift_tools_path is not None:
+ toolchain_path = os.path.split(self.args.native_swift_tools_path)[0]
+ else:
+ toolchain_path = self.install_toolchain_path(host_target)
+ toolchain_path = self.native_toolchain_path(host_target)
swiftc = os.path.join(toolchain_path, "bin", "swiftc")
# FIXME: We require llbuild build directory in order to build. Is
@@ -92,9 +97,23 @@ def run_bootstrap_script(self, action, host_target, additional_params=[]):
@@ -92,9 +94,22 @@ def run_bootstrap_script(self, action, host_target, additional_params=[]):
# Pass Cross compile host info
if self.has_cross_compile_hosts(self.args):
- helper_cmd += ['--cross-compile-hosts']
- for cross_compile_host in self.args.cross_compile_hosts:
- helper_cmd += [cross_compile_host]
+ if StdlibDeploymentTarget.get_target_for_name(
+ host_target).platform.is_darwin:
+ if self.is_darwin_host(host_target):
+ helper_cmd += ['--cross-compile-hosts']
+ for cross_compile_host in self.args.cross_compile_hosts:
+ helper_cmd += [cross_compile_host]
+ elif host_target != self.args.host_target:
+ elif self.is_cross_compile_target(host_target):
+ helper_cmd += ['--cross-compile-hosts', host_target,
+ '--skip-cmake-bootstrap']
+ build_toolchain_path = self.get_install_destdir(
+ self.args, host_target, self.build_dir) + self.args.install_prefix
+ build_toolchain_path = self.host_install_destdir(
+ host_target) + self.args.install_prefix
+ resource_dir = '%s/lib/swift' % build_toolchain_path
+ helper_cmd += [
+ '--cross-compile-config',
@ -207,24 +283,28 @@ index 4a97f377ef408..47a893a98ca16 100644
helper_cmd.extend(additional_params)
@@ -126,8 +145,13 @@ def has_cross_compile_hosts(self, args):
def get_install_destdir(self, args, host_target, build_dir):
install_destdir = args.install_destdir
if self.has_cross_compile_hosts(args):
@@ -122,18 +137,8 @@ def should_install(self, host_target):
def has_cross_compile_hosts(self, args):
return args.cross_compile_hosts
- @classmethod
- def get_install_destdir(self, args, host_target, build_dir):
- install_destdir = args.install_destdir
- if self.has_cross_compile_hosts(args):
- build_root = os.path.dirname(build_dir)
- install_destdir = '%s/intermediate-install/%s' % (build_root, host_target)
+ if StdlibDeploymentTarget.get_target_for_name(
+ host_target).platform.is_darwin:
+ build_root = os.path.dirname(build_dir)
+ install_destdir = '%s/intermediate-install/%s' % (
+ build_root, host_target)
+ else:
+ install_destdir = os.path.join(install_destdir, host_target)
return install_destdir
- return install_destdir
-
def install(self, host_target):
- install_destdir = self.get_install_destdir(self.args,
- host_target,
- self.build_dir)
+ install_destdir = self.host_install_destdir(host_target)
install_prefix = install_destdir + self.args.install_prefix
self.run_bootstrap_script('install', host_target, [
diff --git a/swift/utils/swift_build_support/swift_build_support/targets.py b/swift/utils/swift_build_support/swift_build_support/targets.py
index 34364458ec736..b6cedb3908f48 100644
index 05966defe2861..c5a86651bb869 100644
--- a/swift/utils/swift_build_support/swift_build_support/targets.py
+++ b/swift/utils/swift_build_support/swift_build_support/targets.py
@@ -80,6 +80,13 @@ def cmake_options(self, args):
@ -251,7 +331,7 @@ index 34364458ec736..b6cedb3908f48 100644
flags += '-sdk %s/sysroot ' % (android_toolchain_path)
flags += '-tools-directory %s/bin' % (android_toolchain_path)
@@ -171,6 +177,46 @@ def cmake_options(self, args):
@@ -171,6 +177,42 @@ def cmake_options(self, args):
options += '-DCMAKE_ANDROID_NDK:PATH=%s' % (args.android_ndk)
return options
@ -263,11 +343,13 @@ index 34364458ec736..b6cedb3908f48 100644
+ config_file = '%s/swiftpm-android-%s.json' % (output_dir, args.android_arch)
+
+ if os.path.exists(config_file):
+ print("Using existing config at %s" % config_file)
+ return config_file
+
+ spm_json = '{\n'
+ spm_json += ' "version": 1,\n'
+ spm_json += ' "target": "%s-unknown-linux-android",\n' % args.android_arch
+ spm_json += ' "target": "%s-unknown-linux-android%s",\n' % (
+ args.android_arch, args.android_api_level)
+ spm_json += ' "toolchain-bin-dir": "%s/bin",\n' % swift_toolchain
+ spm_json += ' "sdk": "%s/sysroot",\n' % self.ndk_toolchain_path(args)
+
@ -279,13 +361,7 @@ index 34364458ec736..b6cedb3908f48 100644
+ spm_json += ' "-tools-directory", "%s/bin",\n' % (
+ self.ndk_toolchain_path(args))
+ spm_json += ' "-Xcc", "-I%s/usr/include",\n' % args.cross_compile_deps_path
+ spm_json += ' "-L%s/usr/lib",\n' % args.cross_compile_deps_path
+ spm_json += ' "-L%s/lib/gcc/%s-linux-android%s/%s.x/%s"\n' % (
+ self.ndk_toolchain_path(args),
+ args.android_arch if not args.android_arch == 'armv7' else 'arm',
+ '' if not args.android_arch == 'armv7' else 'eabi',
+ args.android_ndk_gcc_version,
+ '' if not args.android_arch == 'armv7' else 'armv7-a')
+ spm_json += ' "-L%s/usr/lib"\n' % args.cross_compile_deps_path
+ spm_json += ' ],\n'
+
+ spm_json += ' "extra-cpp-flags": [ "-lstdc++" ]\n'

View File

@ -1,37 +0,0 @@
--- a/swift/utils/swift_build_support/swift_build_support/products/indexstoredb.py 2021-08-07 01:42:42.000000000 +0000
+++ b/swift/utils/swift_build_support/swift_build_support/products/indexstoredb.py 2021-08-20 21:38:31.566330389 +0000
@@ -81,8 +81,10 @@
install_destdir = swiftpm.SwiftPM.get_install_destdir(args,
host_target,
product.build_dir)
- toolchain_path = targets.toolchain_path(install_destdir,
- args.install_prefix)
+ if args.native_swift_tools_path is not None:
+ toolchain_path = os.path.split(args.native_swift_tools_path)[0]
+ else:
+ toolchain_path = product.install_toolchain_path(host_target)
is_release = product.is_release()
configuration = 'release' if is_release else 'debug'
helper_cmd = [
@@ -106,4 +108,21 @@
elif args.enable_tsan:
helper_cmd.extend(['--sanitize', 'thread'])
+ if swiftpm.SwiftPM.has_cross_compile_hosts(args) and host_target != args.host_target:
+ helper_cmd.extend(['--cross-compile-host', host_target])
+ build_toolchain_path = install_destdir + args.install_prefix
+ resource_dir = '%s/lib/swift' % build_toolchain_path
+ helper_cmd += [
+ '--cross-compile-config',
+ targets.StdlibDeploymentTarget.get_target_for_name(host_target).platform
+ .swiftpm_config(args, output_dir=build_toolchain_path,
+ swift_toolchain=toolchain_path,
+ resource_path=resource_dir)
+ ]
+
+ if action == 'install':
+ helper_cmd.extend([
+ '--prefix', install_destdir + args.install_prefix
+ ])
+
shell.call(helper_cmd)

View File

@ -0,0 +1,39 @@
diff --git a/swift/utils/swift_build_support/swift_build_support/targets.py b/swift/utils/swift_build_support/swift_build_support/targets.py
index 7ebcdc070c1..5a6ed88182e 100644
--- a/swift/utils/swift_build_support/swift_build_support/targets.py
+++ b/swift/utils/swift_build_support/swift_build_support/targets.py
@@ -166,6 +166,7 @@ class AndroidPlatform(Platform):
flags += '-sdk %s/sysroot ' % (android_toolchain_path)
flags += '-tools-directory %s/bin' % (android_toolchain_path)
+ flags += ' -Xlinker -rpath -Xlinker @TERMUX_PREFIX@/lib'
return flags
def cmake_options(self, args):
@@ -174,8 +175,7 @@ class AndroidPlatform(Platform):
return options
def ndk_toolchain_path(self, args):
- return '%s/toolchains/llvm/prebuilt/%s' % (
- args.android_ndk, StdlibDeploymentTarget.host_target().name)
+ return args.android_ndk
def swiftpm_config(self, args, output_dir, swift_toolchain, resource_path):
config_file = '%s/swiftpm-android-%s.json' % (output_dir, args.android_arch)
@@ -190,7 +190,7 @@ class AndroidPlatform(Platform):
spm_json += ' "version": 1,\n'
spm_json += ' "target": "%s-unknown-linux-android%s",\n' % (
args.android_arch, args.android_api_level)
- spm_json += ' "toolchain-bin-dir": "%s/bin",\n' % swift_toolchain
+ spm_json += ' "toolchain-bin-dir": "%s/bin",\n' % args.android_ndk
spm_json += ' "sdk": "%s/sysroot",\n' % self.ndk_toolchain_path(args)
spm_json += ' "extra-cc-flags": [ "-fPIC", "-I%s/usr/include" ],\n' % (
@@ -203,6 +203,7 @@ class AndroidPlatform(Platform):
spm_json += ' "-tools-directory", "%s/bin",\n' % (
self.ndk_toolchain_path(args))
spm_json += ' "-Xcc", "-I%s/usr/include",\n' % args.cross_compile_deps_path
+ spm_json += ' "-Xlinker", "-rpath", "-Xlinker", "@TERMUX_PREFIX@/lib",\n'
spm_json += ' "-L%s/usr/lib"\n' % args.cross_compile_deps_path
spm_json += ' ],\n'

View File

@ -30,9 +30,22 @@ diff --git a/sourcekit-lsp/Utilities/build-script-helper.py b/sourcekit-lsp/Util
swiftpm_args += ['-Xswiftc', '-no-toolchain-stdlib-rpath']
- swiftpm('build', swift_exec, swiftpm_args, env)
+ swiftpm('build', swiftpm_exec, swiftpm_args, env)
install(bin_path, args.install_prefixes if not None else [args.toolchain], args.toolchain)
else:
assert False, 'unknown action \'{}\''.format(args.action)
if not args.install_prefixes:
args.install_prefixes = [args.toolchain]
diff --git a/swift/utils/swift_build_support/swift_build_support/products/product.py b/swift/utils/swift_build_support/swift_build_support/products/product.py
index 575fa374ad..3554577f92 100644
--- a/swift/utils/swift_build_support/swift_build_support/products/product.py
+++ b/swift/utils/swift_build_support/swift_build_support/products/product.py
@@ -202,7 +202,7 @@ class Product(object):
if self.is_darwin_host(host_target):
install_destdir = self.host_install_destdir(host_target)
else:
- install_destdir = os.path.join(install_destdir, self.args.host_target)
+ return os.path.join(os.path.dirname(self.build_dir), "swift-%s" % self.args.host_target)
return targets.toolchain_path(install_destdir,
self.args.install_prefix)
diff --git a/swift-driver/Utilities/build-script-helper.py b/swift-driver/Utilities/build-script-helper.py
--- a/swift-driver/Utilities/build-script-helper.py
+++ b/swift-driver/Utilities/build-script-helper.py

View File

@ -1,81 +0,0 @@
diff --git a/swift/utils/swift_build_support/swift_build_support/products/product.py b/swift/utils/swift_build_support/swift_build_support/products/product.py
index 741353f15ce..e54e211b705 100644
--- a/swift/utils/swift_build_support/swift_build_support/products/product.py
+++ b/swift/utils/swift_build_support/swift_build_support/products/product.py
@@ -202,7 +202,7 @@
install_destdir = '%s/intermediate-install/%s' % (build_root,
host_target)
else:
- install_destdir = os.path.join(install_destdir, self.args.host_target)
+ return os.path.join(os.path.dirname(self.build_dir), "swift-%s" % self.args.host_target)
return targets.toolchain_path(install_destdir,
self.args.install_prefix)
diff --git a/swift/utils/swift_build_support/swift_build_support/products/swiftpm.py b/swift/utils/swift_build_support/swift_build_support/products/swiftpm.py
index 81460b3ba6d..46a43b4acdd 100644
--- a/swift/utils/swift_build_support/swift_build_support/products/swiftpm.py
+++ b/swift/utils/swift_build_support/swift_build_support/products/swiftpm.py
@@ -146,8 +146,6 @@ class SwiftPM(product.Product):
build_root = os.path.dirname(build_dir)
install_destdir = '%s/intermediate-install/%s' % (
build_root, host_target)
- else:
- install_destdir = os.path.join(install_destdir, host_target)
return install_destdir
def install(self, host_target):
diff --git a/swift/utils/swift_build_support/swift_build_support/targets.py b/swift/utils/swift_build_support/swift_build_support/targets.py
index 7ebcdc070c1..5a6ed88182e 100644
--- a/swift/utils/swift_build_support/swift_build_support/targets.py
+++ b/swift/utils/swift_build_support/swift_build_support/targets.py
@@ -166,6 +166,7 @@ class AndroidPlatform(Platform):
flags += '-sdk %s/sysroot ' % (android_toolchain_path)
flags += '-tools-directory %s/bin' % (android_toolchain_path)
+ flags += ' -use-ld=lld -Xlinker -rpath -Xlinker @TERMUX_PREFIX@/lib'
return flags
def cmake_options(self, args):
@@ -174,12 +175,11 @@ class AndroidPlatform(Platform):
options += '-DCMAKE_SYSTEM_PROCESSOR=%s ' % (args.android_arch if not
args.android_arch == 'armv7'
else 'armv7-a')
- options += '-DCMAKE_ANDROID_NDK:PATH=%s' % (args.android_ndk)
+ options += '-DCMAKE_ANDROID_STANDALONE_TOOLCHAIN:PATH=%s' % (args.android_ndk)
return options
def ndk_toolchain_path(self, args):
- return '%s/toolchains/llvm/prebuilt/%s' % (
- args.android_ndk, StdlibDeploymentTarget.host_target().name)
+ return args.android_ndk
def swiftpm_config(self, args, output_dir, swift_toolchain, resource_path):
config_file = '%s/swiftpm-android-%s.json' % (output_dir, args.android_arch)
@@ -190,24 +190,16 @@ class AndroidPlatform(Platform):
spm_json = '{\n'
spm_json += ' "version": 1,\n'
spm_json += ' "target": "%s-unknown-linux-android",\n' % args.android_arch
- spm_json += ' "toolchain-bin-dir": "%s/bin",\n' % swift_toolchain
+ spm_json += ' "toolchain-bin-dir": "%s/bin",\n' % args.android_ndk
spm_json += ' "sdk": "%s/sysroot",\n' % self.ndk_toolchain_path(args)
- spm_json += ' "extra-cc-flags": [ "-fPIC", "-I%s/usr/include" ],\n' % (
- args.cross_compile_deps_path)
+ spm_json += ' "extra-cc-flags": [ "-fPIC" ],\n'
spm_json += ' "extra-swiftc-flags": [\n'
spm_json += ' "-resource-dir", "%s",\n' % resource_path
spm_json += ' "-tools-directory", "%s/bin",\n' % (
self.ndk_toolchain_path(args))
- spm_json += ' "-Xcc", "-I%s/usr/include",\n' % args.cross_compile_deps_path
- spm_json += ' "-L%s/usr/lib",\n' % args.cross_compile_deps_path
- spm_json += ' "-L%s/lib/gcc/%s-linux-android%s/%s.x/%s"\n' % (
- self.ndk_toolchain_path(args),
- args.android_arch if not args.android_arch == 'armv7' else 'arm',
- '' if not args.android_arch == 'armv7' else 'eabi',
- args.android_ndk_gcc_version,
- '' if not args.android_arch == 'armv7' else 'armv7-a')
+ spm_json += ' "-use-ld=lld", "-L%s/usr/lib"\n' % args.cross_compile_deps_path
spm_json += ' ],\n'
spm_json += ' "extra-cpp-flags": [ "-lstdc++" ]\n'

View File

@ -1,91 +0,0 @@
commit 74a8de7bccc0c40381b63a79143d4ca945c0ed68
Date: Thu Aug 5 23:30:59 2021 +0530
Change the order of Workspace toolchain C/Swift flags to match the command-line (#3636)
* Move Workspace UserToolchain C/Swift flags to just before the command-line flags,
so both are after the package's internal flags.
This makes sure internal package paths are searched first, before external flags
are applied.
diff --git a/swiftpm/Sources/Build/BuildPlan.swift b/swiftpm/Sources/Build/BuildPlan.swift
index 78072f5b..fb78b54f 100644
--- a/swiftpm/Sources/Build/BuildPlan.swift
+++ b/swiftpm/Sources/Build/BuildPlan.swift
@@ -330,7 +330,6 @@ public final class ClangTargetBuildDescription {
args += ["-fobjc-arc"]
}
args += buildParameters.targetTripleArgs(for: target)
- args += buildParameters.toolchain.extraCCFlags
args += ["-g"]
if buildParameters.triple.isWindows() {
args += ["-gcodeview"]
@@ -373,6 +372,7 @@ public final class ClangTargetBuildDescription {
args += ["-include", resourceAccessorHeaderFile.pathString]
}
+ args += buildParameters.toolchain.extraCCFlags
// User arguments (from -Xcc and -Xcxx below) should follow generated arguments to allow user overrides
args += buildParameters.flags.cCompilerFlags
@@ -724,7 +724,6 @@ public final class SwiftTargetBuildDescription {
}
args += buildParameters.indexStoreArguments(for: target)
- args += buildParameters.toolchain.extraSwiftCFlags
args += optimizationArguments
args += testingArguments
args += ["-g"]
@@ -791,6 +790,7 @@ public final class SwiftTargetBuildDescription {
args += ["-emit-module-interface-path", parseableModuleInterfaceOutputPath.pathString]
}
+ args += buildParameters.toolchain.extraSwiftCFlags
// User arguments (from -Xswiftc) should follow generated arguments to allow user overrides
args += buildParameters.swiftCompilerFlags
return args
@@ -907,7 +907,6 @@ public final class SwiftTargetBuildDescription {
result += ["-swift-version", swiftVersion.rawValue]
result += buildParameters.indexStoreArguments(for: target)
- result += buildParameters.toolchain.extraSwiftCFlags
result += optimizationArguments
result += testingArguments
result += ["-g"]
@@ -919,6 +918,7 @@ public final class SwiftTargetBuildDescription {
result += buildParameters.sanitizers.compileSwiftFlags()
result += ["-parseable-output"]
result += self.buildSettingsFlags()
+ result += buildParameters.toolchain.extraSwiftCFlags
result += buildParameters.swiftCompilerFlags
return result
}
@@ -1165,7 +1165,6 @@ public final class ProductBuildDescription {
/// The arguments to link and create this product.
public func linkArguments() throws -> [String] {
var args = [buildParameters.toolchain.swiftCompiler.pathString]
- args += buildParameters.toolchain.extraSwiftCFlags
args += buildParameters.sanitizers.linkSwiftFlags()
args += additionalFlags
@@ -1286,6 +1285,7 @@ public final class ProductBuildDescription {
// building for Darwin in debug configuration.
args += swiftASTs.flatMap{ ["-Xlinker", "-add_ast_path", "-Xlinker", $0.pathString] }
+ args += buildParameters.toolchain.extraSwiftCFlags
// User arguments (from -Xlinker and -Xswiftc) should follow generated arguments to allow user overrides
args += buildParameters.linkerFlags
args += stripInvalidArguments(buildParameters.swiftCompilerFlags)
diff --git a/swiftpm/Utilities/bootstrap b/swiftpm/Utilities/bootstrap
index 1f673fdd..e51616cb 100755
--- a/swiftpm/Utilities/bootstrap
+++ b/swiftpm/Utilities/bootstrap
@@ -800,6 +800,7 @@ def get_swiftpm_flags(args):
if 'ANDROID_DATA' in os.environ or (args.cross_compile_hosts and re.match(
'android-', args.cross_compile_hosts)):
build_flags.extend(["-Xswiftc", "-Xcc", "-Xswiftc", "-U_GNU_SOURCE"])
+ build_flags.extend(["-Xlinker", "-landroid-spawn"])
# On ELF platforms, remove the host toolchain's stdlib absolute rpath from
# installed executables and shared libraries.

View File

@ -1,37 +0,0 @@
--- a/sourcekit-lsp/Utilities/build-script-helper.py
+++ b/sourcekit-lsp/Utilities/build-script-helper.py
@@ -66,7 +66,7 @@
]
if args.cross_compile_host:
- swiftpm_args += ['--destination', args.cross_compile_config]
+ swiftpm_args += ['--destination', args.cross_compile_config, '-Xcc', '-I@TERMUX_PREFIX@/include', '-Xswiftc', '-Xclang-linker', '-Xswiftc', '--target=@CCTERMUX_HOST_PLATFORM@', '-Xlinker', '-rpath', '-Xlinker', '@TERMUX_PREFIX@/lib']
return swiftpm_args
diff --git a/swiftpm/Utilities/bootstrap b/swiftpm/Utilities/bootstrap
index 1f673fdd..e51616cb 100755
--- a/swiftpm/Utilities/bootstrap
+++ b/swiftpm/Utilities/bootstrap
@@ -811,7 +812,7 @@ def get_swiftpm_flags(args):
if build_target == 'x86_64-apple-macosx' and "macosx-arm64" in cross_compile_hosts:
build_flags += ["--arch", "x86_64", "--arch", "arm64"]
elif cross_compile_hosts and re.match('android-', cross_compile_hosts):
- build_flags.extend(["--destination", args.cross_compile_config])
+ build_flags.extend(["--destination", args.cross_compile_config, "-Xcc", "-I@TERMUX_PREFIX@/include", "-Xswiftc", "-Xclang-linker", "-Xswiftc", "--target=@CCTERMUX_HOST_PLATFORM@", "-Xlinker", "-rpath", "-Xlinker", "@TERMUX_PREFIX@/lib"])
elif cross_compile_hosts:
error("cannot cross-compile for %s" % cross_compile_hosts)
diff --git a/swift-driver/Utilities/build-script-helper.py b/swift-driver/Utilities/build-script-helper.py
index 91a8d57..48bffd6 100755
--- a/swift-driver/Utilities/build-script-helper.py
+++ b/swift-driver/Utilities/build-script-helper.py
@@ -98,7 +98,7 @@ def get_swiftpm_options(args):
]
if args.cross_compile_hosts:
- swiftpm_args += [ '--destination', args.cross_compile_config ]
+ swiftpm_args += [ '--destination', args.cross_compile_config, '-Xcc', '-I@TERMUX_PREFIX@/include', '-Xswiftc', '-Xclang-linker', '-Xswiftc', '--target=@CCTERMUX_HOST_PLATFORM@', '-Xlinker', '-rpath', '-Xlinker', '@TERMUX_PREFIX@/lib']
if 'ANDROID_DATA' in os.environ or (args.cross_compile_hosts and re.match(
'android-', args.cross_compile_hosts[0])):

View File

@ -1,83 +0,0 @@
diff --git a/swift-tools-support-core/Sources/TSCUtility/Triple.swift b/swift-tools-support-core/Sources/TSCUtility/Triple.swift
index 449a21f..87e70b5 100644
--- a/swift-tools-support-core/Sources/TSCUtility/Triple.swift
+++ b/swift-tools-support-core/Sources/TSCUtility/Triple.swift
@@ -27,6 +27,8 @@ public struct Triple: Encodable, Equatable {
public let vendor: Vendor
public let os: OS
public let abi: ABI
+ public let osVersion: String?
+ public let abiVersion: String?
public enum Error: Swift.Error {
case badFormat
@@ -83,13 +85,18 @@ public struct Triple: Encodable, Equatable {
throw Error.unknownOS
}
+ let osVersion = Triple.parseVersion(components[2])
+
let abi = components.count > 3 ? Triple.parseABI(components[3]) : nil
+ let abiVersion = components.count > 3 ? Triple.parseVersion(components[3]) : nil
self.tripleString = string
self.arch = arch
self.vendor = vendor
self.os = os
+ self.osVersion = osVersion
self.abi = abi ?? .unknown
+ self.abiVersion = abiVersion
}
fileprivate static func parseOS(_ string: String) -> OS? {
@@ -100,6 +107,15 @@ public struct Triple: Encodable, Equatable {
return nil
}
+ fileprivate static func parseVersion(_ string: String) -> String? {
+ let candidate = String(string.drop(while: { $0.isLetter }))
+ if candidate != string && !candidate.isEmpty {
+ return candidate
+ }
+
+ return nil
+ }
+
fileprivate static func parseABI(_ string: String) -> ABI? {
if string.hasPrefix(ABI.android.rawValue) {
return ABI.android
@@ -132,18 +148,18 @@ public struct Triple: Encodable, Equatable {
/// This is currently meant for Apple platforms only.
public func tripleString(forPlatformVersion version: String) -> String {
precondition(isDarwin())
- return self.tripleString + version
+ return String(self.tripleString.dropLast(self.osVersion?.count ?? 0)) + version
}
public static let macOS = try! Triple("x86_64-apple-macosx")
- /// Determine the host triple using the Swift compiler.
+ /// Determine the versioned host triple using the Swift compiler.
public static func getHostTriple(usingSwiftCompiler swiftCompiler: AbsolutePath) -> Triple {
do {
let result = try Process.popen(args: swiftCompiler.pathString, "-print-target-info")
let output = try result.utf8Output().spm_chomp()
let targetInfo = try JSON(string: output)
- let tripleString: String = try targetInfo.get("target").get("unversionedTriple")
+ let tripleString: String = try targetInfo.get("target").get("triple")
return try Triple(tripleString)
} catch {
// FIXME: Remove the macOS special-casing once the latest version of Xcode comes with
diff --git a/swiftpm/Utilities/bootstrap b/swiftpm/Utilities/bootstrap
index 6ae084e9..2f3f99e0 100755
--- a/swiftpm/Utilities/bootstrap
+++ b/swiftpm/Utilities/bootstrap
@@ -289,7 +289,7 @@ def get_build_target(args, cross_compile=False):
target_info_json = subprocess.check_output(command,
stderr=subprocess.PIPE, universal_newlines=True).strip()
args.target_info = json.loads(target_info_json)
- return args.target_info["target"]["unversionedTriple"]
+ return args.target_info["target"]["triple"]
except Exception as e:
# Temporary fallback for Darwin.
if platform.system() == 'Darwin':