Skip to content

[android] Remove ICU build flags since that requirement was dropped in #40340 #40625

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
Dec 23, 2021
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
60 changes: 9 additions & 51 deletions docs/Android.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,51 +43,22 @@ To follow along with this guide, you'll need:

## "Hello, world" on Android

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

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.

The steps are as follows:

1. Ensure you have `curl`, `autoconf`, `automake`, `libtool`, and
`git` installed.
2. Clone the [SwiftAndroid/libiconv-libicu-android](https://github.com/SwiftAndroid/libiconv-libicu-android)
project. From the command-line, run the following command:
`git clone https://github.com/SwiftAndroid/libiconv-libicu-android.git`.
3. From the command-line, run `which ndk-build`. Confirm that the path to
the `ndk-build` executable in the Android NDK you downloaded is displayed.
If not, you may need to add the Android NDK directory to your `PATH`.
4. Change directories into `libiconv-libicu-android`: `cd libiconv-libicu-android`
5. Run the Swift build script: `./build-swift.sh`
6. Confirm that the various `libicuXYZswift.so` libraries are located in the
`armeabi-v7a` directory.
Copy link
Member Author

Choose a reason for hiding this comment

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

We may need this back if we ever add instructions for cross-compiling swift-corelibs-foundation for Android as in #38441, since that repo still requires libicu, but in the meantime this libicu cross-compilation is no longer needed and we can always resurrect this doc from git if we want it later.


### 2. Building the Swift stdlib for Android

Enter your Swift directory, then run the build script, passing paths to the
Android NDK, as well as the directories that contain the `libicuucswift.so` and
`libicui18nswift.so` you downloaded or built in step one:
Enter your Swift directory, then run the build script, passing the path to the
Android NDK:

```
$ ARM_DIR=path/to/libiconv-libicu-android/armeabi-v7a
Copy link
Member Author

Choose a reason for hiding this comment

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

Removed this line that I had missed and rebased.

$ NDK_PATH=path/to/android-ndk-r23b
$ utils/build-script \
-R \ # Build in ReleaseAssert mode.
--android \ # Build for Android.
--android-ndk $NDK_PATH \ # Path to an Android NDK.
--android-arch armv7 \ # Optionally specify Android architecture, alternately aarch64 or x86_64
--android-api-level 21 \ # The Android API level to target. Swift only supports 21 or greater.
--android-icu-uc ${ARM_DIR}/libicuucswift.so \
--android-icu-uc-include ${ARM_DIR}/icu/source/common \
--android-icu-i18n ${ARM_DIR}/libicui18nswift.so \
--android-icu-i18n-include ${ARM_DIR}/icu/source/i18n \
--android-icu-data ${ARM_DIR}/libicudataswift.so
--android-api-level 21 # The Android API level to target. Swift only supports 21 or greater.
```

### 3. Compiling `hello.swift` to run on an Android device
### 2. Compiling `hello.swift` to run on an Android device

Create a simple Swift file named `hello.swift`:

Expand Down Expand Up @@ -121,7 +92,7 @@ This is exactly the error we want: the executable is built to run on an
Android device--it does not run on Linux. Next, let's deploy it to an Android
device in order to execute it.

### 4. Deploying the build products to the device
### 3. Deploying the build products to the device

You can use the `adb push` command to copy build products from your Linux
environment to your Android device. If you haven't already installed `adb`,
Expand All @@ -142,14 +113,6 @@ $ adb push build/Ninja-ReleaseAssert/swift-linux-x86_64/lib/swift/android/libswi
$ adb push build/Ninja-ReleaseAssert/swift-linux-x86_64/lib/swift/android/libswiftRemoteMirror.so /data/local/tmp
```

You will also need to push the icu libraries:

```
adb push /path/to/libicu-android/armeabi-v7a/libicudataswift.so /data/local/tmp
adb push /path/to/libicu-android/armeabi-v7a/libicui18nswift.so /data/local/tmp
adb push /path/to/libicu-android/armeabi-v7a/libicuucswift.so /data/local/tmp
```

In addition, you'll also need to copy the Android NDK's libc++:

```
Expand All @@ -162,7 +125,7 @@ previous step:
$ adb push hello /data/local/tmp
```

### 5. Running "Hello, world" on your Android device
### 4. Running "Hello, world" on your Android device

You can use the `adb shell` command to execute the `hello` executable on
the Android device:
Expand All @@ -182,7 +145,7 @@ Congratulations! You've just run your first Swift program on Android.
## Running the Swift test suite hosted on an Android device

When running the test suite, build products are automatically pushed to your
device. As in part four, you'll need to connect your Android device via USB:
device. As in part three, you'll need to connect your Android device via USB:

1. Connect your Android device to your computer via USB. Ensure that remote
debugging is enabled for that device by following the official instructions:
Expand All @@ -198,10 +161,5 @@ $ utils/build-script \
--android \ # Build for Android.
--android-ndk ~/android-ndk-r23b \ # Path to an Android NDK.
--android-arch armv7 \ # Optionally specify Android architecture, alternately aarch64
--android-ndk-version 21 \
--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 \
--android-icu-i18n-include ~/libicu-android/armeabi-v7a/icu/source/i18n/ \
--android-icu-data ~/libicu-android/armeabi-v7a/libicudata.so
--android-ndk-version 21
```
4 changes: 0 additions & 4 deletions docs/AndroidBuild.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@ cmake -C S:\swift-build\cmake\caches\android-armv7.cmake
-DANDROID_ALTERNATE_TOOLCHAIN=S:/b/a/Library/Developer/Toolchains/unknown-Asserts-development.xctoolchain/usr ^
-DLLVM_DIR=S:/b/a/llvm/lib/cmake/llvm ^
-DSWIFT_NATIVE_SWIFT_TOOLS_PATH=S:/b/a/Library/Developer/Toolchains/unknown-Asserts-development.xctoolchain/usr/bin ^
-DSWIFT_ANDROID_armv7_ICU_UC_INCLUDE=S:/b/a/Library/icu-64/usr/include/unicode ^
-DSWIFT_ANDROID_armv7_ICU_UC=S:/b/a/Library/icu-64/usr/lib/libicuuc64.so ^
-DSWIFT_ANDROID_armv7_ICU_I18N_INCLUDE=S:/b/a/Library/icu-64/usr/include ^
-DSWIFT_ANDROID_armv7_ICU_I18N=S:/b/a/Library/icu-64/usr/lib/libicuin64.so ^
S:/swift
ninja
ninja install
Expand Down
8 changes: 1 addition & 7 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -340,13 +340,7 @@ foreach(SDK ${SWIFT_SDKS})
--destination "${SWIFT_ANDROID_DEPLOY_DEVICE_PATH}"
--destination-arch "${ARCH}"
# Build products like libswiftCore.so.
"${SWIFTLIB_DIR}/android"
# These two directories may contain the same libraries,
# but upload both to device just in case. Duplicates will be
# overwritten, and uploading doesn't take very long anyway.
"${SWIFT_ANDROID_${ARCH}_ICU_UC}"
"${SWIFT_ANDROID_${ARCH}_ICU_I18N}"
"${SWIFT_ANDROID_${ARCH}_ICU_DATA}")
"${SWIFTLIB_DIR}/android")
endif()
add_custom_target("upload-stdlib${VARIANT_SUFFIX}"
${command_upload_stdlib}
Expand Down
48 changes: 0 additions & 48 deletions utils/android/build-toolchain

This file was deleted.

8 changes: 0 additions & 8 deletions utils/build-presets.ini
Original file line number Diff line number Diff line change
Expand Up @@ -927,12 +927,6 @@ libcxx
android
android-ndk=%(ndk_path)s
android-api-level=21
android-icu-uc=%(arm_dir)s/libicuucswift.so
android-icu-uc-include=%(arm_dir)s/icu/source/common
android-icu-i18n=%(arm_dir)s/libicui18nswift.so
android-icu-i18n-include=%(arm_dir)s/icu/source/i18n
android-icu-data=%(arm_dir)s/libicudataswift.so

build-swift-static-stdlib
build-swift-static-sdk-overlay
build-swift-stdlib-unittest-extra
Expand All @@ -945,8 +939,6 @@ installable-package=%(installable_package)s

host-test

extra-cmake-options=-DSWIFT_ENABLE_LLD_LINKER:BOOL=OFF
Copy link
Member Author

Choose a reason for hiding this comment

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

This hasn't been used since @davezarzycki removed it in #32042.


install-prefix=/usr
install-llvm
install-swift
Expand Down
14 changes: 3 additions & 11 deletions utils/build-script
Original file line number Diff line number Diff line change
Expand Up @@ -225,18 +225,10 @@ def validate_arguments(toolchain, args):

if args.android:
if args.android_ndk 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 \
args.android_icu_i18n_include is None or \
args.android_icu_data is None:
args.android_api_level is None:
fatal_error(
"when building for Android, --android-ndk, "
"--android-api-level, --android-icu-uc, "
"--android-icu-uc-include, --android-icu-i18n, "
"--android-icu-i18n-include, and --android-icu-data "
"must be specified")
"when building for Android, --android-ndk "
"and --android-api-level must be specified")

