From 4923b42d0b7e3238e082d4f4994908c796f3ac7f Mon Sep 17 00:00:00 2001 From: Volodymyr Boichentsov Date: Sun, 30 Jul 2023 19:03:17 +0100 Subject: [PATCH] update to swift 5.8.1 --- cmake_caches.cmake | 1 + setup.sh | 56 +++++++++++++++++++++------------------------- swift-build.sh | 2 +- swiftpm.sh | 21 ++++++++++++++--- 4 files changed, 45 insertions(+), 35 deletions(-) diff --git a/cmake_caches.cmake b/cmake_caches.cmake index eb270e4..f08dd1e 100644 --- a/cmake_caches.cmake +++ b/cmake_caches.cmake @@ -34,6 +34,7 @@ endif() # Make a list that we then convert to a (space-delimited) string, below set(SWIFT_FLAGS + -L${SWIFT_SDK}/usr/lib/${ANDROID_TOOLCHAIN_NAME} -g # always produce debug symbols -sdk ${ANDROID_NDK}/toolchains/llvm/prebuilt/${ANDROID_HOST_TAG}/sysroot -resource-dir ${SWIFT_SDK}/usr/lib/swift diff --git a/setup.sh b/setup.sh index 972aaf9..3cb45ce 100644 --- a/setup.sh +++ b/setup.sh @@ -12,7 +12,7 @@ then fi readonly SDK_DIR="${SCRIPT_ROOT}/sdk" -readonly TOOLCHAIN_PATH="${TOOLCHAIN_PATH:-/Library/Developer/Toolchains/swift-5.7-RELEASE.xctoolchain}" +readonly TOOLCHAIN_PATH="${TOOLCHAIN_PATH:-/Library/Developer/Toolchains/swift-5.8.1-RELEASE.xctoolchain}" for LAST_ARGUMENT in $@; do :; done readonly PROJECT_DIRECTORY=${LAST_ARGUMENT:-$PWD} @@ -20,7 +20,8 @@ readonly BUILD_DIR="${PROJECT_DIRECTORY}/build/${ANDROID_ABI}" readonly LIBRARY_OUTPUT_DIRECTORY="${LIBRARY_OUTPUT_DIRECTORY:-${PROJECT_DIRECTORY}/libs/${ANDROID_ABI}}" readonly CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-"Debug"} -readonly SWIFT_SDK_PATH="${SCRIPT_ROOT}/sdk/${ANDROID_ABI}" +readonly SDK_DIRNAME=swift-android +readonly SWIFT_SDK_PATH="${SCRIPT_ROOT}/sdk/${SDK_DIRNAME}" readonly HOST=darwin-x86_64 # TODO: add more platforms copySwiftDependencyLibs() { @@ -65,8 +66,8 @@ fi if [ ! -d ${TOOLCHAIN_PATH} ] then - echo "Please install the swift-5.7-RELEASE toolchain (or set TOOLCHAIN_PATH)" - echo "On Mac: https://download.swift.org/swift-5.7-release/xcode/swift-5.7-RELEASE/swift-5.7-RELEASE-osx.pkg" + echo "Please install the swift-5.8.1-RELEASE toolchain (or set TOOLCHAIN_PATH)" + echo "On Mac: https://download.swift.org/swift-5.8.1-release/xcode/swift-5.8.1-RELEASE/swift-5.8.1-RELEASE-osx.pkg" exit 1 fi @@ -80,30 +81,23 @@ fi downloadSdks() { [ ! -d ${SDK_DIR} ] && mkdir -p ${SDK_DIR} pushd ${SDK_DIR} > /dev/null + + local ORIGINAL_FILENAME="swift-5.8-android-24-sdk" - for SDK in aarch64 armv7 x86_64 - do - local SDK_DIRNAME=${SDK}; - [ ${SDK} = "aarch64" ] && SDK_DIRNAME=arm64-v8a - [ ${SDK} = "armv7" ] && SDK_DIRNAME=armeabi-v7a - - local ORIGINAL_FILENAME="swift-5.7-android-${SDK}-24-sdk" - - if [ ! -f "${ORIGINAL_FILENAME}.tar.xz" ] - then - log "Downloading ${SDK_DIRNAME} SDK..." - local SDK_URL_BASEPATH="https://github.com/buttaface/swift-android-sdk/releases/download/5.7" - curl -LO ${SDK_URL_BASEPATH}/${ORIGINAL_FILENAME}.tar.xz - fi - - if [ ! -d "${SDK_DIRNAME}" ] - then - log "Extracting ${SDK_DIRNAME} SDK..." - tar --extract --file ${ORIGINAL_FILENAME}.tar.xz - # rm ${ORIGINAL_FILENAME}.tar.xz - mv ${ORIGINAL_FILENAME} ${SDK_DIRNAME} - fi - done + if [ ! -f "${ORIGINAL_FILENAME}.tar.xz" ] + then + log "Downloading ${SDK_DIRNAME} SDK..." + local SDK_URL_BASEPATH="https://github.com/buttaface/swift-android-sdk/releases/download/5.8" + curl -LO ${SDK_URL_BASEPATH}/${ORIGINAL_FILENAME}.tar.xz + fi + + if [ ! -d "${SDK_DIRNAME}" ] + then + log "Extracting ${SDK_DIRNAME} SDK..." + tar --extract --file ${ORIGINAL_FILENAME}.tar.xz + # rm ${ORIGINAL_FILENAME}.tar.xz + mv ${ORIGINAL_FILENAME} ${SDK_DIRNAME} + fi popd > /dev/null } @@ -111,17 +105,17 @@ downloadSdks() { downloadSdks # dynamic resources -if [ ! -f "${SCRIPT_ROOT}/sdk/${ANDROID_ABI}/usr/lib/swift/clang" ] +if [ ! -f "${SCRIPT_ROOT}/sdk/${SDK_DIRNAME}/usr/lib/swift/clang" ] then ln -fs \ ${ANDROID_NDK_PATH}/toolchains/llvm/prebuilt/${HOST}/lib64/clang/14.0.6 \ - ${SCRIPT_ROOT}/sdk/${ANDROID_ABI}/usr/lib/swift/clang + ${SCRIPT_ROOT}/sdk/${SDK_DIRNAME}/usr/lib/swift/clang fi # static resources -if [ ! -f "${SCRIPT_ROOT}/sdk/${ANDROID_ABI}/usr/lib/swift_static/clang" ] +if [ ! -f "${SCRIPT_ROOT}/sdk/${SDK_DIRNAME}/usr/lib/swift_static/clang" ] then ln -fs \ ${ANDROID_NDK_PATH}/toolchains/llvm/prebuilt/${HOST}/lib64/clang/14.0.6 \ - ${SCRIPT_ROOT}/sdk/${ANDROID_ABI}/usr/lib/swift_static/clang + ${SCRIPT_ROOT}/sdk/${SDK_DIRNAME}/usr/lib/swift_static/clang fi diff --git a/swift-build.sh b/swift-build.sh index 833f83d..f861b0e 100755 --- a/swift-build.sh +++ b/swift-build.sh @@ -8,7 +8,7 @@ source "${SCRIPT_ROOT}/setup.sh" if [ ! -d ${TOOLCHAIN_PATH} ] then echo "Please install the swift-5.7-RELEASE toolchain (or set TOOLCHAIN_PATH)" - echo "On Mac: https://download.swift.org/swift-5.7-release/xcode/swift-5.7-RELEASE/swift-5.7-RELEASE-osx.pkg" + echo "On Mac: https://download.swift.org/swift-5.8.1-release/xcode/swift-5.8.1-RELEASE/swift-5.8.1-RELEASE-osx.pkg" exit 1 fi diff --git a/swiftpm.sh b/swiftpm.sh index 7c6a61b..80b5443 100755 --- a/swiftpm.sh +++ b/swiftpm.sh @@ -5,6 +5,7 @@ set -e readonly SCRIPT_ROOT=$(cd $(dirname $0); echo -n $PWD) # path of this file source "${SCRIPT_ROOT}/setup.sh" +# readonly SDK_DIRNAME=swift-android readonly BUILD_TYPE=${BUILD_TYPE:-release} readonly SCRATCH_PATH="swiftpm-build" @@ -23,11 +24,17 @@ do done if [ ${ANDROID_ABI} = "armeabi-v7a" ]; then + ANDROID_ARCH="armv7" TARGET_TRIPLE="armv7-unknown-linux-androideabi24" + TARGET_LIB_DIR="arm-linux-androideabi" elif [ ${ANDROID_ABI} = "x86_64" ]; then + ANDROID_ARCH="x86_64" TARGET_TRIPLE="x86_64-unknown-linux-android24" + TARGET_LIB_DIR="x86_64-linux-android" else # assume arm64 + ANDROID_ARCH="aarch64" TARGET_TRIPLE="aarch64-unknown-linux-android24" + TARGET_LIB_DIR="aarch64-linux-android" fi if [ "${STATIC_SWIFT_STDLIB}" ] @@ -48,9 +55,11 @@ cat <<- EOF > "${DESTINATION_FILE}" "sdk": "${ANDROID_NDK_PATH}/toolchains/llvm/prebuilt/${HOST}/sysroot", "extra-cc-flags": ["-fPIC", "-DSTATIC_SWIFT_STDLIB"], "extra-swiftc-flags": [ + "-L", + "${SCRIPT_ROOT}/sdk/${SDK_DIRNAME}/usr/lib/swift_static/android/${ANDROID_ARCH}", "-DSTATIC_SWIFT_STDLIB", "-resource-dir", - "${SCRIPT_ROOT}/sdk/${ANDROID_ABI}/usr/lib/swift_static", + "${SCRIPT_ROOT}/sdk/${SDK_DIRNAME}/usr/lib/swift_static", "-tools-directory", "${ANDROID_NDK_PATH}/toolchains/llvm/prebuilt/${HOST}/bin" ], @@ -66,8 +75,10 @@ cat <<- EOF > "${DESTINATION_FILE}" "sdk": "${ANDROID_NDK_PATH}/toolchains/llvm/prebuilt/${HOST}/sysroot", "extra-cc-flags": ["-fPIC"], "extra-swiftc-flags": [ + "-L", + "${SCRIPT_ROOT}/sdk/${SDK_DIRNAME}/usr/lib/${TARGET_LIB_DIR}", "-resource-dir", - "${SCRIPT_ROOT}/sdk/${ANDROID_ABI}/usr/lib/swift", + "${SCRIPT_ROOT}/sdk/${SDK_DIRNAME}/usr/lib/swift", "-tools-directory", "${ANDROID_NDK_PATH}/toolchains/llvm/prebuilt/${HOST}/bin" ], @@ -77,6 +88,10 @@ EOF fi fi +${TOOLCHAIN_PATH}/usr/bin/swift package update \ + --disable-index-store \ + --scratch-path ${SCRATCH_PATH} + # --disable-index-store works around compiler crash in swift 5.7 toolchain: # adding a --scratch-path per ABI makes rebuilding faster ${TOOLCHAIN_PATH}/usr/bin/swift build \ @@ -93,4 +108,4 @@ then copySwiftDependencyLibs mkdir -p ${LIBRARY_OUTPUT_DIRECTORY} cp -f "${SCRATCH_PATH}/${BUILD_TYPE}"/*.so "${LIBRARY_OUTPUT_DIRECTORY}" -fi \ No newline at end of file +fi