1#!/bin/bash 2# Copyright 2021 Huawei Technologies Co., Ltd 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15# ============================================================================ 16 17set -e 18 19checkndk() { 20 if [ "${ANDROID_NDK}" ]; then 21 echo -e "\e[31mANDROID_NDK=$ANDROID_NDK \e[0m" 22 else 23 echo -e "\e[31mplease set ANDROID_NDK in environment variable for example: export ANDROID_NDK=/root/usr/android-ndk-r20b/ \e[0m" 24 exit 1 25 fi 26} 27 28get_version() { 29 VERSION_MAJOR=$(grep "const int ms_version_major =" ${BASEPATH}/mindspore/lite/include/version.h | tr -dc "[0-9]") 30 VERSION_MINOR=$(grep "const int ms_version_minor =" ${BASEPATH}/mindspore/lite/include/version.h | tr -dc "[0-9]") 31 VERSION_REVISION=$(grep "const int ms_version_revision =" ${BASEPATH}/mindspore/lite/include/version.h | tr -dc "[0-9]") 32 VERSION_STR=${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_REVISION} 33} 34 35write_commit_file() { 36 COMMIT_STR=$(git log -1 | grep commit) 37 echo ${COMMIT_STR} > "${BASEPATH}/mindspore/lite/build/.commit_id" 38} 39 40build_lite_x86_64_jni_and_jar() { 41 # copy x86 so 42 local is_train=on 43 cd ${BASEPATH}/output/tmp 44 local pkg_name=mindspore-lite-${VERSION_STR}-linux-x64 45 46 cd ${BASEPATH}/output/tmp/ 47 rm -rf ${pkg_name} 48 tar -zxf ${BASEPATH}/output/tmp/${pkg_name}.tar.gz 49 rm -rf ${LITE_JAVA_PATH}/java/linux_x86/libs/ && mkdir -pv ${LITE_JAVA_PATH}/java/linux_x86/libs/ 50 rm -rf ${LITE_JAVA_PATH}/native/libs/linux_x86/ && mkdir -pv ${LITE_JAVA_PATH}/native/libs/linux_x86/ 51 cp ./${pkg_name}/runtime/lib/*.so* ${LITE_JAVA_PATH}/java/linux_x86/libs/ 52 cp ./${pkg_name}/runtime/lib/*.so* ${LITE_JAVA_PATH}/native/libs/linux_x86/ 53 local train_so=$pkg_name/runtime/lib/libmindspore-lite-train.so 54 if [ ! -f "$train_so" ]; then 55 echo "not exist" 56 is_train=off 57 fi 58 if [[ "X$is_train" = "Xon" ]]; then 59 cp ./${pkg_name}/runtime/third_party/libjpeg-turbo/lib/*.so* ${LITE_JAVA_PATH}/java/linux_x86/libs/ 60 cp ./${pkg_name}/runtime/third_party/libjpeg-turbo/lib/*.so* ${LITE_JAVA_PATH}/native/libs/linux_x86/ 61 fi 62 # build jni so 63 cd ${BASEPATH}/mindspore/lite/build 64 rm -rf java/jni && mkdir -pv java/jni 65 cd java/jni 66 cmake -DMS_VERSION_MAJOR=${VERSION_MAJOR} -DMS_VERSION_MINOR=${VERSION_MINOR} -DMS_VERSION_REVISION=${VERSION_REVISION} \ 67 -DCMAKE_BUILD_TYPE=${LITE_BUILD_TYPE} -DENABLE_VERBOSE=${ENABLE_VERBOSE} -DSUPPORT_TRAIN=${is_train} "${LITE_JAVA_PATH}/native/" 68 make -j$THREAD_NUM 69 if [[ $? -ne 0 ]]; then 70 echo "---------------- mindspore lite: build jni x86_64 failed----------------" 71 exit 1 72 fi 73 cp ./libmindspore-lite-jni.so ${LITE_JAVA_PATH}/java/linux_x86/libs/ 74 cp ./libmindspore-lite-jni.so ${LITE_JAVA_PATH}/native/libs/linux_x86/ 75 cp ./libmindspore-lite-jni.so ${BASEPATH}/output/tmp/${pkg_name}/runtime/lib/ 76 if [[ "X$is_train" = "Xon" ]]; then 77 cp ./libmindspore-lite-train-jni.so ${LITE_JAVA_PATH}/java/linux_x86/libs/ 78 cp ./libmindspore-lite-train-jni.so ${LITE_JAVA_PATH}/native/libs/linux_x86/ 79 cp ./libmindspore-lite-train-jni.so ${BASEPATH}/output/tmp/${pkg_name}/runtime/lib/ 80 fi 81 82 cd ${LITE_JAVA_PATH}/java 83 rm -rf gradle .gradle gradlew gradlew.bat 84 gradle wrapper --gradle-version 6.6.1 --distribution-type all 85 # build java common 86 ${LITE_JAVA_PATH}/java/gradlew clean -p ${LITE_JAVA_PATH}/java/common 87 ${LITE_JAVA_PATH}/java/gradlew build -p ${LITE_JAVA_PATH}/java/common 88 cp ${LITE_JAVA_PATH}/java/common/build/libs/mindspore-lite-java-common.jar ${LITE_JAVA_PATH}/java/linux_x86/libs/ 89 90 # build java fl_client 91 if [[ "X$is_train" = "Xon" ]]; then 92 ${LITE_JAVA_PATH}/java/gradlew clean -p ${LITE_JAVA_PATH}/java/fl_client 93 ${LITE_JAVA_PATH}/java/gradlew createFlatBuffers -p ${LITE_JAVA_PATH}/java/fl_client 94 ${LITE_JAVA_PATH}/java/gradlew build -p ${LITE_JAVA_PATH}/java/fl_client 95 ${LITE_JAVA_PATH}/java/gradlew clearJar -p ${LITE_JAVA_PATH}/java/fl_client 96 ${LITE_JAVA_PATH}/java/gradlew flReleaseJarX86 --rerun-tasks -p ${LITE_JAVA_PATH}/java/fl_client 97 cp ${LITE_JAVA_PATH}/java/fl_client/build/libs/jarX86/mindspore-lite-java-flclient.jar ${BASEPATH}/output/tmp/${pkg_name}/runtime/lib/ 98 rm -rf ${LITE_JAVA_PATH}/java/fl_client/.gradle ${LITE_JAVA_PATH}/java/fl_client/src/main/java/mindspore 99 fi 100 101 # build jar 102 ${LITE_JAVA_PATH}/java/gradlew clean -p ${LITE_JAVA_PATH}/java/linux_x86/ 103 ${LITE_JAVA_PATH}/java/gradlew releaseJar -p ${LITE_JAVA_PATH}/java/linux_x86/ 104 cp ${LITE_JAVA_PATH}/java/linux_x86/build/lib/jar/*.jar ${BASEPATH}/output/tmp/${pkg_name}/runtime/lib/ 105 106 # package 107 cd ${BASEPATH}/output/tmp 108 rm -rf ${pkg_name}.tar.gz ${pkg_name}.tar.gz.sha256 109 tar czf ${pkg_name}.tar.gz ${pkg_name} 110 sha256sum ${pkg_name}.tar.gz > ${pkg_name}.tar.gz.sha256 111 rm -rf ${LITE_JAVA_PATH}/java/linux_x86/libs/ 112 rm -rf ${LITE_JAVA_PATH}/native/libs/linux_x86/ 113} 114 115build_lite() { 116 [ -n "${BASEPATH}" ] && rm -rf ${BASEPATH}/output 117 get_version 118 echo "============ Start building MindSpore Lite ${VERSION_STR} ============" 119 local local_lite_platform=${LITE_PLATFORM} 120 if [[ "${LITE_ENABLE_AAR}" == "on" ]]; then 121 local_lite_platform=$1 122 mkdir -pv ${BASEPATH}/mindspore/lite/build/java 123 cd ${BASEPATH}/mindspore/lite/build/ 124 [ -n "${BASEPATH}" ] && find . -maxdepth 1 | grep -v java | grep '/' | xargs -I {} rm -rf {} 125 else 126 if [[ "${INC_BUILD}" == "off" ]]; then 127 [ -n "${BASEPATH}" ] && rm -rf ${BASEPATH}/mindspore/lite/build 128 fi 129 mkdir -pv ${BASEPATH}/mindspore/lite/build 130 fi 131 cd ${BASEPATH}/mindspore/lite/build 132 write_commit_file 133 134 if [[ "${local_lite_platform}" == "arm32" ]]; then 135 if [[ "${TOOLCHAIN_NAME}" == "ohos-lite" ]]; then 136 COMPILE_MINDDATA_LITE="off" 137 CMAKE_TOOLCHAIN_FILE=${BASEPATH}/mindspore/lite/cmake/ohos-lite.toolchain.cmake 138 CMAKE_TOOLCHAIN_NAME="ohos-lite" 139 elif [[ "${TOOLCHAIN_NAME}" == "himix200" ]]; then 140 COMPILE_MINDDATA_LITE="off" 141 CMAKE_TOOLCHAIN_FILE=${BASEPATH}/mindspore/lite/cmake/himix200.toolchain.cmake 142 CMAKE_TOOLCHAIN_NAME="himix200" 143 else 144 CMAKE_TOOLCHAIN_FILE=${ANDROID_NDK}/build/cmake/android.toolchain.cmake 145 ANDROID_NATIVE_API_LEVEL="19" 146 CMAKE_ANDROID_NDK=${ANDROID_NDK} 147 CMAKE_ANDROID_ABI="armeabi-v7a" 148 CMAKE_ANDROID_TOOLCHAIN_NAME="clang" 149 CMAKE_ANDROID_STL=${MSLITE_ANDROID_STL} 150 MSLITE_ENABLE_FP16="on" 151 fi 152 fi 153 154 if [[ "${local_lite_platform}" == "arm64" ]]; then 155 if [ "$(uname)" == "Darwin" ]; then 156 pkg_name=mindspore-lite-${VERSION_STR}-ios-aarch64 157 cmake -DCMAKE_TOOLCHAIN_FILE=${BASEPATH}/cmake/lite_ios.cmake -DARCHS="arm64" -DENABLE_BITCODE=0 \ 158 -DCMAKE_BUILD_TYPE="Release" -DBUILD_MINDDATA="" -DPLATFORM_ARM64="on" -DENABLE_NEON="on" -DMSLITE_ENABLE_FP16="on" \ 159 -DMSLITE_ENABLE_TRAIN="off" -DMSLITE_GPU_BACKEND="off" -DMSLITE_ENABLE_NPU="off" \ 160 -DENABLE_ASAN=${ENABLE_ASAN} -DCMAKE_INSTALL_PREFIX=${BUILD_PATH}/output/tmp -G Xcode .. 161 else 162 checkndk 163 echo "default link libc++_static.a, export MSLITE_ANDROID_STL=c++_shared to link libc++_shared.so" 164 cmake -DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK}/build/cmake/android.toolchain.cmake" -DANDROID_NATIVE_API_LEVEL="19" \ 165 -DANDROID_NDK="${ANDROID_NDK}" -DANDROID_ABI="arm64-v8a" -DANDROID_TOOLCHAIN_NAME="aarch64-linux-android-clang" \ 166 -DANDROID_STL=${MSLITE_ANDROID_STL} -DCMAKE_BUILD_TYPE=${LITE_BUILD_TYPE} -DBUILD_MINDDATA=${COMPILE_MINDDATA_LITE} \ 167 -DPLATFORM_ARM64="on" -DENABLE_NEON="on" -DMSLITE_ENABLE_FP16="on" -DCMAKE_INSTALL_PREFIX=${BASEPATH}/output/tmp \ 168 -DMS_VERSION_MAJOR=${VERSION_MAJOR} -DMS_VERSION_MINOR=${VERSION_MINOR} -DMS_VERSION_REVISION=${VERSION_REVISION} \ 169 -DENABLE_ASAN=${ENABLE_ASAN} -DENABLE_VERBOSE=${ENABLE_VERBOSE} "${BASEPATH}/mindspore/lite" 170 fi 171 elif [[ "${local_lite_platform}" == "arm32" ]]; then 172 if [ "$(uname)" == "Darwin" ]; then 173 pkg_name=mindspore-lite-${VERSION_STR}-ios-aarch32 174 cmake -DCMAKE_TOOLCHAIN_FILE=${BASEPATH}/cmake/lite_ios.cmake -DARCHS="armv7;armv7s" -DENABLE_BITCODE=0 \ 175 -DCMAKE_BUILD_TYPE="Release" -DBUILD_MINDDATA="" -DPLATFORM_ARM32="on" -DENABLE_NEON="on" \ 176 -DMSLITE_ENABLE_TRAIN="off" -DMSLITE_GPU_BACKEND="off" -DMSLITE_ENABLE_NPU="off" \ 177 -DENABLE_ASAN=${ENABLE_ASAN} -DCMAKE_INSTALL_PREFIX=${BUILD_PATH}/output/tmp -G Xcode .. 178 else 179 checkndk 180 echo "default link libc++_static.a, export MSLITE_ANDROID_STL=c++_shared to link libc++_shared.so" 181 cmake -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} -DTOOLCHAIN_NAME=${CMAKE_TOOLCHAIN_NAME} -DANDROID_NATIVE_API_LEVEL=${ANDROID_NATIVE_API_LEVEL} \ 182 -DANDROID_NDK=${CMAKE_ANDROID_NDK} -DANDROID_ABI=${CMAKE_ANDROID_ABI} -DANDROID_TOOLCHAIN_NAME=${CMAKE_ANDROID_TOOLCHAIN_NAME} \ 183 -DANDROID_STL=${CMAKE_ANDROID_STL} -DCMAKE_BUILD_TYPE=${LITE_BUILD_TYPE} -DBUILD_MINDDATA=${COMPILE_MINDDATA_LITE} \ 184 -DPLATFORM_ARM32="on" -DENABLE_NEON="on" -DMSLITE_ENABLE_FP16=${MSLITE_ENABLE_FP16} -DCMAKE_INSTALL_PREFIX=${BASEPATH}/output/tmp \ 185 -DMS_VERSION_MAJOR=${VERSION_MAJOR} -DMS_VERSION_MINOR=${VERSION_MINOR} -DMS_VERSION_REVISION=${VERSION_REVISION} \ 186 -DENABLE_ASAN=${ENABLE_ASAN} -DENABLE_VERBOSE=${ENABLE_VERBOSE} "${BASEPATH}/mindspore/lite" 187 fi 188 else 189 if [ "$(uname)" == "Darwin" ]; then 190 pkg_name=mindspore-lite-${VERSION_STR}-ios-simulator 191 cmake -DCMAKE_TOOLCHAIN_FILE=${BASEPATH}/cmake/lite_ios.cmake -DPLATFORM=SIMULATOR64 -DMSLITE_ENABLE_MINDRT="on" \ 192 -DCMAKE_BUILD_TYPE="Release" -DPLATFORM_ARM64="off" -DENABLE_NEON="off" -DMSLITE_ENABLE_TOOLS="off" -DMSLITE_ENABLE_CONVERTER=off \ 193 -DMSLITE_ENABLE_TRAIN="off" -DMSLITE_GPU_BACKEND="off" -DMSLITE_ENABLE_NPU="off" -DBUILD_MINDDATA="" -DMSLITE_ENABLE_V0=on \ 194 -DENABLE_ASAN=${ENABLE_ASAN} -DCMAKE_INSTALL_PREFIX=${BASEPATH}/output/tmp -DENABLE_VERBOSE=${ENABLE_VERBOSE} "${BASEPATH}/mindspore/lite" \ 195 -G Xcode .. 196 else 197 cmake -DPLATFORM_X86_64=on -DCMAKE_BUILD_TYPE=${LITE_BUILD_TYPE} -DBUILD_MINDDATA=${COMPILE_MINDDATA_LITE} \ 198 -DMS_VERSION_MAJOR=${VERSION_MAJOR} -DMS_VERSION_MINOR=${VERSION_MINOR} -DMS_VERSION_REVISION=${VERSION_REVISION} \ 199 -DENABLE_ASAN=${ENABLE_ASAN} -DCMAKE_INSTALL_PREFIX=${BASEPATH}/output/tmp -DENABLE_VERBOSE=${ENABLE_VERBOSE} "${BASEPATH}/mindspore/lite" 200 fi 201 fi 202 if [[ "$(uname)" == "Darwin" && "${local_lite_platform}" != "x86_64" ]]; then 203 xcodebuild ONLY_ACTIVE_ARCH=NO -configuration Release -scheme mindspore-lite_static -target mindspore-lite_static -sdk iphoneos -quiet 204 elif [[ "$(uname)" == "Darwin" && "${local_lite_platform}" == "x86_64" ]]; then 205 xcodebuild ONLY_ACTIVE_ARCH=NO -configuration Release -scheme mindspore-lite_static -target mindspore-lite_static -sdk iphonesimulator -quiet 206 else 207 make -j$THREAD_NUM && make install && make package 208 if [[ "${local_lite_platform}" == "x86_64" ]]; then 209 if [ "${JAVA_HOME}" ]; then 210 echo -e "\e[31mJAVA_HOME=$JAVA_HOME \e[0m" 211 build_lite_x86_64_jni_and_jar 212 else 213 echo -e "\e[31mJAVA_HOME is not set, so jni and jar packages will not be compiled \e[0m" 214 echo -e "\e[31mIf you want to compile the JAR package, please set $JAVA_HOME. For example: export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64 \e[0m" 215 fi 216 fi 217 fi 218 if [[ $? -ne 0 ]]; then 219 echo "---------------- mindspore lite: build failed ----------------" 220 exit 1 221 else 222 if [ "$(uname)" == "Darwin" ]; then 223 mkdir -p ${BASEPATH}/output 224 cp -r ${BASEPATH}/mindspore/lite/build/src/Release-*/mindspore-lite.framework ${BASEPATH}/output/mindspore-lite.framework 225 cd ${BASEPATH}/output 226 tar -zcvf ${pkg_name}.tar.gz mindspore-lite.framework/ 227 sha256sum ${pkg_name}.tar.gz > ${pkg_name}.tar.gz.sha256 228 rm -r mindspore-lite.framework 229 else 230 mv ${BASEPATH}/output/tmp/*.tar.gz* ${BASEPATH}/output/ 231 fi 232 233 if [[ "${local_lite_platform}" == "x86_64" ]]; then 234 if [[ "${MSLITE_ENABLE_TESTCASES}" == "ON" || "${MSLITE_ENABLE_TESTCASES}" == "on" ]]; then 235 mkdir -pv ${BASEPATH}/mindspore/lite/test/do_test || true 236 if [[ ! "${MSLITE_ENABLE_CONVERTER}" || "${MSLITE_ENABLE_CONVERTER}" == "ON" || "${MSLITE_ENABLE_CONVERTER}" == "on" ]]; then 237 cp ${BASEPATH}/output/tmp/mindspore-lite*/tools/converter/lib/*.so* ${BASEPATH}/mindspore/lite/test/do_test || true 238 fi 239 cp ${BASEPATH}/output/tmp/mindspore-lite*/runtime/lib/*.so* ${BASEPATH}/mindspore/lite/test/do_test || true 240 if [[ ! "${MSLITE_ENABLE_TRAIN}" || "${MSLITE_ENABLE_TRAIN}" == "ON" || "${MSLITE_ENABLE_TRAIN}" == "on" ]]; then 241 cp ${BASEPATH}/output/tmp/mindspore-lite*/runtime/third_party/libjpeg-turbo/lib/*.so* ${BASEPATH}/mindspore/lite/test/do_test || true 242 fi 243 fi 244 fi 245 246 [ -n "${BASEPATH}" ] && rm -rf ${BASEPATH}/output/tmp/ 247 if [[ "${MSLITE_ENABLE_NNIE}" == "on" ]]; then 248 compile_nnie_script=${BASEPATH}/mindspore/lite/tools/providers/NNIE/Hi3516D/compile_nnie.sh 249 cd ${BASEPATH}/../ 250 if [[ "${local_lite_platform}" == "x86_64" ]]; then 251 sh ${compile_nnie_script} -I x86_64 -b nnie_3516_r1.5 -j $THREAD_NUM 252 if [[ $? -ne 0 ]]; then 253 echo "compile x86_64 for nnie failed." 254 exit 1 255 fi 256 elif [[ "${local_lite_platform}" == "arm32" ]]; then 257 sh ${compile_nnie_script} -I arm32 -b nnie_3516_r1.5 -j $THREAD_NUM 258 if [[ $? -ne 0 ]]; then 259 echo "compile arm32 for nnie failed." 260 exit 1 261 fi 262 fi 263 fi 264 echo "---------------- mindspore lite: build success ----------------" 265 fi 266} 267 268build_lite_arm64_and_jni() { 269 build_lite "arm64" 270 # copy arm64 so 271 local is_train=on 272 local pkg_name=mindspore-lite-${VERSION_STR}-android-aarch64 273 cd "${BASEPATH}/mindspore/lite/build" 274 275 rm -rf ${pkg_name} 276 tar -zxf ${BASEPATH}/output/${pkg_name}.tar.gz 277 rm -rf ${LITE_JAVA_PATH}/java/app/libs/arm64-v8a/ && mkdir -p ${LITE_JAVA_PATH}/java/app/libs/arm64-v8a/ 278 rm -rf ${LITE_JAVA_PATH}/native/libs/arm64-v8a/ && mkdir -p ${LITE_JAVA_PATH}/native/libs/arm64-v8a/ 279 cp ./${pkg_name}/runtime/lib/libmindspore-lite.so ${LITE_JAVA_PATH}/java/app/libs/arm64-v8a/ 280 cp ./${pkg_name}/runtime/lib/libmindspore-lite.so ${LITE_JAVA_PATH}/native/libs/arm64-v8a/ 281 local train_so=$pkg_name/runtime/lib/libmindspore-lite-train.so 282 if [ ! -f "$train_so" ]; then 283 echo "not exist" 284 is_train=off 285 fi 286 if [[ "X$is_train" = "Xon" ]]; then 287 cp ./${pkg_name}/runtime/lib/*.so* ${LITE_JAVA_PATH}/java/app/libs/arm64-v8a/ 288 cp ./${pkg_name}/runtime/lib/*.so* ${LITE_JAVA_PATH}/native/libs/arm64-v8a/ 289 cp ./${pkg_name}/runtime/third_party/libjpeg-turbo/lib/*.so* ${LITE_JAVA_PATH}/java/app/libs/arm64-v8a/ 290 cp ./${pkg_name}/runtime/third_party/libjpeg-turbo/lib/*.so* ${LITE_JAVA_PATH}/native/libs/arm64-v8a/ 291 fi 292 # build jni so 293 [ -n "${BASEPATH}" ] && rm -rf java/jni && mkdir -pv java/jni 294 cd java/jni 295 cmake -DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK}/build/cmake/android.toolchain.cmake" -DANDROID_NATIVE_API_LEVEL="19" \ 296 -DANDROID_NDK="${ANDROID_NDK}" -DANDROID_ABI="arm64-v8a" -DANDROID_TOOLCHAIN_NAME="aarch64-linux-android-clang" \ 297 -DMS_VERSION_MAJOR=${VERSION_MAJOR} -DMS_VERSION_MINOR=${VERSION_MINOR} -DMS_VERSION_REVISION=${VERSION_REVISION} \ 298 -DANDROID_STL=${MSLITE_ANDROID_STL} -DCMAKE_BUILD_TYPE=${LITE_BUILD_TYPE} -DENABLE_VERBOSE=${ENABLE_VERBOSE} \ 299 -DSUPPORT_TRAIN=${is_train} -DPLATFORM_ARM64=on "${LITE_JAVA_PATH}/native/" 300 make -j$THREAD_NUM 301 if [[ $? -ne 0 ]]; then 302 echo "---------------- mindspore lite: build jni arm64 failed----------------" 303 exit 1 304 fi 305 cp ./libmindspore-lite-jni.so ${LITE_JAVA_PATH}/java/app/libs/arm64-v8a/ 306 cp ./libmindspore-lite-jni.so ${LITE_JAVA_PATH}/native/libs/arm64-v8a/ 307 if [[ "X$is_train" = "Xon" ]]; then 308 cp ./libmindspore-lite-train-jni.so ${LITE_JAVA_PATH}/java/app/libs/arm64-v8a/ 309 cp ./libmindspore-lite-train-jni.so ${LITE_JAVA_PATH}/native/libs/arm64-v8a/ 310 fi 311} 312 313build_lite_arm32_and_jni() { 314 build_lite "arm32" 315 # copy arm32 so 316 local is_train=on 317 local pkg_name=mindspore-lite-${VERSION_STR}-android-aarch32 318 cd "${BASEPATH}/mindspore/lite/build" 319 320 rm -rf ${pkg_name} 321 tar -zxf ${BASEPATH}/output/${pkg_name}.tar.gz 322 rm -rf ${LITE_JAVA_PATH}/java/app/libs/armeabi-v7a/ && mkdir -pv ${LITE_JAVA_PATH}/java/app/libs/armeabi-v7a/ 323 rm -rf ${LITE_JAVA_PATH}/native/libs/armeabi-v7a/ && mkdir -pv ${LITE_JAVA_PATH}/native/libs/armeabi-v7a/ 324 cp ./${pkg_name}/runtime/lib/libmindspore-lite.so ${LITE_JAVA_PATH}/java/app/libs/armeabi-v7a/ 325 cp ./${pkg_name}/runtime/lib/libmindspore-lite.so ${LITE_JAVA_PATH}/native/libs/armeabi-v7a/ 326 local train_so=$pkg_name/runtime/lib/libmindspore-lite-train.so 327 if [ ! -f "$train_so" ]; then 328 echo "not exist" 329 is_train=off 330 fi 331 if [[ "X$is_train" = "Xon" ]]; then 332 cp ./${pkg_name}/runtime/lib/*.so* ${LITE_JAVA_PATH}/java/app/libs/armeabi-v7a/ 333 cp ./${pkg_name}/runtime/lib/*.so* ${LITE_JAVA_PATH}/native/libs/armeabi-v7a/ 334 cp ./${pkg_name}/runtime/third_party/libjpeg-turbo/lib/*.so* ${LITE_JAVA_PATH}/java/app/libs/armeabi-v7a/ 335 cp ./${pkg_name}/runtime/third_party/libjpeg-turbo/lib/*.so* ${LITE_JAVA_PATH}/native/libs/armeabi-v7a/ 336 fi 337 338 # build jni so 339 [ -n "${BASEPATH}" ] && rm -rf java/jni && mkdir -pv java/jni 340 cd java/jni 341 cmake -DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK}/build/cmake/android.toolchain.cmake" -DANDROID_NATIVE_API_LEVEL="19" \ 342 -DANDROID_NDK="${ANDROID_NDK}" -DANDROID_ABI="armeabi-v7a" -DANDROID_TOOLCHAIN_NAME="aarch64-linux-android-clang" \ 343 -DMS_VERSION_MAJOR=${VERSION_MAJOR} -DMS_VERSION_MINOR=${VERSION_MINOR} -DMS_VERSION_REVISION=${VERSION_REVISION} \ 344 -DANDROID_STL=${MSLITE_ANDROID_STL} -DCMAKE_BUILD_TYPE=${LITE_BUILD_TYPE} -DENABLE_VERBOSE=${ENABLE_VERBOSE} \ 345 -DSUPPORT_TRAIN=${is_train} -DPLATFORM_ARM32=on "${LITE_JAVA_PATH}/native" 346 make -j$THREAD_NUM 347 if [[ $? -ne 0 ]]; then 348 echo "---------------- mindspore lite: build jni arm32 failed----------------" 349 exit 1 350 fi 351 cp ./libmindspore-lite-jni.so ${LITE_JAVA_PATH}/java/app/libs/armeabi-v7a/ 352 cp ./libmindspore-lite-jni.so ${LITE_JAVA_PATH}/native/libs/armeabi-v7a/ 353 if [[ "X$is_train" = "Xon" ]]; then 354 cp ./libmindspore-lite-train-jni.so ${LITE_JAVA_PATH}/java/app/libs/armeabi-v7a/ 355 cp ./libmindspore-lite-train-jni.so ${LITE_JAVA_PATH}/native/libs/armeabi-v7a/ 356 fi 357} 358 359build_aar() { 360 get_version 361 if [[ "X${INC_BUILD}" == "Xoff" ]]; then 362 [ -n "${BASEPATH}" ] && rm -rf ${BASEPATH}/mindspore/lite/build 363 fi 364 cd ${LITE_JAVA_PATH}/java 365 rm -rf gradle .gradle gradlew gradlew.bat 366 gradle wrapper --gradle-version 6.6.1 --distribution-type all 367 # build common module 368 ${LITE_JAVA_PATH}/java/gradlew clean -p ${LITE_JAVA_PATH}/java/common 369 ${LITE_JAVA_PATH}/java/gradlew build -p ${LITE_JAVA_PATH}/java/common 370 371 # build aar 372 local npu_bak=${MSLITE_ENABLE_NPU} 373 export MSLITE_ENABLE_NPU="off" 374 build_lite_arm64_and_jni 375 build_lite_arm32_and_jni 376 export MSLITE_ENABLE_NPU=${npu_bak} 377 378 # build java fl_client 379 local is_train=on 380 local train_so=${LITE_JAVA_PATH}/java/app/libs/arm64-v8a/libmindspore-lite-train.so 381 if [ ! -f "$train_so" ]; then 382 echo "not exist" 383 is_train=off 384 fi 385 if [[ "X$is_train" = "Xon" ]]; then 386 ${LITE_JAVA_PATH}/java/gradlew clean -p ${LITE_JAVA_PATH}/java/fl_client 387 ${LITE_JAVA_PATH}/java/gradlew createFlatBuffers -p ${LITE_JAVA_PATH}/java/fl_client 388 ${LITE_JAVA_PATH}/java/gradlew build -p ${LITE_JAVA_PATH}/java/fl_client 389 ${LITE_JAVA_PATH}/java/gradlew clearJar -p ${LITE_JAVA_PATH}/java/fl_client 390 ${LITE_JAVA_PATH}/java/gradlew flReleaseJarAAR --rerun-tasks -p ${LITE_JAVA_PATH}/java/fl_client 391 cp ${LITE_JAVA_PATH}/java/fl_client/build/libs/jarAAR/mindspore-lite-java-flclient.jar ${LITE_JAVA_PATH}/java/app/libs 392 rm -rf ${LITE_JAVA_PATH}/java/fl_client/.gradle ${LITE_JAVA_PATH}/java/fl_client/src/main/java/mindspore 393 fi 394 395 cp ${LITE_JAVA_PATH}/java/common/build/libs/mindspore-lite-java-common.jar ${LITE_JAVA_PATH}/java/app/libs 396 ${LITE_JAVA_PATH}/java/gradlew clean -p ${LITE_JAVA_PATH}/java/app 397 ${LITE_JAVA_PATH}/java/gradlew assembleRelease -p ${LITE_JAVA_PATH}/java/app 398 ${LITE_JAVA_PATH}/java/gradlew publish -PLITE_VERSION=${VERSION_STR} -p ${LITE_JAVA_PATH}/java/app 399 400 cd ${LITE_JAVA_PATH}/java/app/build 401 [ -n "${BASEPATH}" ] && rm -rf ${BASEPATH}/output/*.tar.gz* 402 zip -r ${BASEPATH}/output/mindspore-lite-maven-${VERSION_STR}.zip mindspore 403 cd ${BASEPATH}/output 404 sha256sum mindspore-lite-maven-${VERSION_STR}.zip > mindspore-lite-maven-${VERSION_STR}.zip.sha256 405} 406 407update_submodule() 408{ 409 git submodule update --init graphengine 410 cd "${BASEPATH}/graphengine" 411 git submodule update --init metadef 412} 413 414LITE_JAVA_PATH=${BASEPATH}/mindspore/lite/java 415LITE_BUILD_TYPE="Release" 416if [[ "${MSLITE_ENABLE_ACL}" == "on" ]]; then 417 update_submodule 418fi 419if [[ "${DEBUG_MODE}" == "on" ]]; then 420 LITE_BUILD_TYPE="Debug" 421fi 422if [[ "X$LITE_ENABLE_AAR" = "Xon" ]]; then 423 build_aar 424elif [[ "X$LITE_PLATFORM" != "X" ]]; then 425 build_lite 426else 427 echo "Invalid parameter" 428fi 429