targets_needing_toolchain = [
'build_indexstoredb',
Expand Down
10 changes: 0 additions & 10 deletions utils/build-script-impl
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,6 @@ KNOWN_SETTINGS=(
android-api-level "" "The Android API level to target when building for Android. Currently only 21 or above is supported"
android-arch "armv7" "The Android target architecture when building for Android"
android-deploy-device-path "" "Path on an Android device to which built Swift stdlib products will be deployed"
android-icu-data "" "Path to libicudata.so"
android-icu-i18n "" "Path to libicui18n.so"
android-icu-i18n-include "" "Path to a directory containing headers libicui18n"
android-icu-uc "" "Path to libicuuc.so"
android-icu-uc-include "" "Path to a directory containing headers for libicuuc"
android-ndk "" "An absolute path to the NDK that will be used as a libc implementation for Android builds"

## Darwin Options
Expand Down Expand Up @@ -1907,11 +1902,6 @@ for host in "${ALL_HOSTS[@]}"; do
cmake_options=(
"${cmake_options[@]}"
-DSWIFT_ANDROID_NDK_PATH:STRING="${ANDROID_NDK}"
-DSWIFT_ANDROID_${ANDROID_ARCH}_ICU_UC:STRING="${ANDROID_ICU_UC}"
-DSWIFT_ANDROID_${ANDROID_ARCH}_ICU_UC_INCLUDE:STRING="${ANDROID_ICU_UC_INCLUDE}"
-DSWIFT_ANDROID_${ANDROID_ARCH}_ICU_I18N:STRING="${ANDROID_ICU_I18N}"
-DSWIFT_ANDROID_${ANDROID_ARCH}_ICU_I18N_INCLUDE:STRING="${ANDROID_ICU_I18N_INCLUDE}"
-DSWIFT_ANDROID_${ANDROID_ARCH}_ICU_DATA:STRING="${ANDROID_ICU_DATA}"
-DSWIFT_ANDROID_DEPLOY_DEVICE_PATH:STRING="${ANDROID_DEPLOY_DEVICE_PATH}"
-DSWIFT_SDK_ANDROID_ARCHITECTURES:STRING="${ANDROID_ARCH}"
)
Expand Down
10 changes: 0 additions & 10 deletions utils/build_swift/build_swift/driver_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -1176,16 +1176,6 @@ def create_argument_parser():
help='The Android API level to target when building for Android. '
'Currently only 21 or above is supported')

option('--android-icu-uc', store_path,
help='Path to libicuuc.so')
option('--android-icu-uc-include', store_path,
help='Path to a directory containing headers for libicuuc')
option('--android-icu-i18n', store_path,
help='Path to libicui18n.so')
option('--android-icu-i18n-include', store_path,
help='Path to a directory containing headers libicui18n')
option('--android-icu-data', store_path,
help='Path to libicudata.so')
option('--android-deploy-device-path', store_path,
default=android.adb.commands.DEVICE_TEMP_DIR,
help='Path on an Android device to which built Swift stdlib '
Expand Down
10 changes: 0 additions & 10 deletions utils/build_swift/tests/expected_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@
'android': False,
'android_api_level': '21',
'android_deploy_device_path': '/data/local/tmp',
'android_icu_i18n': None,
'android_icu_i18n_include': None,
'android_icu_uc': None,
'android_icu_uc_include': None,
'android_icu_data': None,
'android_ndk': None,
'android_arch': 'armv7',
'assertions': True,
Expand Down Expand Up @@ -688,11 +683,6 @@ class BuildScriptImplOption(_BaseOption):
SetTrueOption('--swift-freestanding-is-darwin'),

PathOption('--android-deploy-device-path'),
PathOption('--android-icu-i18n'),
PathOption('--android-icu-i18n-include'),
PathOption('--android-icu-uc'),
PathOption('--android-icu-uc-include'),
PathOption('--android-icu-data'),
PathOption('--android-ndk'),
PathOption('--build-subdir'),
SetTrueOption('--relocate-xdg-cache-home-under-build-subdir'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,6 @@ def convert_to_impl_arguments(self):
"--android-arch", args.android_arch,
"--android-ndk", args.android_ndk,
"--android-api-level", args.android_api_level,
"--android-icu-uc", args.android_icu_uc,
"--android-icu-uc-include", args.android_icu_uc_include,
"--android-icu-i18n", args.android_icu_i18n,
"--android-icu-i18n-include", args.android_icu_i18n_include,
"--android-icu-data", args.android_icu_data,
]
# If building natively on an Android host, only pass the API level.
if StdlibDeploymentTarget.Android.contains(StdlibDeploymentTarget
Expand Down
2 changes: 1 addition & 1 deletion validation-test/BuildSystem/android_cross_compile.test
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# UNSUPPORTED: OS=watchos

# RUN: %empty-directory(%t)
# RUN: SKIP_XCODE_VERSION_CHECK=1 SWIFT_BUILD_ROOT=%t %swift_src_root/utils/build-script --dry-run --cmake %cmake --libdispatch --cross-compile-hosts=android-aarch64 --skip-local-build --android --android-ndk %t/ndk/ --android-arch aarch64 --android-icu-uc %t/lib/libicuuc.so --android-icu-uc-include %t/include/ --android-icu-i18n %t/lib/libicui18n.so --android-icu-i18n-include %t/include/ --android-icu-data %t/lib/libicudata.so 2>&1 | %FileCheck %s
# RUN: SKIP_XCODE_VERSION_CHECK=1 SWIFT_BUILD_ROOT=%t %swift_src_root/utils/build-script --dry-run --cmake %cmake --libdispatch --cross-compile-hosts=android-aarch64 --skip-local-build --android --android-ndk %t/ndk/ --android-arch aarch64 2>&1 | %FileCheck %s

# CHECK: -DCMAKE_Swift_FLAGS{{.*}}-target {{.*}}unknown-linux-android{{.*}} -sdk
# CHECK: -DCMAKE_SYSTEM_NAME=Android {{.*}} -DCMAKE_ANDROID_NDK