ソースを参照

cross-platform: Embed ICU statically

Download ICU 57 [ if user accepts the license ] and build
Link to ChakraCore statically
Oguz Bastemur 9 年 前
コミット
5dbf96f8e7
3 ファイル変更96 行追加7 行削除
  1. 2 0
      .gitignore
  2. 29 7
      CMakeLists.txt
  3. 65 0
      build.sh

+ 2 - 0
.gitignore

@@ -59,3 +59,5 @@ install_manifest.txt
 *.o
 Makefile
 pal/src/config.h
+
+deps/

+ 29 - 7
CMakeLists.txt

@@ -24,6 +24,14 @@ if(ICU_SETTINGS_RESET)
   unset(ICU_INCLUDE_PATH_SH CACHE)
   unset(NO_ICU_PATH_GIVEN_SH CACHE)
   unset(NO_ICU_PATH_GIVEN CACHE)
+  unset(CC_EMBED_ICU_SH CACHE)
+endif()
+
+if(CC_EMBED_ICU_SH)
+  unset(CC_EMBED_ICU_SH CACHE)
+  set(CC_EMBED_ICU 1)
+  set(ICU_INCLUDE_PATH "deps/icu/source/output/include/")
+  add_definitions(-DU_STATIC_IMPLEMENTATION)
 endif()
 
 if(ICU_INCLUDE_PATH_SH)
@@ -62,12 +70,24 @@ if(ICU_INCLUDE_PATH)
       ${ICUDATA}
       )
   endif()
-endif()
+elseif(CC_EMBED_ICU)
+  set(ICU_CC_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../deps/icu/source/output/lib/")
+  find_library(ICUUC icuuc PATHS ${ICU_CC_PATH} NO_DEFAULT_PATH)
+  find_library(ICU18 icui18n PATHS ${ICU_CC_PATH} NO_DEFAULT_PATH)
+  find_library(ICUDATA icudata PATHS ${ICU_CC_PATH} NO_DEFAULT_PATH)
+  set(ICULIB
+    ${ICUUC}
+    ${ICU18}
+    ${ICUDATA}
+    )
+ endif()
 
 if(CMAKE_SYSTEM_NAME STREQUAL Linux)
     if(NOT ICULIB)
       if(NOT NO_ICU_PATH_GIVEN)
-        set(ICULIB "icuuc")
+        if(NOT CC_EMBED_ICU)
+          set(ICULIB "icuuc")
+        endif()
         add_definitions(-DHAS_REAL_ICU=1)
       endif()
     endif()
@@ -86,11 +106,13 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
 
     if(NOT ICULIB)
       if(NOT NO_ICU_PATH_GIVEN)
-        set(ICULIB "icucore")
         add_definitions(-DHAS_REAL_ICU=1)
-        add_definitions(
-          -DU_DISABLE_RENAMING=1 #in case we link against to an older binary of icu
-          )
+        if(NOT CC_EMBED_ICU)
+          set(ICULIB "icucore")
+          add_definitions(
+            -DU_DISABLE_RENAMING=1 #in case we link against to an older binary of icu
+            )
+        endif()
         message("using ICU from system default: ${ICULIB}")
       endif()
     endif()
@@ -109,7 +131,7 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
     set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} \
         -mmacosx-version-min=10.7")
 else()
-    clr_unknown_arch()
+    message(FATAL_ERROR "This OS is not supported")
 endif()
 
 if(CLR_CMAKE_PLATFORM_UNIX_TARGET_AMD64)

+ 65 - 0
build.sh

@@ -14,6 +14,13 @@ SAFE_RUN() {
     echo $SF_RETURN_VALUE
 }
 
