Skip to content

Commit

Permalink
Merge pull request #6 from SoftwareMansion/intlFlavor
Browse files Browse the repository at this point in the history
Intl flavor
  • Loading branch information
kmagiera authored Jul 12, 2017
2 parents 890d898 + e7cda2f commit e961088
Show file tree
Hide file tree
Showing 23 changed files with 296 additions and 169 deletions.
34 changes: 27 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ As mentioned the list of dependencies is huge, we tried to list everything that
3. `./icu-prep.sh`
4. `./jsc-prep.sh`
5. `./all.sh`
6. `./gradlew installArchives` (add `-w /bitrise/src/lib` to `docker run` args)
6. `./gradlew lib:installArchives libIntl:installArchives` (add `-w /bitrise/src/lib` to `docker run` args)

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

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

## ICU data
## International variant

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`.
Starting with <unreleased> version, we provide two build variants which differ in i18n support.

### Building ICU with no data
### Default variant

Just uncomment two lines in `icu.sh` responsible for copying `stubdata` lib. This saves ~2.0 MiB per architecture.
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.

### Building ICU also with collation data
### International variant

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.

To use this variant instead replace patch from the third installation step with:

```diff
}

+configurations.all {
+ resolutionStrategy {
+ eachDependency { DependencyResolveDetails details ->
+ if (details.requested.name == 'android-jsc') {
+ details.useTarget group: details.requested.group, name: 'android-jsc-intl', version: 'r216113'
+ }
+ }
+ }
+}

