Skip to content
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

Create build-android.sh and update instructions #8

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
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
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
libiconv-libicu-android
=======================

## Swift android instructions

Follow the original instructions, but instead of step (3), run ./build-android.sh instead


## Original instructions

Port of libiconv and libicu to Android

You will need NDK r15, curl, autoconf, automake, libtool, and git installed.

There are no sources and no patches - everything is done with magical build scripts,
just run build.sh and enjoy.
Don't forget to strip them, because they are huge with debug info included.
There are no sources and no patches - everything is done with magical build scripts:

(1) Make sure "which ndk-build" shows the correct version to build from

(2) The scripts assume NDK/toolchain/... version 4.9. If otherwise, edit all the *.sh to
change GCCVER=4.9 as desired.

(3) Run "./build.sh" and enjoy!

(4) Don't forget to strip them, because they are huge with debug info included.

There is no mips architecture, because there are very few devices using this architecture in the wild.

Expand Down
33 changes: 33 additions & 0 deletions build-android.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

#
# *** build-android.sh ***
#
# This script automates editing the libiconv and libicu source code and build
# directives to build the libraries correctly to use when building swift for
# Android. Original instructions that this script automates are available at
# https://github.com/apple/swift/blob/4bf6f5475ddf5c9ff4a7e383bac41c8a0464cd90/docs/Android.md#adding-swift-suffix-to-icu-libraries
#

set -e

echo "warning: this script assumes it's running from the root of the libiconv-libicu-android directory"

# Create armeabi-v7a dir
mkdir armeabi-v7a && cd armeabi-v7a
tar xvf ../icu4c-55_1-src.tgz
cd ..

# Patch icu configure file
patch -i swift-android-source-patches/build.patch

# Patch build.sh file
cd armeabi-v7a/icu/source/
patch -i ../../../swift-android-source-patches/icu-configure.patch
cd ../../..

# 🎉 Run build.sh, with the edited sources
./build.sh

echo "Done building 🎉🎉🎉"
echo "Check out the armeabi-v7a directory."
33 changes: 19 additions & 14 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ uname -s | grep -i "linux" && NCPU=`cat /proc/cpuinfo | grep -c -i processor`

NDK=`which ndk-build`
NDK=`dirname $NDK`
NDK=`readlink -f $NDK`
#NDK=`readlink -f $NDK`

export CLANG=1

for ARCH in armeabi armeabi-v7a arm64-v8a x86 x86_64; do
for ARCH in armeabi-v7a; do

cd $BUILDDIR

Expand All @@ -40,7 +40,7 @@ cd $BUILDDIR/$ARCH

# =========== libiconv.so ===========

