From 72767ca5ae1953335ece74be4ca18626e7f54ae5 Mon Sep 17 00:00:00 2001 From: Butta Date: Wed, 29 Sep 2021 18:57:59 +0530 Subject: [PATCH] swift: get new Concurrency library working, by compiling it with the Swift-forked clang instead of the NDK clang Also, adjust some linker config and libraries to work with this new clang config. --- packages/swift/build.sh | 3 ++- packages/swift/swift-cmake.patch | 26 +++++++++++++++++-- .../swift/swift-standalone-toolchain.patch | 8 ++++-- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/packages/swift/build.sh b/packages/swift/build.sh index 7b242683c..c53b75664 100644 --- a/packages/swift/build.sh +++ b/packages/swift/build.sh @@ -3,6 +3,7 @@ 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 +TERMUX_PKG_REVISION=1 SWIFT_RELEASE="RELEASE" TERMUX_PKG_SRCURL=https://github.com/apple/swift/archive/swift-$TERMUX_PKG_VERSION-$SWIFT_RELEASE.tar.gz TERMUX_PKG_SHA256=0f76c429e65f24d48a2a18b18e7b380a5c97be0d4370271ac3623e436332fd35 @@ -144,7 +145,7 @@ termux_step_make() { --cross-compile-hosts=android-$SWIFT_ARCH --cross-compile-deps-path=$(dirname $TERMUX_PREFIX) --native-swift-tools-path=$SWIFT_BINDIR - --native-clang-tools-path=$TERMUX_STANDALONE_TOOLCHAIN/bin" + --native-clang-tools-path=$SWIFT_BINDIR" fi SWIFT_BUILD_ROOT=$TERMUX_PKG_BUILDDIR $TERMUX_PKG_SRCDIR/swift/utils/build-script \ diff --git a/packages/swift/swift-cmake.patch b/packages/swift/swift-cmake.patch index a7a99c753..2a0cc0f27 100644 --- a/packages/swift/swift-cmake.patch +++ b/packages/swift/swift-cmake.patch @@ -48,7 +48,7 @@ diff --git a/swift/stdlib/public/Concurrency/CMakeLists.txt b/swift/stdlib/publi index 3313f56c8a6..59804ff6228 100644 --- a/swift/stdlib/public/Concurrency/CMakeLists.txt +++ b/swift/stdlib/public/Concurrency/CMakeLists.txt -@@ -27,8 +27,8 @@ if(SWIFT_CONCURRENCY_USES_DISPATCH) +@@ -24,20 +24,11 @@ if(SWIFT_CONCURRENCY_USES_DISPATCH) # FIXME: we can't rely on libdispatch having been built for the # target at this point in the process. Currently, we're relying # on soft-linking. @@ -59,6 +59,18 @@ index 3313f56c8a6..59804ff6228 100644 endif() endif() +-# Linux requires us to link an atomic library to use atomics. +-# Frustratingly, in many cases this isn't necessary because the +-# sequence is inlined, but we have some code that's just subtle +-# enough to turn into runtime calls. +-if(SWIFT_HOST_VARIANT STREQUAL "android") +- list(APPEND SWIFT_RUNTIME_CONCURRENCY_SWIFT_LINK_FLAGS +- -latomic) +-endif() +- + add_swift_target_library(swift_Concurrency ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_STDLIB + ../CompatibilityOverride/CompatibilityOverride.cpp + Actor.cpp @@ -87,6 +87,6 @@ add_swift_target_library(swift_Concurrency ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} I -Xfrontend -enable-experimental-concurrency -Xfrontend -define-availability @@ -108,12 +120,22 @@ diff --git a/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake b/swift/stdlib/cmak index 38191b01a64..1f851d3409c 100644 --- a/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake +++ b/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake -@@ -397,6 +397,9 @@ function(_add_target_variant_link_flags) +@@ -96,7 +96,7 @@ function(_add_target_variant_c_compile_link_flags) + 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") ++ if(NOT SWIFT_USE_LINKER STREQUAL "lld" OR "${CFLAGS_ARCH}" STREQUAL "x86_64") + swift_android_tools_path(${CFLAGS_ARCH} tools_path) + list(APPEND result "-B" "${tools_path}") + endif() +@@ -397,6 +397,10 @@ function(_add_target_variant_link_flags) list(APPEND result "-Wl,-Bsymbolic") elseif("${LFLAGS_SDK}" STREQUAL "ANDROID") list(APPEND link_libraries "dl" "log") + if(LFLAGS_ARCH STREQUAL "armv7") + list(APPEND link_libraries "atomic") ++ list(APPEND library_search_directories "${SWIFT_SDK_ANDROID_ARCH_${arch}_PATH}/../${SWIFT_SDK_ANDROID_ARCH_${arch}_NDK_TRIPLE}/lib/armv7-a") + endif() # We need to add the math library, which is linked implicitly by libc++ list(APPEND result "-lm") diff --git a/packages/swift/swift-standalone-toolchain.patch b/packages/swift/swift-standalone-toolchain.patch index 529ebc751..cef8ea630 100644 --- a/packages/swift/swift-standalone-toolchain.patch +++ b/packages/swift/swift-standalone-toolchain.patch @@ -11,12 +11,16 @@ index c8d224c958..9b0b9043af 100644 elseif(NOT "${SWIFT_ANDROID_NATIVE_SYSROOT}" STREQUAL "") set(${sysroot_var_name} "${SWIFT_ANDROID_NATIVE_SYSROOT}" PARENT_SCOPE) else() -@@ -36,7 +36,7 @@ function(swift_android_tools_path arch path_var_name) +@@ -44,7 +44,11 @@ function(swift_android_tools_path arch path_var_name) "${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) -+ set(${path_var_name} "${SWIFT_ANDROID_NDK_PATH}/${SWIFT_SDK_ANDROID_ARCH_${arch}_NDK_TRIPLE}/bin" PARENT_SCOPE) ++ if("${arch}" STREQUAL "armv7") ++ set(${path_var_name} "${SWIFT_ANDROID_NDK_PATH}/${SWIFT_SDK_ANDROID_ARCH_${arch}_NDK_TRIPLE}/bin" PARENT_SCOPE) ++ elseif("${arch}" STREQUAL "x86_64") ++ set(${path_var_name} "${SWIFT_ANDROID_NDK_PATH}/bin" PARENT_SCOPE) ++ endif() elseif(NOT "${SWIFT_ANDROID_NATIVE_SYSROOT}" STREQUAL "") set(${path_var_name} "${SWIFT_ANDROID_NATIVE_SYSROOT}/usr/bin" PARENT_SCOPE) else()