dependencies {
compile fileTree(dir: "libs", include: ["*.jar"])
```

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

## Credits

Expand Down
24 changes: 18 additions & 6 deletions all.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
#!/bin/bash

for arch in arm arm64 x86 x86_64
do
JSC_ARCH=$arch ./toolchain.sh
JSC_ARCH=$arch ./icu.sh
JSC_ARCH=$arch ./jsc.sh
done
compile() {
for arch in arm arm64 x86 x86_64
do
export JSC_ARCH=$arch
./toolchain.sh
./icu.sh
./jsc.sh
done
}

export FLAVOR=no-intl
export ENABLE_INTL=0
compile


export FLAVOR=intl
export ENABLE_INTL=1
compile
36 changes: 34 additions & 2 deletions common.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,33 @@
#!/bin/bash


# functions
fix_zero_value_flag() {
flag=$1
var="ENABLE_$flag"
if [[ ${!var} == 0 ]]; then unset "$var"; fi
}

process_switch_options() {
flag=$1
var="ENABLE_$flag"
if [[ ${!var} ]]; then
suffix="ON"
else
suffix="OFF"
fi
var2="SWITCH_COMMON_CFLAGS_${flag}_${suffix}"
readonly "SWITCH_COMMON_CFLAGS_${flag}"="${!var2}"
var2="SWITCH_BUILD_WEBKIT_OPTIONS_${flag}_${suffix}"
readonly "SWITCH_BUILD_WEBKIT_OPTIONS_${flag}"="${!var2}"
}

if ! [[ $ROOTDIR ]]; then ROOTDIR=`pwd`; fi
ARCH=$JSC_ARCH

ANDROID_API=21

# platform specific settings

CROSS_COMPILE_PLATFORM_arm="arm-linux-androideabi"
CROSS_COMPILE_PLATFORM_arm64="aarch64-linux-android"
CROSS_COMPILE_PLATFORM_x86="i686-linux-android"
Expand All @@ -17,6 +38,12 @@ var="CROSS_COMPILE_PLATFORM_$JSC_ARCH"
CROSS_COMPILE_PLATFORM=${!var}
TOOLCHAIN_DIR=$ROOTDIR/target/toolchains/$CROSS_COMPILE_PLATFORM

# options flags
# INTL
SWITCH_COMMON_CFLAGS_INTL_OFF="-DUCONFIG_NO_COLLATION=1 -DUCONFIG_NO_FORMATTING=1"
SWITCH_BUILD_WEBKIT_OPTIONS_INTL_OFF="--no-intl"
SWITCH_BUILD_WEBKIT_OPTIONS_INTL_ON="--intl"

# settings
TOOLCHAIN_LINK_DIR_arm="$TOOLCHAIN_DIR/$CROSS_COMPILE_PLATFORM/lib/armv7-a"
PLATFORM_CFLAGS_arm=" \
Expand Down Expand Up @@ -73,9 +100,13 @@ var="JNI_ARCH_$JSC_ARCH"
JNI_ARCH=${!var}
var="TOOLCHAIN_LINK_DIR_$JSC_ARCH"
TOOLCHAIN_LINK_DIR=${!var}
# switches
fix_zero_value_flag "INTL"
process_switch_options "INTL"

# checks
err=false
if ! [[ $FLAVOR ]]; then echo "set FLAVOR to the name of the flavor"; err=true; fi
if ! [[ $CROSS_COMPILE_PLATFORM ]]; then echo "set JSC_ARCH to one of {arm,arm64,x86,x86_64}"; err=true; fi
if ! [[ $ANDROID_HOME ]]; then echo "set ANDROID_HOME to android sdk dir"; err=true; fi
if ! [[ $ANDROID_NDK ]]; then echo "set ANDROID_NDK to android ndk dir"; err=true; fi
Expand All @@ -102,6 +133,7 @@ COMMON_CFLAGS=" \
-fPIC \
-fvisibility=hidden \
-DNDEBUG \
$SWITCH_COMMON_CFLAGS_INTL \
"

COMMON_CXXFLAGS=" \
Expand All @@ -112,5 +144,5 @@ ICU_CFLAGS="$COMMON_CFLAGS $PLATFORM_CFLAGS -Os"
ICU_CXXFLAGS="$COMMON_CXXFLAGS $ICU_CFLAGS -Os"
ICU_LDFLAGS="$COMMON_LDFLAGS $PLATFORM_LDFLAGS"

INSTALL_DIR=$ROOTDIR/lib/distribution/jsc/lib/$JNI_ARCH
INSTALL_DIR=$ROOTDIR/lib/distribution-${FLAVOR}/jsc/lib/$JNI_ARCH
mkdir -p $INSTALL_DIR
15 changes: 9 additions & 6 deletions icu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ source './common.sh'

ICU_VERSION="56.1"

BUILD_DIR=$ROOTDIR/target/icu/$CROSS_COMPILE_PLATFORM
BUILD_DIR=$ROOTDIR/target/icu/${CROSS_COMPILE_PLATFORM}-${FLAVOR}
rm -rf $BUILD_DIR
mkdir -p $BUILD_DIR
cd $BUILD_DIR
Expand Down Expand Up @@ -36,10 +36,13 @@ PATH=$TOOLCHAIN_DIR/bin:$PATH

make -j5

cp lib/libicudata_jsc.so $INSTALL_DIR/libicudata_jsc.so
if [[ $ENABLE_INTL ]]; then
cp lib/libicudata_jsc.so $INSTALL_DIR/libicudata_jsc.so
cp lib/libicui18n_jsc.so.$ICU_VERSION $INSTALL_DIR/libicui18n_jsc.so
else
rm lib/libicui18n_jsc.so*
cp stubdata/libicudata_jsc.so.$ICU_VERSION lib/
cp stubdata/libicudata_jsc.so.$ICU_VERSION $INSTALL_DIR/libicudata_jsc.so
fi

#cp stubdata/libicudata_jsc.so.$ICU_VERSION lib/
#cp stubdata/libicudata_jsc.so.$ICU_VERSION $INSTALL_DIR/libicudata_jsc.so

cp lib/libicui18n_jsc.so.$ICU_VERSION $INSTALL_DIR/libicui18n_jsc.so
cp lib/libicuuc_jsc.so.$ICU_VERSION $INSTALL_DIR/libicuuc_jsc.so
2 changes: 0 additions & 2 deletions jsc-prep.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@

ROOTDIR=`pwd`

cd $ROOTDIR/target

patch -p0 < $ROOTDIR/patches/jsc.patch
21 changes: 16 additions & 5 deletions jsc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ source common.sh

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

rm -rf target/webkit/$CROSS_COMPILE_PLATFORM
# conditional patch
if ! [[ $ENABLE_INTL ]]; then
patch -p0 < $ROOTDIR/patches/intl/icu-disabled.patch
fi

rm -rf target/webkit/$CROSS_COMPILE_PLATFORM-${FLAVOR}
rm -rf target/webkit/WebKitBuild
cd target/webkit/Tools/Scripts

Expand All @@ -26,7 +31,7 @@ $PLATFORM_LDFLAGS \
--jsc-only \
--release \
--jit \
--intl \
"$SWITCH_BUILD_WEBKIT_OPTIONS_INTL" \
--no-webassembly \
--no-xslt \
--no-netscape-plugin-api \
Expand All @@ -36,7 +41,7 @@ $PLATFORM_LDFLAGS \
-DCMAKE_SYSTEM_PROCESSOR=$ARCH \
-DCMAKE_ANDROID_STANDALONE_TOOLCHAIN=$TOOLCHAIN_DIR \
-DWEBKIT_LIBRARIES_INCLUDE_DIR=$ROOTDIR/target/icu/source/common \
-DWEBKIT_LIBRARIES_LINK_DIR=$ROOTDIR/target/icu/$CROSS_COMPILE_PLATFORM/lib \
-DWEBKIT_LIBRARIES_LINK_DIR=$ROOTDIR/target/icu/${CROSS_COMPILE_PLATFORM}-${FLAVOR}/lib \
-DCMAKE_C_COMPILER=$CROSS_COMPILE_PLATFORM-clang \
-DCMAKE_CXX_COMPILER=$CROSS_COMPILE_PLATFORM-clang \
-DCMAKE_SYSROOT=$ANDROID_NDK/platforms/android-$ANDROID_API/arch-$ARCH \
Expand All @@ -49,5 +54,11 @@ $PLATFORM_LDFLAGS \
"

cp $ROOTDIR/target/webkit/WebKitBuild/Release/lib/libjsc.so $INSTALL_DIR
mv $ROOTDIR/target/webkit/WebKitBuild $ROOTDIR/target/webkit/$CROSS_COMPILE_PLATFORM
cp $TOOLCHAIN_LINK_DIR/libc++_shared.so $INSTALL_DIR
mv $ROOTDIR/target/webkit/WebKitBuild $ROOTDIR/target/webkit/${CROSS_COMPILE_PLATFORM}-${FLAVOR}
cp $TOOLCHAIN_LINK_DIR/libc++_shared.so $INSTALL_DIR

# conditional patch undo
cd $ROOTDIR
if ! [[ $ENABLE_INTL ]]; then
patch -p0 -R < $ROOTDIR/patches/intl/icu-disabled.patch
fi
3 changes: 2 additions & 1 deletion lib/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions lib/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
Empty file.
5 changes: 1 addition & 4 deletions lib/lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@ android {

sourceSets {
main {
jniLibs.srcDirs = ['../distribution/jsc/lib']
jniLibs.srcDirs = ['../distribution-no-intl/jsc/lib']
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
apply from: 'release.gradle'
15 changes: 0 additions & 15 deletions lib/lib/release.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
// Copyright 2015-present Facebook. All Rights Reserved.
// https://github.com/facebook/react-native/blob/master/ReactAndroid/release.gradle
apply plugin: 'maven'
apply plugin: 'signing'

// Gradle tasks for publishing to maven
// 1) To install in local maven repo use :installArchives task
// 2) To upload artifact to maven central use: :uploadArchives (you'd need to have the permission to do that)

def isReleaseBuild() {
return VERSION_NAME.contains('SNAPSHOT') == false
}

def configureReactNativePom(def pom) {
pom.project {
Expand All @@ -24,15 +15,9 @@ afterEvaluate { project ->
version = VERSION_NAME
group = GROUP

signing {
required { isReleaseBuild() && gradle.taskGraph.hasTask('uploadArchives') }
sign configurations.archives
}

task installArchives(type: Upload) {
configuration = configurations.archives
repositories.mavenDeployer {
// Deploy to react-native/android, ready to publish to npm
repository url: "file://${projectDir}/../android"

configureReactNativePom pom
Expand Down
1 change: 1 addition & 0 deletions lib/libIntl/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
23 changes: 23 additions & 0 deletions lib/libIntl/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
}

sourceSets {
main {
jniLibs.srcDirs = ['../distribution-intl/jsc/lib']
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
apply from: 'release.gradle'
6 changes: 6 additions & 0 deletions lib/libIntl/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
VERSION_NAME=r216113
GROUP=org.webkit

POM_NAME=android-jsc
POM_ARTIFACT_ID=android-jsc-intl
POM_PACKAGING=aar
25 changes: 25 additions & 0 deletions lib/libIntl/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/lukaszgurdek/Library/Android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
26 changes: 26 additions & 0 deletions lib/libIntl/release.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2015-present Facebook. All Rights Reserved.
// https://github.com/facebook/react-native/blob/master/ReactAndroid/release.gradle
apply plugin: 'maven'

def configureReactNativePom(def pom) {
pom.project {
name POM_NAME
artifactId POM_ARTIFACT_ID
packaging POM_PACKAGING
}
}


afterEvaluate { project ->
version = VERSION_NAME
group = GROUP

task installArchives(type: Upload) {
configuration = configurations.archives
repositories.mavenDeployer {
repository url: "file://${projectDir}/../android"

configureReactNativePom pom
}
}
}
3 changes: 3 additions & 0 deletions lib/libIntl/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.swmansion.myjsc">
</manifest>
Loading

0 comments on commit e961088

Please sign in to comment.