├── release ├── bin │ ├── armv7-none-linux-androideabi-ld │ ├── swift-androidfix │ ├── swiftc-pm-android │ ├── swift-android-push │ └── swiftc-android └── deploy.sh ├── copyto.sh ├── README.md ├── copyicu.sh └── rundroid /release/bin/armv7-none-linux-androideabi-ld: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | exec arm-linux-androideabi-ld.bfd $@ 3 | -------------------------------------------------------------------------------- /copyto.sh: -------------------------------------------------------------------------------- 1 | cd release 2 | cp -r * /home/zhuowei/build/Ninja-ReleaseAssert+stdlib-DebugAssert/swift-linux-x86_64/ 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Various extra scripts shipped with the Swift compiler port for Android. 2 | 3 | All licensed under Apache License 2. 4 | -------------------------------------------------------------------------------- /release/bin/swift-androidfix: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | mypath=`which $0` 3 | mydir=`dirname $mypath` 4 | if [ -z $ANDROID_NDK_HOME ] 5 | then 6 | echo "ANDROID_NDK_HOME not set: run \"export ANDROID_NDK_HOME=/path/to/ndk\"" 7 | exit 1 8 | fi 9 | hardcodedpath="/home/zhuowei/ndk" 10 | sed -e "s@$hardcodedpath@$ANDROID_NDK_HOME@g" -i $mydir/../lib/swift/bionic/module.map 11 | -------------------------------------------------------------------------------- /release/bin/swiftc-pm-android: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | source ~/.swift-android-ndk-home 3 | case "$@" in 4 | *-lPackageDescription*) 5 | exec swiftc $@ 6 | ;; 7 | *) 8 | oldargs="$@" 9 | newargs=${oldargs//-I \/usr\/local\/include/} 10 | newargs=${newargs//-L\/usr\/local\/lib/} 11 | case "$newargs" in 12 | *-emit-module*) 13 | ;; 14 | *) 15 | newargs="$newargs -emit-library" 16 | esac 17 | exec swiftc-android $newargs 18 | ;; 19 | esac 20 | -------------------------------------------------------------------------------- /release/bin/swift-android-push: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | mypath=`which $0` 3 | mydir=`dirname $mypath` 4 | for i in $mydir/../lib/swift/android/*.so 5 | do 6 | echo $i 7 | adb push $i /data/local/tmp 8 | done 9 | echo "libc++_shared.so" 10 | adb push $ANDROID_NDK_HOME/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libc++_shared.so /data/local/tmp 11 | for i in $@ 12 | do 13 | echo $i 14 | adb push $i /data/local/tmp 15 | adb shell chmod 755 /data/local/tmp/`basename $i` 16 | done 17 | -------------------------------------------------------------------------------- /release/bin/swiftc-android: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | mypath=`which $0` 3 | mydir=`dirname $mypath` 4 | if [ -z $ANDROID_NDK_HOME ] 5 | then 6 | echo "ANDROID_NDK_HOME not set: run \"export ANDROID_NDK_HOME=/path/to/ndk\"" 7 | exit 1 8 | fi 9 | clangpath=$ANDROID_NDK_HOME/toolchains/llvm-3.6/prebuilt/linux-x86_64/bin 10 | gccpath=$ANDROID_NDK_HOME/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin 11 | export PATH=$clangpath:$gccpath:$PATH:`pwd` 12 | $mydir/swiftc -target armv7-none-linux-androideabi -Xlinker --allow-shlib-undefined $@ 13 | -------------------------------------------------------------------------------- /copyicu.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | mystrip=$ANDROID_NDK_HOME/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-strip 3 | for i in ../libiconv-libicu-android/armeabi-v7a/libicu*.so 4 | do 5 | echo $i 6 | $mystrip -o ../build/Ninja-ReleaseAssert+stdlib-DebugAssert/swift-linux-x86_64/lib/swift/android/`basename $i` $i 7 | done 8 | 9 | # icu must be placed in ../icu, relative to swift source directory. 10 | # See: https://github.com/apple/swift/compare/master...SwiftAndroid:20dbe893a8f2fb77bf8fc7f067c602d273181362?expand=1#diff-820a1d13441195f42bb1712046b14552R29 11 | cp -r ../libiconv-libicu-android/armeabi-v7a/icu ../icu 12 | -------------------------------------------------------------------------------- /release/deploy.sh: -------------------------------------------------------------------------------- 1 | rm -r swiftandroid 2 | mkdir swiftandroid 3 | cd swiftandroid 4 | cp ~/swift/README.android ./ 5 | mkdir bin 6 | IFS=" " 7 | for i in swift swift-demangle 8 | do 9 | echo $i 10 | strip -o bin/$i ../bin/$i 11 | done 12 | for i in swift-autolink-extract swiftc swiftc-android swift-android-push armv7-none-linux-androideabi-ld swift-androidfix swiftc-pm-android 13 | do 14 | cp -P ../bin/$i bin/$i 15 | done 16 | mkdir lib 17 | cp -r ../lib/swift lib/ 18 | [ -a lib/swift/android/libicuuc.so ] || echo "WHERE IS ICU" 19 | cp -r ../../swiftpm-linux-x86_64/lib/swift lib/ 20 | cp -r ../../swiftpm-linux-x86_64/debug/swift-build bin/ 21 | cp -r ../../llbuild-linux-x86_64/bin/* bin/ 22 | rm lib/swift/clang 23 | cp -r ../../llvm-linux-x86_64/lib/clang/3.8.0 lib/swift/clang 24 | cd .. 25 | rm swift_android.tar.xz 26 | tar cJf swift_android.tar.xz swiftandroid 27 | -------------------------------------------------------------------------------- /rundroid: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Grab the path to the executable we wish to run on device. 4 | # Shift the command-line arguments by one--we'll be using the 5 | # remaining arguments below. 6 | EXECUTABLE="$1" 7 | shift 1 8 | 9 | DEVICE_TMP_DIR="/data/local/tmp" # We'll be running the executable in a temporary directory in /data/local/tmp. 10 | DEVICE_UUID_DIR="$DEVICE_TMP_DIR/`uuidgen`" # Each test gets its own sub-directory--especially important since tests can be run in parallel. 11 | DEVICE_EXECUTABLE="$DEVICE_UUID_DIR/__executable" # `adb` can only handle commands under a certain length. No matter what the original executable's name, on device we call it `__executable`. 12 | DEVICE_CMD="$DEVICE_UUID_DIR/__cmd" # This is the file containing the command we'll use to run the executable on the device. 13 | DEVICE_RUNDROID="$DEVICE_UUID_DIR/__rundroid" # This is the final wrapper, the script we use to run the test and capture its output. 14 | 15 | # Output from running the executable on the device will be piped into these files. 16 | DEVICE_STDOUT="$DEVICE_UUID_DIR/__stdout" 17 | DEVICE_EXITCODE="$DEVICE_UUID_DIR/__exitcode" 18 | 19 | # Create the temporary directory on the device, 20 | # then push the executable to that directory. 21 | adb shell mkdir -p "$DEVICE_UUID_DIR" 22 | adb push "$EXECUTABLE" "$DEVICE_EXECUTABLE" 2>/dev/null || exit 1 23 | 24 | # Push wrapper scripts to the device. First, we need a script that executes the built 25 | # Swift executable with the command-line arguments `rundroid` was invoked with. 26 | # We put that in a shellscript, push it to the device, and make it executable. 27 | TMP_CMD=$(mktemp /tmp/rundroid_cmd.XXXXXX) 28 | echo "LD_LIBRARY_PATH=$DEVICE_UUID_DIR:$DEVICE_TMP_DIR $DEVICE_EXECUTABLE $@" > "$TMP_CMD" 29 | adb push "$TMP_CMD" "$DEVICE_CMD" 2>/dev/null 30 | adb shell chmod 755 "$DEVICE_CMD" || exit 1 31 | 32 | # This script writes the output from the test executable to a file named 33 | # "__stdout", and if the test executable succeeds, writes "RUNDROID_SUCCEEDED" 34 | # to a file named "__exitcode". We do this because `adb shell` does not report 35 | # the exit code of the command it executes on the device. 36 | adb shell "echo \"$DEVICE_CMD > $DEVICE_STDOUT && echo \"RUNDROID_SUCCEEDED\" > $DEVICE_EXITCODE\" > $DEVICE_RUNDROID" || exit 1 37 | adb shell chmod 755 "$DEVICE_RUNDROID" || exit 1 38 | 39 | # We've pushed everything we need to the device. Now execute the wrapper script. 40 | adb shell "$DEVICE_RUNDROID" 41 | 42 | # First, check whether the executable succeeded on device. 43 | TMP_STDOUT=$(mktemp /tmp/rundroid_stdout.XXXXXX) 44 | adb shell cat "$DEVICE_EXITCODE" > "$TMP_STDOUT" 45 | if ! grep -q "RUNDROID_SUCCEEDED" "$TMP_STDOUT"; then 46 | echo "" 47 | echo "Executable '$DEVICE_EXECUTABLE' exited with a non-zero code on the Android device." 48 | echo "Use the following command to see its output: 'adb shell $DEVICE_CMD'" 49 | echo "" 50 | echo "Contents of '$DEVICE_STDOUT':" 51 | adb shell cat "$DEVICE_STDOUT" 52 | echo "" 53 | echo "Contents of '$DEVICE_EXITCODE':" 54 | adb shell cat "$DEVICE_EXITCODE" 55 | echo "" 56 | echo "Re-running executable:" 57 | echo "$ adb shell $DEVICE_CMD" 58 | 59 | # Exit early. The output isn't passed to FileCheck, nor are any 60 | # temporary directories removed; this allows the user to re-run 61 | # the executable on the device. 62 | adb shell "$DEVICE_CMD" && exit 1 63 | fi 64 | 65 | # Then pass the test output to FileCheck. 66 | adb shell cat "$DEVICE_STDOUT" 67 | 68 | # Finally, remove all run artifacts. 69 | adb shell rm -rf "$DEVICE_UUID_DIR" 70 | --------------------------------------------------------------------------------