build.sh 5.8 KB
Newer Older
Y
Yan Chunwei 已提交
1
#!/bin/bash
2
set -ex
Y
Yan Chunwei 已提交
3 4 5 6 7 8 9 10 11

readonly CMAKE_COMMON_OPTIONS="-DWITH_GPU=OFF \
                               -DWITH_MKL=OFF \
                               -DWITH_LITE=ON \
                               -DLITE_WITH_CUDA=OFF \
                               -DLITE_WITH_X86=OFF \
                               -DLITE_WITH_ARM=ON \
                               -DLITE_WITH_LIGHT_WEIGHT_FRAMEWORK=ON"

12 13
readonly NUM_PROC=${LITE_BUILD_THREADS:-4}

14 15 16 17

# global variables
BUILD_EXTRA=OFF

18 19 20 21
readonly THIRDPARTY_TAR=https://paddle-inference-dist.bj.bcebos.com/PaddleLite/third-party-05b862.tar.gz

readonly workspace=$PWD

Y
Yan Chunwei 已提交
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
# for code gen, a source file is generated after a test, but is dependended by some targets in cmake.
# here we fake an empty file to make cmake works.
function prepare_workspace {
    # in build directory
    # 1. Prepare gen_code file
    GEN_CODE_PATH_PREFIX=lite/gen_code
    mkdir -p ./${GEN_CODE_PATH_PREFIX}
    touch ./${GEN_CODE_PATH_PREFIX}/__generated_code__.cc

    # 2.Prepare debug tool
    DEBUG_TOOL_PATH_PREFIX=lite/tools/debug
    mkdir -p ./${DEBUG_TOOL_PATH_PREFIX}
    cp ../${DEBUG_TOOL_PATH_PREFIX}/analysis_tool.py ./${DEBUG_TOOL_PATH_PREFIX}/
}

37 38 39 40 41 42 43 44 45 46 47 48 49
function prepare_thirdparty {
    if [ ! -d $workspace/third-party -o -f $workspace/third-party-05b862.tar.gz ]; then
        rm -rf $workspace/third-party

        if [ ! -f $workspace/third-party-05b862.tar.gz ]; then
            wget $THIRDPARTY_TAR
        fi
        tar xzf third-party-05b862.tar.gz
    else
        git submodule update --init --recursive
    fi
}

Y
Yan Chunwei 已提交
50 51 52 53 54 55 56 57
function make_tiny_publish_so {
  local os=$1
  local abi=$2
  local lang=$3
  local android_stl=$4

  cur_dir=$(pwd)
  build_dir=$cur_dir/build.lite.${os}.${abi}.${lang}
S
sangoly 已提交
58 59 60 61
  if [ -d $build_dir ]
  then
    rm -rf $build_dir
  fi
Y
Yan Chunwei 已提交
62 63 64 65 66 67 68 69 70 71
  mkdir -p $build_dir
  cd $build_dir

  cmake .. \
      ${CMAKE_COMMON_OPTIONS} \
      -DWITH_TESTING=OFF \
      -DLITE_WITH_JAVA=ON \
      -DLITE_SHUTDOWN_LOG=ON \
      -DLITE_ON_TINY_PUBLISH=ON \
      -DANDROID_STL_TYPE=$android_stl \
72
      -DLITE_BUILD_EXTRA=$BUILD_EXTRA \
Y
Yan Chunwei 已提交
73 74
      -DARM_TARGET_OS=${os} -DARM_TARGET_ARCH_ABI=${abi} -DARM_TARGET_LANG=${lang}

75
  make publish_inference -j$NUM_PROC
Y
Yan Chunwei 已提交
76 77 78 79 80 81 82 83 84
  cd - > /dev/null
}

function make_full_publish_so {
  local os=$1
  local abi=$2
  local lang=$3
  local android_stl=$4

85 86
  #git submodule update --init --recursive
  prepare_thirdparty
87

Y
Yan Chunwei 已提交
88 89
  cur_dir=$(pwd)
  build_dir=$cur_dir/build.lite.${os}.${abi}.${lang}
S
sangoly 已提交
90 91 92 93
  if [ -d $build_dir ]
  then
    rm -rf $build_dir
  fi
Y
Yan Chunwei 已提交
94 95 96 97 98 99 100 101 102 103
  mkdir -p $build_dir
  cd $build_dir

  prepare_workspace
  cmake .. \
      ${CMAKE_COMMON_OPTIONS} \
      -DWITH_TESTING=OFF \
      -DLITE_WITH_JAVA=ON \
      -DLITE_SHUTDOWN_LOG=ON \
      -DANDROID_STL_TYPE=$android_stl \
104
      -DLITE_BUILD_EXTRA=$BUILD_EXTRA \
Y
Yan Chunwei 已提交
105 106 107 108 109 110 111 112 113 114 115
      -DARM_TARGET_OS=${os} -DARM_TARGET_ARCH_ABI=${abi} -DARM_TARGET_LANG=${lang}

  make publish_inference -j4
  cd - > /dev/null
}

