Skip to content

Added swiftpm and other libs to Android toolchain #11870

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

Merged
merged 1 commit into from
Oct 23, 2017
Merged
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
16 changes: 16 additions & 0 deletions utils/android/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

# Build Android Toolchain
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a suggestion: I think expanding on what "Android toolchain" means here would help people who have some interest, but don't quite understand what a "toolchain" is, to use the scripts and tools in here. Ideally, I think this README should answer the question: "why would I want to build an Android toolchain?"


This toolchain will generate the .so and .swiftmodule files of the Swift standard library and Foundation framework for the Android environment, armv7 architecture. Those files are needed when building any Swift library to be included in an application for Android.

To build the toolchain run:

```
android$ ./build-toolchain
```

It will be built on:

```
path/to/swift-source/swift-android-toolchain
```
46 changes: 27 additions & 19 deletions utils/android/build-toolchain
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,37 @@

set -e

cd "$(dirname $0)/../.." || exit
SRC_DIR=$PWD
SWIFT_PATH="$( cd "$(dirname $0)/../../.." && pwd )"

ANDROID_NDK_DIR="${ANDROID_NDK_DIR:?Please set the Android NDK directory in the ANDROID_NDK_DIR environment variable}"
ANDROID_ICU_DIR="${ANDROID_ICU_DIR:?Please set the libiconv-libicu-android directory in the ANDROID_ICU_DIR environment variable}"
ANDROID_NDK_PATH="${ANDROID_NDK_PATH:?Please set the Android NDK path in the ANDROID_NDK_PATH environment variable}"
ANDROID_ICU_PATH=${SWIFT_PATH}/libiconv-libicu-android

SWIFT_TOOLCHAIN_DIR="${SRC_DIR}/../swift-android-toolchain"
SWIFT_LINUX_DIR="${SRC_DIR}/../build/Ninja-ReleaseAssert/swift-linux-x86_64"
[ -e ${ANDROID_ICU_PATH} ] || exit 1

./utils/build-script \
SWIFT_ANDROID_TOOLCHAIN_PATH="${SWIFT_PATH}/swift-android-toolchain"

rm -rf ${SWIFT_ANDROID_TOOLCHAIN_PATH}

${SWIFT_PATH}/swift/utils/build-script \
-R \
--android \
--android-ndk "${ANDROID_NDK_DIR}" \
--android-ndk ${ANDROID_NDK_PATH} \
--android-api-level 21 \
--android-icu-uc "${ANDROID_ICU_DIR}/armeabi-v7a" \
--android-icu-uc-include "${ANDROID_ICU_DIR}/armeabi-v7a/icu/source/common" \
--android-icu-i18n "${ANDROID_ICU_DIR}/armeabi-v7a" \
--android-icu-i18n-include "${ANDROID_ICU_DIR}/armeabi-v7a/icu/source/i18n" || exit

test -e ${SWIFT_LINUX_DIR} || exit
rm -rf ${SWIFT_TOOLCHAIN_DIR}
mkdir -p ${SWIFT_TOOLCHAIN_DIR}/usr

cp -r ${SWIFT_LINUX_DIR}/{bin,lib,include} ${SWIFT_TOOLCHAIN_DIR}/usr
cp ${ANDROID_ICU_DIR}/armeabi-v7a/*.so ${SWIFT_TOOLCHAIN_DIR}/usr/lib/swift/android
--android-icu-uc "${ANDROID_ICU_PATH}/armeabi-v7a" \
--android-icu-uc-include "${ANDROID_ICU_PATH}/armeabi-v7a/icu/source/common" \
--android-icu-i18n "${ANDROID_ICU_PATH}/armeabi-v7a" \
--android-icu-i18n-include "${ANDROID_ICU_PATH}/armeabi-v7a/icu/source/i18n" \
--libdispatch --install-libdispatch \
--foundation --install-foundation \
--llbuild --install-llbuild \
--lldb --install-lldb \
--swiftpm --install-swiftpm \
--xctest --install-xctest \
--install-swift \
'--swift-install-components=autolink-driver;compiler;clang-builtin-headers;stdlib;swift-remote-mirror;sdk-overlay;dev' \
--install-prefix=/usr \
--install-destdir=${SWIFT_ANDROID_TOOLCHAIN_PATH}

${SWIFT_PATH}/swift-corelibs-libdispatch/build-android
${SWIFT_PATH}/swift-corelibs-foundation/build-android