Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to swift 5.8.1 #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmake_caches.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
56 changes: 25 additions & 31 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ 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}
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() {
Expand Down Expand Up @@ -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

Expand All @@ -80,48 +81,41 @@ 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
}

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
2 changes: 1 addition & 1 deletion swift-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 18 additions & 3 deletions swiftpm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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}" ]
Expand All @@ -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"
],
Expand All @@ -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"
],
Expand All @@ -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 \
Expand All @@ -93,4 +108,4 @@ then
copySwiftDependencyLibs
mkdir -p ${LIBRARY_OUTPUT_DIRECTORY}
cp -f "${SCRATCH_PATH}/${BUILD_TYPE}"/*.so "${LIBRARY_OUTPUT_DIRECTORY}"
fi
fi