0
0
mirror of https://github.com/termux/termux-packages.git synced 2024-12-12 14:13:36 +00:00
2024-12-12 14:40:51 +05:30

176 lines
8.4 KiB
Bash

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="@finagolfin"
TERMUX_PKG_VERSION=6.0.3
SWIFT_RELEASE="RELEASE"
TERMUX_PKG_SRCURL=https://github.com/swiftlang/swift/archive/swift-$TERMUX_PKG_VERSION-$SWIFT_RELEASE.tar.gz
TERMUX_PKG_SHA256=eef9f312d00540cfabc35cb1da9221dd15d3aaca546497a14f29a641ee6484e3
TERMUX_PKG_AUTO_UPDATE=false
TERMUX_PKG_HOSTBUILD=true
TERMUX_PKG_DEPENDS="clang, libandroid-execinfo, libandroid-glob, libandroid-posix-semaphore, libandroid-shmem, libandroid-spawn, libandroid-spawn-static, libandroid-sysv-semaphore, libcurl, libsqlite, libuuid, libxml2, libdispatch, llbuild, pkg-config, swift-sdk-${TERMUX_ARCH/_/-}"
TERMUX_PKG_BUILD_DEPENDS="rsync"
TERMUX_PKG_BLACKLISTED_ARCHES="i686"
TERMUX_PKG_NO_STATICSPLIT=true
# Temporary hack only needed for x86_64
TERMUX_PKG_UNDEF_SYMBOLS_FILES="
./opt/ndk-multilib/arm-linux-androideabi/lib/libFoundation.so
./opt/ndk-multilib/arm-linux-androideabi/lib/libFoundationNetworking.so
./opt/ndk-multilib/x86_64-linux-android/lib/libFoundation.so
./opt/ndk-multilib/x86_64-linux-android/lib/libFoundationNetworking.so
"
# Building swift uses CMake, but the standard
# termux_step_configure_cmake function is not used. Instead, we set
# TERMUX_PKG_FORCE_CMAKE to make the build system aware that CMake is
# needed.
TERMUX_PKG_FORCE_CMAKE=true
TERMUX_CMAKE_BUILD=Ninja
SWIFT_COMPONENTS="autolink-driver;compiler;clang-resource-dir-symlink;swift-remote-mirror;license;sourcekit-inproc;static-mirror-lib;stdlib;sdk-overlay"
SWIFT_TOOLCHAIN_FLAGS="-RA --llvm-targets-to-build='X86;ARM;AArch64' -j $TERMUX_PKG_MAKE_PROCESSES --install-prefix=$TERMUX_PREFIX"
SWIFT_PATH_FLAGS="--build-subdir=. --install-destdir=/"
SWIFT_BUILD_FLAGS="$SWIFT_TOOLCHAIN_FLAGS $SWIFT_PATH_FLAGS"
SWIFT_ARCH=$TERMUX_ARCH
test $SWIFT_ARCH == 'arm' && SWIFT_ARCH='armv7'
termux_step_post_get_source() {
# The Swift build-script requires a particular organization of source
# directories, which the following downloads and sets up.
mkdir .temp
mv [a-zA-Z]* .temp/
mv .temp swift
declare -A library_checksums
library_checksums[swift-cmark]=ab1064350ecedd5b3c0f2a6fbe3acefbc45d7accf1e4ca1591ce04d0c6787e40
library_checksums[llvm-project]=d93ca164615938e5026a2d1af76b2ef7514eae98b38a716f3278bc1a6dfc8f92
library_checksums[swift-experimental-string-processing]=6c34cfdf934eb781169866a66505e11541861ba638b05fd4ed87f8c34a6fa55e
library_checksums[swift-syntax]=30788e115f37b7d3f8fc1f5d436b80996f4945fc13287ed7e4391b358479fafd
library_checksums[swift-corelibs-libdispatch]=444c0de5fe18e148548a3f3b60b3bac3d4d586285c21064346c7ca17ed1d4fac
library_checksums[swift-corelibs-foundation]=62c276a18fa3b3b92e95f5349dc125d03f09cea3c477b3af1428ccdbab29e139
library_checksums[swift-foundation]=31ee3ea95a015049d3f6a5cfe8bd3a460071fa0086c1d112efaf0580611d162c
library_checksums[swift-foundation-icu]=c4332b4e6cc008a5a7045ad7f368df7deb518f286ecd5a78839066dcc07a853a
library_checksums[swift-corelibs-xctest]=eb131d1cfde18548c5fc782ba56bc871b13057b5e7b6992ddae4d4349360571d
library_checksums[swift-llbuild]=68d71bf7e0882153c6ad91fbe0626ab761d8bc46d2d93ce32cbfa392d256a30e
library_checksums[swift-argument-parser]=4a10bbef290a2167c5cc340b39f1f7ff6a8cf4e1b5433b68548bf5f1e542e908
library_checksums[Yams]=a81c6b93f5d26bae1b619b7f8babbfe7c8abacf95b85916961d488888df886fb
library_checksums[swift-collections]=cd30d2f93c72424df48d182006417abdeebe74d250cb99d1cda78daf40aca569
library_checksums[swift-crypto]=5c860c0306d0393ff06268f361aaf958656e1288353a0e23c3ad20de04319154
library_checksums[swift-system]=02e13a7f77887c387f5aa1de05f4d4b8b158c35145450e1d9557d6c42b06cd1f
library_checksums[swift-asn1]=e0da995ae53e6fcf8251887f44d4030f6600e2f8f8451d9c92fcaf52b41b6c35
library_checksums[swift-certificates]=fcaca458aab45ee69b0f678b72c2194b15664cc5f6f5e48d0e3f62bc5d1202ca
library_checksums[swift-driver]=9ee38eda1a0adc24dd995b345dff4a5a25d42ae8d063fcc04b170469f2f53d43
library_checksums[swift-tools-support-core]=fc83e9922d4c7df0f0d94b8840f292989eb148d5e451b182a9e390a9ea4dd94e
library_checksums[swift-package-manager]=03c5b8dfd8628de42ca1c171faeeddea977ecdad8675d3826a2c165ad8f972ba
library_checksums[indexstore-db]=fdaceb80a819e5b86d1599e7357c79e518a3ff0bb96dcd82245fc50e3d6bbc0d
library_checksums[sourcekit-lsp]=928db64bc179a250afd305b5729217180e2de1cdcd3d353d0fa20b38c5def8ec
for library in "${!library_checksums[@]}"; do \
GH_ORG="apple"
if [ "$library" = "swift-argument-parser" ]; then
SRC_VERSION="1.2.3"
TAR_NAME=$SRC_VERSION
elif [ "$library" = "swift-asn1" ]; then
SRC_VERSION="1.0.0"
TAR_NAME=$SRC_VERSION
elif [ "$library" = "swift-certificates" ]; then
SRC_VERSION="1.0.1"
TAR_NAME=$SRC_VERSION
elif [ "$library" = "swift-collections" ]; then
SRC_VERSION="1.1.2"
TAR_NAME=$SRC_VERSION
elif [ "$library" = "swift-crypto" ]; then
SRC_VERSION="3.0.0"
TAR_NAME=$SRC_VERSION
elif [ "$library" = "swift-system" ]; then
SRC_VERSION="1.3.0"
TAR_NAME=$SRC_VERSION
elif [ "$library" = "Yams" ]; then
GH_ORG="jpsim"
SRC_VERSION="5.0.6"
TAR_NAME=$SRC_VERSION
else
GH_ORG="swiftlang"
SRC_VERSION=$SWIFT_RELEASE
TAR_NAME=swift-$TERMUX_PKG_VERSION-$SWIFT_RELEASE
fi
termux_download \
https://github.com/$GH_ORG/$library/archive/$TAR_NAME.tar.gz \
$TERMUX_PKG_CACHEDIR/$library-$SRC_VERSION.tar.gz \
${library_checksums[$library]}
tar xf $TERMUX_PKG_CACHEDIR/$library-$SRC_VERSION.tar.gz
mv $library-$TAR_NAME $library
done
mv swift-cmark cmark
mv swift-llbuild llbuild
mv Yams yams
mv swift-package-manager swiftpm
}
termux_step_host_build() {
if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ]; then
termux_setup_cmake
termux_setup_ninja
local CLANG=$(command -v clang)
local CLANGXX=$(command -v clang++)
# The Ubuntu CI may not have clang/clang++ in its path so explicitly set it
# to clang-17 instead.
if [ -z "$CLANG" ]; then
CLANG=$(command -v clang-17)
CLANGXX=$(command -v clang++-17)
fi
# 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_PKG_MAKE_PROCESSES $SWIFT_PATH_FLAGS \
--skip-build-cmark --skip-build-llvm --skip-build-swift --skip-early-swift-driver \
--skip-early-swiftsyntax --build-toolchain-only --host-cc=$CLANG --host-cxx=$CLANGXX
fi
}
termux_step_make() {
if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ]; then
termux_setup_swift
ln -sf $TERMUX_PKG_HOSTBUILD_DIR/llvm-linux-x86_64 $TERMUX_PKG_BUILDDIR/llvm-linux-x86_64
for header in execinfo.h glob.h iconv.h spawn.h sys/sem.h sys/shm.h; do
ln -sf $TERMUX_PREFIX/include/$header $TERMUX_STANDALONE_TOOLCHAIN/sysroot/usr/include/$header
done
SWIFT_BUILD_FLAGS="$SWIFT_BUILD_FLAGS --android
--android-ndk $TERMUX_STANDALONE_TOOLCHAIN --android-arch $SWIFT_ARCH
--build-toolchain-only --skip-local-build --skip-local-host-install
--cross-compile-hosts=android-$SWIFT_ARCH
--cross-compile-deps-path=$(dirname $TERMUX_PREFIX)
--native-swift-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 \
$SWIFT_BUILD_FLAGS --xctest -b -p --swift-driver --sourcekit-lsp \
--android-api-level $TERMUX_PKG_API_LEVEL --build-swift-static-stdlib \
--swift-install-components=$SWIFT_COMPONENTS --llvm-install-components=IndexStore \
--install-llvm --install-swift --install-libdispatch --install-foundation \
--install-xctest --install-llbuild --install-swiftpm --install-swift-driver --install-sourcekit-lsp
rm $TERMUX_STANDALONE_TOOLCHAIN/sysroot/usr/include/{execinfo.h,glob.h,iconv.h,spawn.h,sys/sem.h,sys/shm.h}
}
termux_step_make_install() {
rm -rf $TERMUX_PREFIX/lib/swift{,_static}/{Block,os}
rm $TERMUX_PREFIX/lib/swift{,_static}/dispatch/*.h
rm $TERMUX_PREFIX/lib/swift/android/lib{dispatch,BlocksRuntime}.so
mv $TERMUX_PREFIX/lib/swift/android/lib[^_]*.so $TERMUX_PREFIX/opt/ndk-multilib/$TERMUX_ARCH-linux-android*/lib
mv $TERMUX_PREFIX/lib/swift/android/lib_FoundationICU.so $TERMUX_PREFIX/opt/ndk-multilib/$TERMUX_ARCH-linux-android*/lib
mv $TERMUX_PREFIX/lib/swift/android/lib*.a $TERMUX_PREFIX/lib/swift/android/$SWIFT_ARCH
mv $TERMUX_PREFIX/lib/swift_static/android/lib*.a $TERMUX_PREFIX/lib/swift_static/android/$SWIFT_ARCH
if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ]; then
rm $TERMUX_PREFIX/swiftpm-android-$SWIFT_ARCH.json
fi
}