Skip to content

Commit

Permalink
Merge pull request swiftlang#2244 from modocache/swiftandroid-ndk-ver…
Browse files Browse the repository at this point in the history
…sion-bump-r11c

[android] Support latest Android NDK r11c
  • Loading branch information
gribozavr committed Apr 20, 2016
2 parents 9b7fdbb + a7e2329 commit af874ab
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 37 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ set(SWIFT_PARALLEL_LINK_JOBS "" CACHE STRING
"Define the maximum number of linker jobs for swift.")
set(SWIFT_ANDROID_NDK_PATH "" CACHE STRING
"Path to the directory that contains the Android NDK tools that are executable on the build machine")
set(SWIFT_ANDROID_NDK_TOOLCHAIN_VERSION "" CACHE STRING
"A version of the toolchain to use when building for Android. Use 4.8 for 32-bit builds, 4.9 for 64-bit builds")
set(SWIFT_ANDROID_NDK_GCC_VERSION "" CACHE STRING
"The GCC version to use when building for Android. Currently only 4.9 is supported.")
set(SWIFT_ANDROID_SDK_PATH "" CACHE STRING
"Path to the directory that contains the Android SDK tools that will be passed to the swiftc frontend")
set(SWIFT_ANDROID_ICU_UC "" CACHE STRING
Expand Down
4 changes: 2 additions & 2 deletions cmake/modules/AddSwift.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function(_add_variant_c_compile_link_flags)
list(APPEND result
"--sysroot=${SWIFT_ANDROID_SDK_PATH}"
# Use the linker included in the Android NDK.
"-B" "${SWIFT_ANDROID_NDK_PATH}/toolchains/arm-linux-androideabi-${SWIFT_ANDROID_NDK_TOOLCHAIN_VERSION}/prebuilt/linux-x86_64/arm-linux-androideabi/bin/")
"-B" "${SWIFT_ANDROID_NDK_PATH}/toolchains/arm-linux-androideabi-${SWIFT_ANDROID_NDK_GCC_VERSION}/prebuilt/linux-x86_64/arm-linux-androideabi/bin/")
endif()


Expand Down Expand Up @@ -243,7 +243,7 @@ function(_add_variant_link_flags)
elseif("${LFLAGS_SDK}" STREQUAL "ANDROID")
list(APPEND result
"-ldl"
"-L${SWIFT_ANDROID_NDK_PATH}/toolchains/arm-linux-androideabi-${SWIFT_ANDROID_NDK_TOOLCHAIN_VERSION}/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/${SWIFT_ANDROID_NDK_TOOLCHAIN_VERSION}"
"-L${SWIFT_ANDROID_NDK_PATH}/toolchains/arm-linux-androideabi-${SWIFT_ANDROID_NDK_GCC_VERSION}/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/${SWIFT_ANDROID_NDK_GCC_VERSION}"
"${SWIFT_ANDROID_NDK_PATH}/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libc++_shared.so"
"-L${SWIFT_ANDROID_ICU_UC}" "-L${SWIFT_ANDROID_ICU_I18N}")
else()
Expand Down
27 changes: 16 additions & 11 deletions docs/Android.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ To follow along with this guide, you'll need:
currently only buildable for Android from a Linux environment. Before
attempting to build for Android, please make sure you are able to build
for Linux by following the instructions in the Swift project README.
2. An Android NDK of version 21 or greater, available to download here:
2. The latest version of the Android NDK (r11c at the time of this writing),
available to download here:
http://developer.android.com/ndk/downloads/index.html.
3. An Android device with remote debugging enabled. We require remote
debugging in order to deploy built stdlib products to the device. You may
Expand All @@ -39,14 +40,18 @@ To follow along with this guide, you'll need:

## "Hello, world" on Android

### 1. Building the Swift Android stdlib dependencies
### 1. Downloading (or building) the Swift Android stdlib dependencies

You may have noticed that, in order to build the Swift stdlib for Linux, you
needed to `apt-get install libicu-dev icu-devtools`. Similarly, building
the Swift stdlib for Android requires the libiconv and libicu libraries.
However, you'll need versions of these libraries that work on Android devices.

