build-onnxruntime.sh (4971B)
1 #!/bin/bash 2 # 3 # This Source Code Form is subject to the terms of the Mozilla Public 4 # License, v. 2.0. If a copy of the MPL was not distributed with this 5 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 6 7 set -x -e -v 8 9 # This script is for building the onnx runtime using upstream build system. 10 11 target_platform="$1" 12 target_arch="$2" 13 14 ### 15 # Gather build dependencies from fetches 16 17 if test -d "$MOZ_FETCHES_DIR/cmake"; then 18 export PATH="$(cd $MOZ_FETCHES_DIR/cmake && pwd)/bin:${PATH}" 19 fi 20 21 onnxruntime_depdir="$MOZ_FETCHES_DIR/onnxruntime-deps" 22 23 export PATH="$(cd $MOZ_FETCHES_DIR/ninja && pwd)/bin:${PATH}" 24 export PATH="$(cd $MOZ_FETCHES_DIR/clang && pwd)/bin:${PATH}" 25 26 export CC=clang 27 export CXX=clang++ 28 29 ### 30 # Extra setup per platform 31 case ${target_platform} in 32 Darwin) 33 # Use taskcluster clang instead of host compiler on OSX 34 osx_sysroot=`cd ${MOZ_FETCHES_DIR}/MacOSX*.sdk; pwd` 35 extra_args="--cmake_extra_defines CMAKE_OSX_SYSROOT=${osx_sysroot} --osx_arch $target_arch" 36 prefix=lib 37 extension=dylib 38 ;; 39 Linux) 40 prefix=lib 41 extension=so 42 ;; 43 Android) 44 extra_args="--android --android_ndk_path=$MOZ_FETCHES_DIR/android-ndk --android_sdk_path=$MOZ_FETCHES_DIR/android-sdk-linux --android_abi=$target_arch" 45 prefix=lib 46 extension=so 47 ;; 48 Windows) 49 # Still use visual studio there, compilation through clang-cl is not 50 # supported upstream. 51 case $target_arch in 52 x86) 53 extra_args="--x86" 54 ;; 55 esac 56 extra_args="$extra_args --cmake_extra_defines CMAKE_SHARED_LINKER_FLAGS=/MANIFEST:NO" 57 . $GECKO_PATH/taskcluster/scripts/misc/vs-setup.sh 58 sed -i -e 's/ProgramDatabase//' "$MOZ_FETCHES_DIR/onnxruntime/tools/ci_build/build.py" 59 export CC=cl.exe 60 export CXX=cl.exe 61 prefix= 62 extension=dll 63 ;; 64 esac 65 66 artifact=$(basename "$TOOLCHAIN_ARTIFACT") 67 onnx_folder=${artifact%.tar.*} 68 69 cd "$MOZ_FETCHES_DIR/onnxruntime" 70 71 ### 72 # Various patches 73 74 # Update checksum for eigen3, see https://github.com/microsoft/onnxruntime/pull/24884 75 patch -p1 << EOF 76 diff --git a/cmake/deps.txt b/cmake/deps.txt 77 index 728241840f723..6e045f6dcdc9d 100644 78 --- a/cmake/deps.txt 79 +++ b/cmake/deps.txt 80 @@ -22,7 +22,9 @@ dlpack;https://github.com/dmlc/dlpack/archive/5c210da409e7f1e51ddf445134a4376fdb 81 # it contains changes on top of 3.4.0 which are required to fix build issues. 82 # Until the 3.4.1 release this is the best option we have. 83 # Issue link: https://gitlab.com/libeigen/eigen/-/issues/2744 84 -eigen;https://gitlab.com/libeigen/eigen/-/archive/1d8b82b0740839c0de7f1242a3585e3390ff5f33/eigen-1d8b82b0740839c0de7f1242a3585e3390ff5f33.zip;5ea4d05e62d7f954a46b3213f9b2535bdd866803 85 +# Moved to github mirror to avoid gitlab issues. 86 +# Issue link: https://github.com/bazelbuild/bazel-central-registry/issues/4355 87 +eigen;https://github.com/eigen-mirror/eigen/archive/1d8b82b0740839c0de7f1242a3585e3390ff5f33/eigen-1d8b82b0740839c0de7f1242a3585e3390ff5f33.zip;05b19b49e6fbb91246be711d801160528c135e34 88 flatbuffers;https://github.com/google/flatbuffers/archive/refs/tags/v23.5.26.zip;59422c3b5e573dd192fead2834d25951f1c1670c 89 fp16;https://github.com/Maratyszcza/FP16/archive/0a92994d729ff76a58f692d3028ca1b64b145d91.zip;b985f6985a05a1c03ff1bb71190f66d8f98a1494 90 EOF 91 92 # Make sure we use dependencies from onnxruntime-deps and avoid re-downloading 93 # them. 94 sed -i -e "s,;.*/,;$onnxruntime_depdir/,g" cmake/deps.txt 95 96 # Apply local patches 97 find $GECKO_PATH/taskcluster/scripts/misc/onnxruntime.patches -type f -name '*.patch' -print0 | sort -z | while read -d '' patch ; do patch -p1 < $patch ; done 98 99 ### 100 # Configure and build 101 onnx_builddir=_build 102 103 mkdir $onnx_builddir 104 105 build_type=MinSizeRel 106 107 python3 tools/ci_build/build.py \ 108 --update \ 109 --parallel \ 110 --enable_lto \ 111 --disable_rtti \ 112 --cmake_generator Ninja \ 113 --build_dir $onnx_builddir \ 114 --build --build_shared_lib \ 115 --skip_submodule_sync --use_lock_free_queue --skip_tests --config $build_type --compile_no_warning_as_error \ 116 --cmake_extra_defines onnxruntime_BUILD_UNIT_TESTS=OFF\ 117 --cmake_extra_defines PYTHON_EXECUTABLE=$(which python3)\ 118 --cmake_extra_defines ONNX_USE_LITE_PROTO=ON\ 119 --disable_exceptions \ 120 --cmake_extra_defines CMAKE_CXX_FLAGS=-fno-exceptions\ -DORT_NO_EXCEPTIONS\ -DONNX_NO_EXCEPTIONS\ -DMLAS_NO_EXCEPTION\ 121 ${extra_args} 122 123 ### 124 # Pack the result and upload. 125 mkdir $onnx_folder 126 cp $onnx_builddir/$build_type/${prefix}onnxruntime.${extension} $onnx_folder/ 127 128 ls -la "$onnx_folder" 129 130 find "$onnx_folder" -type f -exec llvm-strip -x {} \; || true 131 132 ls -la "$onnx_folder" 133 mkdir -p $UPLOAD_DIR 134 135 export ZSTD_CLEVEL=19 136 137 case ${target_platform} in 138 Windows) 139 tar -a -c -f "$UPLOAD_DIR/$artifact" --force-local "$onnx_folder" 140 ;; 141 *) 142 tar acf "$UPLOAD_DIR/$artifact" "$onnx_folder" 143 ;; 144 esac 145 ls -la "$UPLOAD_DIR/$artifact"