+ERROR_EXIT() {
+    if [[ $? != 0 ]]; then
+        echo $($1 2>&1)
+        exit 1;
+    fi
+}
+
 PRINT_USAGE() {
     echo ""
     echo "[ChakraCore Build Script Help]"
@@ -24,6 +31,7 @@ PRINT_USAGE() {
     echo "      --cxx=PATH       Path to Clang++ (see example below)"
     echo "      --cc=PATH        Path to Clang   (see example below)"
     echo "  -d, --debug          Debug build (by default Release build)"
+    echo "      --embed-icu      Download and embed ICU-57 statically"
     echo "  -h, --help           Show help"
     echo "      --icu=PATH       Path to ICU include folder (see example below)"
     echo "  -j [N], --jobs[=N]   Multicore build, allow N jobs at once"
@@ -57,6 +65,20 @@ ICU_PATH="-DICU_SETTINGS_RESET=1"
 STATIC_LIBRARY="-DSHARED_LIBRARY_SH=1"
 WITHOUT_FEATURES=""
 CREATE_DEB=0
+OS_LINUX=0
+OS_APT_GET=0
+OS_UNIX=0
+
+if [ -f "/proc/version" ]; then
+    OS_LINUX=1
+    PROC_INFO=$(cat /proc/version)
+    if [[ $PROC_INFO =~ 'Ubuntu' || $PROC_INFO =~ 'Debian'
+       || $PROC_INFO =~ 'Linaro' ]]; then
+        OS_APT_GET=1
+    fi
+else
+    OS_UNIX=1
+fi
 
 while [[ $# -gt 0 ]]; do
     case "$1" in
@@ -83,6 +105,49 @@ while [[ $# -gt 0 ]]; do
         BUILD_TYPE="Debug"
         ;;
 
+    --embed-icu)
+        if [ ! -d "${CHAKRACORE_DIR}/deps/icu/source/output" ]; then
+            ICU_URL="http://source.icu-project.org/repos/icu/icu/tags/release-57-1"
+            echo -e "\n----------------------------------------------------------------"
+            echo -e "\nThis script will download ICU-LIB from\n${ICU_URL}\n"
+            echo "It is licensed to you by its publisher, not Microsoft."
+            echo "Microsoft is not responsible for the software."
+            echo "Your installation and use of ICU-LIB is subject to the publisher’s terms available here:"
+            echo -e "http://www.unicode.org/copyright.html#License\n"
+            echo -e "----------------------------------------------------------------\n"
+            echo "If you don't agree, press Ctrl+C to terminate"
+            read -t 10 -p "Hit ENTER to continue (or wait 10 seconds)"
+            SAFE_RUN `mkdir -p ${CHAKRACORE_DIR}/deps/`
+            cd "${CHAKRACORE_DIR}/deps/";
+            ABS_DIR=`pwd`
+            if [ ! -d "${ABS_DIR}/icu/" ]; then
+                echo "Downloading ICU ${ICU_URL}"
+                if [ ! -f "/usr/bin/svn" ]; then
+                    echo -e "\nYou should install 'svn' client in order to use this feature"
+                    if [ $OS_APT_GET == 1 ]; then
+                        echo "tip: Try 'sudo apt-get install subversion'"
+                    fi
+                    exit 1
+                fi
+                svn export -q $ICU_URL icu
+                ERROR_EXIT "rm -rf ${ABS_DIR}/icu/"
+            fi
+
+            cd "${ABS_DIR}/icu/source";./configure --with-data-packaging=static\
+                    --prefix="${ABS_DIR}/icu/source/output/"\
+                    --enable-static --disable-shared --with-library-bits=64\
+                    --disable-icuio --disable-layout\
+                    CXXFLAGS="-fPIC" CFLAGS="-fPIC"
+
+            ERROR_EXIT "rm -rf ${ABS_DIR}/icu/source/output/"
+            make STATICCFLAGS="-fPIC" STATICCXXFLAGS="-fPIC" STATICCPPFLAGS="-DPIC" install
+            ERROR_EXIT "rm -rf ${ABS_DIR}/icu/source/output/"
+            cd "${ABS_DIR}/../"
+        fi
+        ICU_PATH="-DCC_EMBED_ICU_SH=1"
+        ;;
+
+
     -t | --test-build)
         BUILD_TYPE="Test"
         ;;