Skip to content

Commit e961088

Browse files
authored
Merge pull request #6 from SoftwareMansion/intlFlavor
Intl flavor
2 parents 890d898 + e7cda2f commit e961088

File tree

23 files changed

+296
-169
lines changed

23 files changed

+296
-169
lines changed

README.md

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ As mentioned the list of dependencies is huge, we tried to list everything that
3333
3. `./icu-prep.sh`
3434
4. `./jsc-prep.sh`
3535
5. `./all.sh`
36-
6. `./gradlew installArchives` (add `-w /bitrise/src/lib` to `docker run` args)
36+
6. `./gradlew lib:installArchives libIntl:installArchives` (add `-w /bitrise/src/lib` to `docker run` args)
3737

3838
The Maven repo containing the android-jsc AAR will be available at `./lib/android`.
3939

@@ -106,17 +106,37 @@ As a part of this project we provide a patch to the React Native source code tha
106106
| binary size (arm64) | N/A | 6.7 MiB |
107107
| binary size (x86_64) | N/A | 7.4 MiB |
108108

109-
## ICU data
109+
## International variant
110110

111-
ICU data are data tables for ICU to provide i18n features such as collation and date/time localization ([read more](http://userguide.icu-project.org/icudata)). Starting with `216113.0.0-beta.6` by default we provide the build with date/time l18n data only (~2.0 MiB per architecture). This allows you to use `Intl.DateTimeFormat` and `Date.toLocaleString`.
111+
Starting with <unreleased> version, we provide two build variants which differ in i18n support.
112112

113-
### Building ICU with no data
113+
### Default variant
114114

115-
Just uncomment two lines in `icu.sh` responsible for copying `stubdata` lib. This saves ~2.0 MiB per architecture.
115+
By default we ship with no international support. Methods like `Date.toLocaleString` will act as `Date.toString`. `String.localeCompare` will just compare each character's byte value.
116116

117-
### Building ICU also with collation data
117+
### International variant
118+
119+
International variant includes ICU i18n library and necessary data allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that give correct results when using with locales other than `en-US`. Note that this variant is about 6MiB larger per architecture than default.
120+
121+
To use this variant instead replace patch from the third installation step with:
122+
123+
```diff
124+
}
125+
126+
+configurations.all {
127+
+ resolutionStrategy {
128+
+ eachDependency { DependencyResolveDetails details ->
129+
+ if (details.requested.name == 'android-jsc') {
130+
+ details.useTarget group: details.requested.group, name: 'android-jsc-intl', version: 'r216113'
131+
+ }
132+
+ }
133+
+ }
134+
+}
135+
136+
dependencies {
137+
compile fileTree(dir: "libs", include: ["*.jar"])
138+
```
118139

119-
Modify `icu-prep.sh` to use `patches/icu-collation.patch` instead of `patches/icu.patch`. This adds additional ~2.2 MiB per architecture.
120140

121141
## Credits
122142

all.sh

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
#!/bin/bash
22

3-
for arch in arm arm64 x86 x86_64
4-
do
5-
JSC_ARCH=$arch ./toolchain.sh
6-
JSC_ARCH=$arch ./icu.sh
7-
JSC_ARCH=$arch ./jsc.sh
8-
done
3+
compile() {
4+
for arch in arm arm64 x86 x86_64
5+
do
6+
export JSC_ARCH=$arch
7+
./toolchain.sh
8+
./icu.sh
9+
./jsc.sh
10+
done
11+
}
12+
13+
export FLAVOR=no-intl
14+
export ENABLE_INTL=0
15+
compile
16+
17+
18+
export FLAVOR=intl
19+
export ENABLE_INTL=1
20+
compile

common.sh

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,33 @@
11
#!/bin/bash
22

3+
4+
# functions
5+
fix_zero_value_flag() {
6+
flag=$1
7+
var="ENABLE_$flag"
8+
if [[ ${!var} == 0 ]]; then unset "$var"; fi
9+
}
10+
11+
process_switch_options() {
12+
flag=$1
13+
var="ENABLE_$flag"
14+
if [[ ${!var} ]]; then
15+
suffix="ON"
16+
else
17+
suffix="OFF"
18+
fi
19+
var2="SWITCH_COMMON_CFLAGS_${flag}_${suffix}"
20+
readonly "SWITCH_COMMON_CFLAGS_${flag}"="${!var2}"
21+
var2="SWITCH_BUILD_WEBKIT_OPTIONS_${flag}_${suffix}"
22+
readonly "SWITCH_BUILD_WEBKIT_OPTIONS_${flag}"="${!var2}"
23+
}
24+
325
if ! [[ $ROOTDIR ]]; then ROOTDIR=`pwd`; fi
426
ARCH=$JSC_ARCH
527

628
ANDROID_API=21
729

830
# platform specific settings
9-
1031
CROSS_COMPILE_PLATFORM_arm="arm-linux-androideabi"
1132
CROSS_COMPILE_PLATFORM_arm64="aarch64-linux-android"
1233
CROSS_COMPILE_PLATFORM_x86="i686-linux-android"
@@ -17,6 +38,12 @@ var="CROSS_COMPILE_PLATFORM_$JSC_ARCH"
1738
CROSS_COMPILE_PLATFORM=${!var}
1839
TOOLCHAIN_DIR=$ROOTDIR/target/toolchains/$CROSS_COMPILE_PLATFORM
1940

41+
# options flags
42+
# INTL
43+
SWITCH_COMMON_CFLAGS_INTL_OFF="-DUCONFIG_NO_COLLATION=1 -DUCONFIG_NO_FORMATTING=1"
44+
SWITCH_BUILD_WEBKIT_OPTIONS_INTL_OFF="--no-intl"
45+
SWITCH_BUILD_WEBKIT_OPTIONS_INTL_ON="--intl"
46+
2047
# settings
2148
TOOLCHAIN_LINK_DIR_arm="$TOOLCHAIN_DIR/$CROSS_COMPILE_PLATFORM/lib/armv7-a"
2249
PLATFORM_CFLAGS_arm=" \
@@ -73,9 +100,13 @@ var="JNI_ARCH_$JSC_ARCH"
73100
JNI_ARCH=${!var}
74101
var="TOOLCHAIN_LINK_DIR_$JSC_ARCH"
75102
TOOLCHAIN_LINK_DIR=${!var}
103+
# switches
104+
fix_zero_value_flag "INTL"
105+
process_switch_options "INTL"
76106

77107
# checks
78108
err=false
109+
if ! [[ $FLAVOR ]]; then echo "set FLAVOR to the name of the flavor"; err=true; fi
79110
if ! [[ $CROSS_COMPILE_PLATFORM ]]; then echo "set JSC_ARCH to one of {arm,arm64,x86,x86_64}"; err=true; fi
80111
if ! [[ $ANDROID_HOME ]]; then echo "set ANDROID_HOME to android sdk dir"; err=true; fi
81112
if ! [[ $ANDROID_NDK ]]; then echo "set ANDROID_NDK to android ndk dir"; err=true; fi
@@ -102,6 +133,7 @@ COMMON_CFLAGS=" \
102133
-fPIC \
103134
-fvisibility=hidden \
104135
-DNDEBUG \
136+
$SWITCH_COMMON_CFLAGS_INTL \
105137
"
106138

107139
COMMON_CXXFLAGS=" \
@@ -112,5 +144,5 @@ ICU_CFLAGS="$COMMON_CFLAGS $PLATFORM_CFLAGS -Os"
112144
ICU_CXXFLAGS="$COMMON_CXXFLAGS $ICU_CFLAGS -Os"
113145
ICU_LDFLAGS="$COMMON_LDFLAGS $PLATFORM_LDFLAGS"
114146

115-
INSTALL_DIR=$ROOTDIR/lib/distribution/jsc/lib/$JNI_ARCH
147+
INSTALL_DIR=$ROOTDIR/lib/distribution-${FLAVOR}/jsc/lib/$JNI_ARCH
116148
mkdir -p $INSTALL_DIR

icu.sh

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ source './common.sh'
44

55
ICU_VERSION="56.1"
66

7-
BUILD_DIR=$ROOTDIR/target/icu/$CROSS_COMPILE_PLATFORM
7+
BUILD_DIR=$ROOTDIR/target/icu/${CROSS_COMPILE_PLATFORM}-${FLAVOR}
88
rm -rf $BUILD_DIR
99
mkdir -p $BUILD_DIR
1010
cd $BUILD_DIR
@@ -36,10 +36,13 @@ PATH=$TOOLCHAIN_DIR/bin:$PATH
3636

3737
make -j5
3838

39-
cp lib/libicudata_jsc.so $INSTALL_DIR/libicudata_jsc.so
39+
if [[ $ENABLE_INTL ]]; then
40+
cp lib/libicudata_jsc.so $INSTALL_DIR/libicudata_jsc.so
41+
cp lib/libicui18n_jsc.so.$ICU_VERSION $INSTALL_DIR/libicui18n_jsc.so
42+
else
43+
rm lib/libicui18n_jsc.so*
44+
cp stubdata/libicudata_jsc.so.$ICU_VERSION lib/
45+
cp stubdata/libicudata_jsc.so.$ICU_VERSION $INSTALL_DIR/libicudata_jsc.so
46+
fi
4047

41-
#cp stubdata/libicudata_jsc.so.$ICU_VERSION lib/
42-
#cp stubdata/libicudata_jsc.so.$ICU_VERSION $INSTALL_DIR/libicudata_jsc.so
43-
44-
cp lib/libicui18n_jsc.so.$ICU_VERSION $INSTALL_DIR/libicui18n_jsc.so
4548
cp lib/libicuuc_jsc.so.$ICU_VERSION $INSTALL_DIR/libicuuc_jsc.so

jsc-prep.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,4 @@
22

33
ROOTDIR=`pwd`
44

5-
cd $ROOTDIR/target
6-
75
patch -p0 < $ROOTDIR/patches/jsc.patch

jsc.sh

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ source common.sh
44

55
PATH=$TOOLCHAIN_DIR/bin:$ANDROID_HOME/cmake/3.6.3155560/bin/:$PATH
66

7-
rm -rf target/webkit/$CROSS_COMPILE_PLATFORM
7+
# conditional patch
8+
if ! [[ $ENABLE_INTL ]]; then
9+
patch -p0 < $ROOTDIR/patches/intl/icu-disabled.patch
10+
fi
11+
12+
rm -rf target/webkit/$CROSS_COMPILE_PLATFORM-${FLAVOR}
813
rm -rf target/webkit/WebKitBuild
914
cd target/webkit/Tools/Scripts
1015

@@ -26,7 +31,7 @@ $PLATFORM_LDFLAGS \
2631
--jsc-only \
2732
--release \
2833
--jit \
29-
--intl \
34+
"$SWITCH_BUILD_WEBKIT_OPTIONS_INTL" \
3035
--no-webassembly \
3136
--no-xslt \
3237
--no-netscape-plugin-api \
@@ -36,7 +41,7 @@ $PLATFORM_LDFLAGS \
3641
-DCMAKE_SYSTEM_PROCESSOR=$ARCH \
3742
-DCMAKE_ANDROID_STANDALONE_TOOLCHAIN=$TOOLCHAIN_DIR \
3843
-DWEBKIT_LIBRARIES_INCLUDE_DIR=$ROOTDIR/target/icu/source/common \
39-
-DWEBKIT_LIBRARIES_LINK_DIR=$ROOTDIR/target/icu/$CROSS_COMPILE_PLATFORM/lib \
44+
-DWEBKIT_LIBRARIES_LINK_DIR=$ROOTDIR/target/icu/${CROSS_COMPILE_PLATFORM}-${FLAVOR}/lib \
4045
-DCMAKE_C_COMPILER=$CROSS_COMPILE_PLATFORM-clang \
4146
-DCMAKE_CXX_COMPILER=$CROSS_COMPILE_PLATFORM-clang \
4247
-DCMAKE_SYSROOT=$ANDROID_NDK/platforms/android-$ANDROID_API/arch-$ARCH \
@@ -49,5 +54,11 @@ $PLATFORM_LDFLAGS \
4954
"
5055

5156
cp $ROOTDIR/target/webkit/WebKitBuild/Release/lib/libjsc.so $INSTALL_DIR
52-
mv $ROOTDIR/target/webkit/WebKitBuild $ROOTDIR/target/webkit/$CROSS_COMPILE_PLATFORM
53-
cp $TOOLCHAIN_LINK_DIR/libc++_shared.so $INSTALL_DIR
57+
mv $ROOTDIR/target/webkit/WebKitBuild $ROOTDIR/target/webkit/${CROSS_COMPILE_PLATFORM}-${FLAVOR}
58+
cp $TOOLCHAIN_LINK_DIR/libc++_shared.so $INSTALL_DIR
59+
60+
# conditional patch undo
61+
cd $ROOTDIR
62+
if ! [[ $ENABLE_INTL ]]; then
63+
patch -p0 -R < $ROOTDIR/patches/intl/icu-disabled.patch
64+
fi

lib/.idea/gradle.xml

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/.idea/modules.xml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/distribution-intl/jsc/lib/.keep

Whitespace-only changes.

lib/distribution-no-intl/jsc/lib/.keep

Whitespace-only changes.

0 commit comments

Comments
 (0)