To build libiconv and libicu for Android:
You may download prebuilt copies of these dependencies, built for Ubuntu 15.10
and Android NDK r11c. Click [here](https://github.com/SwiftAndroid/libiconv-libicu-android/releases/download/android-ndk-r11c/libiconv-libicu-armeabi-v7a-ubuntu-15.10-ndk-r11c.zip)
to download, then unzip the archive file.

Alternatively, you may choose to build libiconv and libicu for Android yourself:

1. Ensure you have `curl`, `autoconf`, `automake`, `libtool`, and
`git` installed.
Expand All @@ -69,10 +74,10 @@ Android NDK and libicu/libiconv directories:

```
$ utils/build-script \
-R \ # Build in ReleaseAssert mode.
--android \ # Build for Android.
--android-ndk ~/android-ndk-r10e \ # Path to an Android NDK.
--android-ndk-version 21 \ # The NDK version to use. Must be 21 or greater.
-R \ # Build in ReleaseAssert mode.
--android \ # Build for Android.
--android-ndk ~/android-ndk-r11c \ # Path to an Android NDK.
--android-api-level 21 \ # The Android API level to target. Swift only supports 21 or greater.
--android-icu-uc ~/libicu-android/armeabi-v7a/libicuuc.so \
--android-icu-uc-include ~/libicu-android/armeabi-v7a/icu/source/common \
--android-icu-i18n ~/libicu-android/armeabi-v7a/libicui18n.so \
Expand All @@ -93,9 +98,9 @@ file, targeting Android:
```
$ build/Ninja/ReleaseAssert/swift-linux-x86_64/swiftc \ # The Swift compiler built in the previous step.
-target armv7-none-linux-androideabi \ # Targeting android-armv7.
-sdk ~/android-ndk-r10e/platforms/android-21/arch-arm \ # Use the same NDK path and version as you used to build the stdlib in the previous step.
-L ~/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a \ # Link the Android NDK's libc++ and libgcc.
-L ~/android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.8 \
-sdk ~/android-ndk-r11c/platforms/android-21/arch-arm \ # Use the same NDK path and API version as you used to build the stdlib in the previous step.
-L ~/android-ndk-r11c/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a \ # Link the Android NDK's libc++ and libgcc.
-L ~/android-ndk-r11c/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9 \
hello.swift
```

Expand Down Expand Up @@ -129,7 +134,7 @@ $ adb push build/Ninja-ReleaseAssert/swift-linux-x86_64/lib/swift/android/libswi
In addition, you'll also need to copy the Android NDK's libc++:

```
$ adb push ~/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libc++_shared.so /data/local/tmp
$ adb push ~/android-ndk-r11c/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libc++_shared.so /data/local/tmp
```

Finally, you'll need to copy the `hello` executable you built in the
Expand Down
9 changes: 1 addition & 8 deletions stdlib/public/stubs/LibcShims.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ int _swift_stdlib_close(int fd) { return close(fd); }
#if defined(__APPLE__)
#include <malloc/malloc.h>
size_t _swift_stdlib_malloc_size(const void *ptr) { return malloc_size(ptr); }
#elif defined(__GNU_LIBRARY__) || defined(__CYGWIN__)
#elif defined(__GNU_LIBRARY__) || defined(__CYGWIN__) || defined(__ANDROID__)
#include <malloc.h>
size_t _swift_stdlib_malloc_size(const void *ptr) {
return malloc_usable_size(const_cast<void *>(ptr));
Expand All @@ -62,13 +62,6 @@ size_t _swift_stdlib_malloc_size(const void *ptr) {
size_t _swift_stdlib_malloc_size(const void *ptr) {
return malloc_usable_size(const_cast<void *>(ptr));
}
#elif defined(__ANDROID__)
extern "C" {
extern size_t dlmalloc_usable_size(void*);
}
size_t _swift_stdlib_malloc_size(const void *ptr) {
return dlmalloc_usable_size(const_cast<void *>(ptr));
}
#else
#error No malloc_size analog known for this platform/libc.
#endif
Expand Down
22 changes: 12 additions & 10 deletions utils/build-script
Original file line number Diff line number Diff line change
Expand Up @@ -759,16 +759,18 @@ details of the setups of other systems or automated environments.""")
"implementation for Android builds",
metavar="PATH")
android_group.add_argument(
"--android-ndk-version",
help="A version of the NDK to use when building for Android. "
"--android-api-level",
help="The Android API level to target when building for Android. "
"Currently only 21 or above is supported",
default="21")
android_group.add_argument(
"--android-ndk-toolchain-version",
help="A version of the toolchain to use when building for Android. "
"Use 4.8 for 32-bit builds, 4.9 for 64-bit builds",
"--android-ndk-gcc-version",
help="The GCC version to use when building for Android. Currently "
"only 4.9 is supported. %(default)s is also the default value. "
"This option may be used when experimenting with versions "
"of the Android NDK not officially supported by Swift",
choices=["4.8", "4.9"],
default="4.8")
default="4.9")
android_group.add_argument(
"--android-icu-uc",
help="Path to a directory containing libicuuc.so",
Expand Down Expand Up @@ -837,7 +839,7 @@ details of the setups of other systems or automated environments.""")

if args.android:
if args.android_ndk is None or \
args.android_ndk_version is None or \
args.android_api_level is None or \
args.android_icu_uc is None or \
args.android_icu_uc_include is None or \
args.android_icu_i18n is None or \
Expand Down Expand Up @@ -1225,9 +1227,9 @@ details of the setups of other systems or automated environments.""")
if args.android:
build_script_impl_args += [
"--android-ndk", args.android_ndk,
"--android-ndk-version", args.android_ndk_version,
"--android-ndk-toolchain-version",
args.android_ndk_toolchain_version,
"--android-api-level", args.android_api_level,
"--android-ndk-gcc-version",
args.android_ndk_gcc_version,
"--android-icu-uc", args.android_icu_uc,
"--android-icu-uc-include", args.android_icu_uc_include,
"--android-icu-i18n", args.android_icu_i18n,
Expand Down
8 changes: 4 additions & 4 deletions utils/build-script-impl
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ KNOWN_SETTINGS=(
build-jobs "" "The number of parallel build jobs to use"
darwin-toolchain-alias "" "Swift alias for toolchain"
android-ndk "" "An absolute path to the NDK that will be used as a libc implementation for Android builds"
android-ndk-version "" "A version of the NDK to use when building for Android. Currently only 21 or above is supported"
android-ndk-toolchain-version "" "A version of the toolchain to use when building for Android. Use 4.8 for 32-bit builds, 4.9 for 64-bit builds"
android-api-level "" "The Android API level to target when building for Android. Currently only 21 or above is supported"
android-ndk-gcc-version "" "The GCC version to use when building for Android. Currently only 4.9 is supported"
android-icu-uc "" "Path to a directory containing libicuuc.so"
android-icu-uc-include "" "Path to a directory containing headers for libicuuc"
android-icu-i18n "" "Path to a directory containing libicui18n.so"
Expand Down Expand Up @@ -1645,8 +1645,8 @@ for deployment_target in "${HOST_TARGET}" "${CROSS_TOOLS_DEPLOYMENT_TARGETS[@]}"
cmake_options=(
"${cmake_options[@]}"
-DSWIFT_ANDROID_NDK_PATH:STRING="${ANDROID_NDK}"
-DSWIFT_ANDROID_NDK_TOOLCHAIN_VERSION:STRING="${ANDROID_NDK_TOOLCHAIN_VERSION}"
-DSWIFT_ANDROID_SDK_PATH:STRING="${ANDROID_NDK}/platforms/android-${ANDROID_NDK_VERSION}/arch-arm"
-DSWIFT_ANDROID_NDK_GCC_VERSION:STRING="${ANDROID_NDK_GCC_VERSION}"
-DSWIFT_ANDROID_SDK_PATH:STRING="${ANDROID_NDK}/platforms/android-${ANDROID_API_LEVEL}/arch-arm"
-DSWIFT_ANDROID_ICU_UC:STRING="${ANDROID_ICU_UC}"
-DSWIFT_ANDROID_ICU_UC_INCLUDE:STRING="${ANDROID_ICU_UC_INCLUDE}"
-DSWIFT_ANDROID_ICU_I18N:STRING="${ANDROID_ICU_I18N}"
Expand Down

0 comments on commit af874ab

Please sign in to comment.