function make_all_tests {
  local os=$1
  local abi=$2
  local lang=$3

116 117
  #git submodule update --init --recursive
  prepare_thirdparty
Y
Yan Chunwei 已提交
118 119
  cur_dir=$(pwd)
  build_dir=$cur_dir/build.lite.${os}.${abi}.${lang}
S
sangoly 已提交
120 121 122 123
  if [ -d $build_dir ]
  then
    rm -rf $build_dir
  fi
Y
Yan Chunwei 已提交
124 125 126 127 128 129 130
  mkdir -p $build_dir
  cd $build_dir

  prepare_workspace
  cmake .. \
      ${CMAKE_COMMON_OPTIONS} \
      -DWITH_TESTING=ON \
131
      -DLITE_BUILD_EXTRA=$BUILD_EXTRA \
Y
Yan Chunwei 已提交
132 133 134 135 136 137 138 139
      -DARM_TARGET_OS=${os} -DARM_TARGET_ARCH_ABI=${abi} -DARM_TARGET_LANG=${lang}

  make lite_compile_deps -j4
  cd - > /dev/null
}


function print_usage {
140
    set +x
Y
Yan Chunwei 已提交
141 142 143 144 145 146 147 148 149 150 151 152
    echo -e "\nUSAGE:"
    echo
    echo "----------------------------------------"
    echo -e "compile tiny publish so lib:"
    echo -e "   ./build.sh --arm_os=<os> --arm_abi=<abi> --arm_lang=<lang> --android_stl=<stl> tiny_publish"
    echo
    echo -e "compile full publish so lib:"
    echo -e "   ./build.sh --arm_os=<os> --arm_abi=<abi> --arm_lang=<lang> --android_stl=<stl> full_publish"
    echo
    echo -e "compile all arm tests:"
    echo -e "   ./build.sh --arm_os=<os> --arm_abi=<abi> --arm_lang=<lang> test"
    echo
153 154
    echo -e "optional argument:"
    echo -e "--build_extra: (OFF|ON); controls whether to publish extra operators and kernels for (sequence-related model such as OCR or NLP)"
Y
Yan Chunwei 已提交
155
    echo
156
    echo -e "argument choices:"
Y
Yan Chunwei 已提交
157 158 159 160 161 162 163 164 165 166
    echo -e "--arm_os:\t android"
    echo -e "--arm_abi:\t armv8|armv7"
    echo -e "--arm_lang:\t gcc|clang"
    echo -e "--android_stl:\t c++_static|c++_shared"
    echo
    echo -e "tasks:"
    echo
    echo -e "tiny_publish: a small library for deployment."
    echo -e "full_publish: a full library for debug and test."
    echo -e "test: produce all the unittests."
Y
Yan Chunwei 已提交
167 168 169 170 171
    echo "----------------------------------------"
    echo
}

function main {
Y
Yan Chunwei 已提交
172 173 174 175 176
    if [ -z "$1" ]; then
        print_usage
        exit -1
    fi

Y
Yan Chunwei 已提交
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
    # Parse command line.
    for i in "$@"; do
        case $i in
            --arm_os=*)
                ARM_OS="${i#*=}"
                shift
                ;;
            --arm_abi=*)
                ARM_ABI="${i#*=}"
                shift
                ;;
            --arm_lang=*)
                ARM_LANG="${i#*=}"
                shift
                ;;
            --android_stl=*)
                ANDROID_STL="${i#*=}"
                shift
                ;;
196 197 198 199
            --build_extra=*)
                BUILD_EXTRA="${i#*=}"
                shift
                ;;
Y
Yan Chunwei 已提交
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
            tiny_publish)
                make_tiny_publish_so $ARM_OS $ARM_ABI $ARM_LANG $ANDROID_STL
                shift
                ;;
            full_publish)
                make_full_publish_so $ARM_OS $ARM_ABI $ARM_LANG $ANDROID_STL
                shift
                ;;
            test)
                make_all_tests $ARM_OS $ARM_ABI $ARM_LANG
                shift
                ;;
            *)
                # unknown option
                print_usage
                exit 1
                ;;
        esac
    done
}

main $@