[ -e libiconv.so ] || {
true || [ -e libiconv.so ] || {

rm -rf libiconv-1.15

Expand Down Expand Up @@ -159,16 +159,24 @@ cd $BUILDDIR/$ARCH

cd $BUILDDIR/$ARCH

[ -e libicuuc.a ] || {
[ -e libicuuc$LIBSUFFIX.a ] || {

rm -rf icu

tar xvf ../icu4c-59_1-src.tgz
[ -e ../icu4c-55_1-src.tgz ] || exit 1

tar xvf ../icu4c-55_1-src.tgz

# The ENVVAR LIBSUFFIX should add the suffix only to the libname and not to the symbols.
# ToDo: Find the right way in Swift to refer to an alternative library with symbol prefixing or any other method to remove this.
if $[ -n "$LIBSUFFIX" ]; then
patch -p0 < ../patches/icu_suffix_only_on_libname.patch
fi

cd icu/source

cp -f $BUILDDIR/config.sub .
cp -f $BUILDDIR/config.guess .
#cp -f $BUILDDIR/config.sub .
#cp -f $BUILDDIR/config.guess .

[ -d cross ] || {
mkdir cross
Expand All @@ -178,8 +186,6 @@ cd $BUILDDIR/$ARCH
cd ..
} || exit 1

sed -i "s@LD_SONAME *=.*@LD_SONAME =@g" config/mh-linux
sed -i "s%ln -s *%cp -f \$(dir \$@)/%g" config/mh-linux

env CFLAGS="-I$NDK/sources/android/support/include -frtti -fexceptions" \
LDFLAGS="-frtti -fexceptions -L$BUILDDIR/$ARCH/lib" \
Expand All @@ -189,28 +195,27 @@ cd $BUILDDIR/$ARCH
./configure \
--host=$GCCPREFIX \
--prefix=`pwd`/../../ \
--with-library-suffix=$LIBSUFFIX \
--with-cross-build=`pwd`/cross \
--enable-static --disable-shared \
--with-data-packaging=archive \
|| exit 1

# ICULEHB_CFLAGS="-I$BUILDDIR/$ARCH/include" \
# ICULEHB_LIBS="-licu-le-hb" \
# --enable-layoutex \

sed -i "s@^prefix *= *.*@prefix = .@" icudefs.mk || exit 1
sed -i.tmp 's/.$(SO_TARGET_VERSION_MAJOR)//' icudefs.mk
sed -i.tmp 's/$(PKGDATA_VERSIONING) -e/-e/' data/Makefile

env PATH=`pwd`:$PATH \
$BUILDDIR/setCrossEnvironment-$ARCH.sh \
make -j$NCPU VERBOSE=1 || exit 1

sed -i "s@^prefix *= *.*@prefix = `pwd`/../../@" icudefs.mk || exit 1

env PATH=`pwd`:$PATH \
$BUILDDIR/setCrossEnvironment-$ARCH.sh \
make V=1 install || exit 1

for f in libicudata libicutest libicui18n libicuio libicutu libicuuc; do
for f in libicudata$LIBSUFFIX libicutest$LIBSUFFIX libicui18n$LIBSUFFIX libicuio$LIBSUFFIX libicule$LIBSUFFIX libiculx$LIBSUFFIX libicutu$LIBSUFFIX libicuuc$LIBSUFFIX; do
#cp -f -H ../../lib/$f.so ../../
cp -f ../../lib/$f.a ../../
#$BUILDDIR/setCrossEnvironment-$ARCH.sh \
Expand Down
18 changes: 18 additions & 0 deletions patches/icu_suffix_only_on_libname.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--- icu/source/configure 2013-05-23 20:06:32.000000000 +0000
+++ icu/source/configure.patched 2018-02-21 23:35:25.934967613 +0000
@@ -7217,14 +7217,7 @@
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $msg" >&5
$as_echo "$msg" >&6; }

-if test "$ICULIBSUFFIX" != ""
-then
- U_HAVE_LIB_SUFFIX=1
- ICULIBSUFFIXCNAME=`echo _$ICULIBSUFFIX | sed 's/^A-Za-z0-9_/_/g'`
- UCONFIG_CPPFLAGS="${UCONFIG_CPPFLAGS} -DU_HAVE_LIB_SUFFIX=1 -DU_LIB_SUFFIX_C_NAME=${ICULIBSUFFIXCNAME} "
-else
- U_HAVE_LIB_SUFFIX=0
-fi
+U_HAVE_LIB_SUFFIX=0



24 changes: 19 additions & 5 deletions setCrossEnvironment-armeabi-v7a.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#!/bin/sh
#!/bin/bash

NDK_STL="libc++"

IFS='
'

MYARCH=linux-x86_64
if uname -s | grep -i "linux" > /dev/null ; then
MYARCH=linux-x86_64
MYARCH=linux-`arch`
fi
if uname -s | grep -i "darwin" > /dev/null ; then
MYARCH=darwin-x86_64
Expand All @@ -16,20 +18,32 @@ fi

NDK=`which ndk-build`
NDK=`dirname $NDK`
NDK=`readlink -f $NDK`
#NDK=`readlink -f $NDK`

grep "64.bit" "$NDK/RELEASE.TXT" >/dev/null 2>&1 && MYARCH="${MYARCH}_64"

#echo NDK $NDK
GCCPREFIX=arm-linux-androideabi
[ -z "$NDK_TOOLCHAIN_VERSION" ] && NDK_TOOLCHAIN_VERSION=4.9
[ -z "$PLATFORMVER" ] && PLATFORMVER=android-15
[ -z "$PLATFORMVER" ] && PLATFORMVER=android-16
GCCVER=4.9

LOCAL_PATH=`dirname $0`
if which realpath > /dev/null ; then
LOCAL_PATH=`realpath $LOCAL_PATH`
else
LOCAL_PATH=`cd $LOCAL_PATH && pwd`
fi
ARCH=armeabi-v7a

STL_CFLAGS="-isystem$NDK/sources/cxx-stl/gnu-libstdc++/$GCCVER/include \
-isystem$NDK/sources/cxx-stl/gnu-libstdc++/$GCCVER/libs/$ARCH/include"
STL_LDFLAGS="-L$NDK/sources/cxx-stl/gnu-libstdc++/$GCCVER/libs/$ARCH"
STL_LDLIB="-lgnustl_shared -lsupc++"
if [[ "$NDK_STL" == "libc++" ]] ; then
STL_CFLAGS="-isystem$NDK/sources/cxx-stl/llvm-libc++/include"
STL_LDFLAGS="-L$NDK/sources/cxx-stl/llvm-libc++/libs/$ARCH"
STL_LDLIB="-lc++_shared"
fi

CFLAGS="
-fexceptions
Expand Down
7 changes: 4 additions & 3 deletions setCrossEnvironment-armeabi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ IFS='

MYARCH=linux-x86_64
if uname -s | grep -i "linux" > /dev/null ; then
MYARCH=linux-x86_64
MYARCH=linux-`arch`
fi
if uname -s | grep -i "darwin" > /dev/null ; then
MYARCH=darwin-x86_64
Expand All @@ -16,12 +16,13 @@ fi

NDK=`which ndk-build`
NDK=`dirname $NDK`
NDK=`readlink -f $NDK`
#NDK=`readlink -f $NDK`

#echo NDK $NDK
GCCPREFIX=arm-linux-androideabi
[ -z "$NDK_TOOLCHAIN_VERSION" ] && NDK_TOOLCHAIN_VERSION=4.9
[ -z "$PLATFORMVER" ] && PLATFORMVER=android-15
GCCVER=4.9

LOCAL_PATH=`dirname $0`
if which realpath > /dev/null ; then
LOCAL_PATH=`realpath $LOCAL_PATH`
Expand Down
8 changes: 6 additions & 2 deletions setCrossEnvironment-x86.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ IFS='

MYARCH=linux-x86_64
if uname -s | grep -i "linux" > /dev/null ; then
MYARCH=linux-x86_64
MYARCH=linux-`arch`
fi
if uname -s | grep -i "darwin" > /dev/null ; then
MYARCH=darwin-x86_64
Expand All @@ -16,12 +16,16 @@ fi

NDK=`which ndk-build`
NDK=`dirname $NDK`
NDK=`readlink -f $NDK`
#NDK=`readlink -f $NDK`

grep "64.bit" "$NDK/RELEASE.TXT" >/dev/null 2>&1 && MYARCH="${MYARCH}_64"

#echo NDK $NDK
GCCPREFIX=i686-linux-android
[ -z "$NDK_TOOLCHAIN_VERSION" ] && NDK_TOOLCHAIN_VERSION=4.9
[ -z "$PLATFORMVER" ] && PLATFORMVER=android-15
GCCVER=4.9

LOCAL_PATH=`dirname $0`
if which realpath > /dev/null ; then
LOCAL_PATH=`realpath $LOCAL_PATH`
Expand Down
34 changes: 34 additions & 0 deletions swift-android-source-patches/build.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
--- build.sh 2018-01-19 09:56:47.000000000 -0800
+++ build.sh.new 2018-01-19 09:56:38.000000000 -0800
@@ -77,11 +77,11 @@

# =========== libicuXX.so ===========

-[ -e libicuuc.so ] || {
+[ -e libicuucswifswiftt.so ] || {

- [ -e ../icu4c-55_1-src.tgz ] || exit 1
+# [ -e ../icu4c-55_1-src.tgz ] || exit 1

- tar xvf ../icu4c-55_1-src.tgz
+# tar xvf ../icu4c-55_1-src.tgz

cd icu/source

@@ -104,6 +104,7 @@
./configure \
--host=arm-linux-androideabi \
--prefix=`pwd`/../../ \
+ --with-library-suffix=swift \
--with-cross-build=`pwd`/cross \
--enable-static --enable-shared \
|| exit 1
@@ -119,7 +120,7 @@
$BUILDDIR/setCrossEnvironment-$ARCH.sh \
make V=1 install || exit 1

- for f in libicudata libicutest libicui18n libicuio libicule libiculx libicutu libicuuc; do
+ for f in libicudataswift libicutestswift libicui18nswift libicuioswift libiculeswift libiculxswift libicutuswift libicuucswift; do
cp -f -H ../../lib/$f.so ../../
cp -f ../../lib/$f.a ../../
$BUILDDIR/setCrossEnvironment-$ARCH.sh \
22 changes: 22 additions & 0 deletions swift-android-source-patches/icu-configure.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--- armeabi-v7a/icu/source/configure 2018-01-18 17:31:55.000000000 -0800
+++ armeabi-v7a/icu/source/configure.new 2018-01-18 17:33:27.000000000 -0800
@@ -7599,14 +7599,14 @@
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $msg" >&5
$as_echo "$msg" >&6; }

-if test "$ICULIBSUFFIX" != ""
-then
- U_HAVE_LIB_SUFFIX=1
- ICULIBSUFFIXCNAME=`echo _$ICULIBSUFFIX | sed 's/^A-Za-z0-9_/_/g'`
- UCONFIG_CPPFLAGS="${UCONFIG_CPPFLAGS} -DU_HAVE_LIB_SUFFIX=1 -DU_LIB_SUFFIX_C_NAME=${ICULIBSUFFIXCNAME} "
-else
- U_HAVE_LIB_SUFFIX=0
-fi
+# if test "$ICULIBSUFFIX" != ""
+# then
+# U_HAVE_LIB_SUFFIX=1
+# ICULIBSUFFIXCNAME=`echo _$ICULIBSUFFIX | sed 's/^A-Za-z0-9_/_/g'`
+# UCONFIG_CPPFLAGS="${UCONFIG_CPPFLAGS} -DU_HAVE_LIB_SUFFIX=1 -DU_LIB_SUFFIX_C_NAME=${ICULIBSUFFIXCNAME} "
+# else
+U_HAVE_LIB_SUFFIX=0
+# fi