| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- #!/bin/bash
- set -e
- pushd $(cd $(dirname ${0})/..; pwd) > /dev/null
- case "${OSTYPE}" in
- msys*) python="winpty python";;
- *) python="python";;
- esac
- venv() {
- env_dir=./third_party/env/onnx
- [ -d "${env_dir}" ] || ${python} -m venv ${env_dir}
- case "${OSTYPE}" in
- msys*) source ${env_dir}/Scripts/activate;;
- *) source ${env_dir}/bin/activate;;
- esac
- ${python} -m pip install --quiet --upgrade pip setuptools wheel
- }
- clean() {
- echo "onnx clean"
- rm -rf "./third_party/env/onnx"
- rm -rf "./third_party/source/onnx"
- rm -rf "./third_party/source/onnxruntime"
- }
- sync() {
- echo "onnx sync"
- if [ ! -d "./third_party/source/onnx" ]; then
- git clone --quiet --recursive https://github.com/onnx/onnx.git "./third_party/source/onnx"
- fi
- pushd "./third_party/source/onnx" > /dev/null
- git pull --quiet --prune
- git submodule sync --quiet
- git submodule update --quiet --init --recursive
- popd > /dev/null
- mkdir -p "./third_party/source/onnxruntime/core/flatbuffers/schema"
- curl --silent --show-error --location --output "./third_party/source/onnxruntime/core/flatbuffers/schema/ort.fbs" "https://github.com/microsoft/onnxruntime/raw/main/onnxruntime/core/flatbuffers/schema/ort.fbs"
- }
- install() {
- echo "onnx install"
- venv
- protobuf_version=$(grep "protobuf" ./third_party/source/onnx/requirements.txt | cut -d'=' -f2)
- protoc_dir="$(pwd)/third_party/bin/protobuf/v${protobuf_version}"
- case "${OSTYPE}" in
- # linux*)
- # [ -x "$(command -v cmake)" ] || sudo apt install -y cmake
- # if [ ! -f "${protoc_dir}/bin/protoc" ]; then
- # rm -rf ${protoc_dir}
- # git clone --quiet -c advice.detachedHead=false --quiet --recursive --depth=1 --branch v${protobuf_version} https://github.com/protocolbuffers/protobuf.git ${protoc_dir}/src
- # pushd "${protoc_dir}/src/cmake" > /dev/null
- # cmake ../cmake -DCMAKE_CXX_FLAGS="-w" -Dprotobuf_BUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX="..\.." -DCMAKE_INSTALL_SYSCONFDIR=/etc -DCMAKE_POSITION_INDEPENDENT_CODE=ON -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release > /dev/null
- # make -j$(nproc) > /dev/null
- # make install > /dev/null
- # popd > /dev/null
- # fi
- # export PATH="${protoc_dir}\bin":${PATH}
- # ;;
- # darwin*)
- # [ -x "$(command -v cmake)" ] || brew install cmake > /dev/null
- # if [ ! -f "${protoc_dir}/bin/protoc" ]; then
- # rm -rf ${protoc_dir}
- # git clone --quiet -c advice.detachedHead=false --quiet --recursive --depth=1 --branch v${protobuf_version} https://github.com/protocolbuffers/protobuf.git ${protoc_dir}/src
- # pushd "${protoc_dir}/src/cmake" > /dev/null
- # cmake ../cmake -DCMAKE_CXX_FLAGS="-w" -Dprotobuf_BUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX="..\.." -DCMAKE_INSTALL_SYSCONFDIR=/etc -DCMAKE_POSITION_INDEPENDENT_CODE=ON -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release > /dev/null
- # make > /dev/null
- # make install > /dev/null
- # popd > /dev/null
- # fi
- # export PATH="${protoc_dir}\bin":${PATH}
- # ;;
- msys*)
- # winget install -e --id=Microsoft.VisualStudio.2019.BuildTools --override "--passive --wait --add Microsoft.VisualStudio.Workload.VCTools;includeRecommended"
- programfiles_x86_dir=$(env | grep "^ProgramFiles(x86)=" | cut -d '=' -f 2)
- build_tools_dir="${programfiles_x86_dir}\Microsoft Visual Studio\2019\BuildTools"
- cmake_dir="${build_tools_dir}\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin"
- protobuf="protobuf==${protobuf_version}"
- ${python} -m pip install --quiet --upgrade ${protobuf}
- export PATH="$(cygpath -u "${cmake_dir}")":${PATH}
- msbuild_dir="${build_tools_dir}\MSBuild\Current\Bin"
- if [ ! -f "${protoc_dir}/bin/protoc.exe" ]; then
- rm -rf ${protoc_dir}
- git clone --quiet -c advice.detachedHead=false -b v${protobuf_version} https://github.com/protocolbuffers/protobuf.git ${protoc_dir}/src
- pushd "${protoc_dir}/src/cmake" > /dev/null
- "${cmake_dir}\cmake.exe" -G "Visual Studio 16 2019" -A x64 -Dprotobuf_MSVC_STATIC_RUNTIME=OFF -Dprotobuf_BUILD_SHARED_LIBS=OFF -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_BUILD_EXAMPLES=OFF -DCMAKE_INSTALL_PREFIX="..\..\.." . > /dev/null
- "${msbuild_dir}\MSBuild.exe" protobuf.sln //m //p:Configuration=Release > /dev/null
- "${msbuild_dir}\MSBuild.exe" INSTALL.vcxproj //p:Configuration=Release > /dev/null
- popd > /dev/null
- fi
- export PATH="${protoc_dir}\bin":${PATH}
- export USE_MSVC_STATIC_RUNTIME=0
- ;;
- esac
- ${python} -m pip install --quiet "./third_party/source/onnx"
- ${python} -m pip install --quiet --upgrade flatbuffers numpy packaging protobuf sympy
- ${python} -m pip install --quiet --upgrade onnxruntime --pre --extra-index https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/ORT-Nightly/pypi/simple/
- deactivate
- }
- schema() {
- echo "onnx schema"
- [[ $(grep -U $'\x0D' ./source/onnx-proto.js) ]] && crlf=1
- node ./tools/protoc.js --binary --text --json --root onnx --out ./source/onnx-proto.js --path ./third_party/source/onnx onnx/onnx-ml.proto onnx/onnx-operators-ml.proto
- if [[ -n ${crlf} ]]; then
- unix2dos --quiet --newfile ./source/onnx-proto.js ./source/onnx-proto.js
- fi
- [[ $(grep -U $'\x0D' ./source/onnx-schema.js) ]] && crlf=1
- node ./tools/flatc.js --root ort --out ./source/onnx-schema.js ./third_party/source/onnxruntime/core/flatbuffers/schema/ort.fbs
- if [[ -n ${crlf} ]]; then
- unix2dos --quiet --newfile ./source/onnx-schema.js ./source/onnx-schema.js
- fi
- }
- metadata() {
- echo "onnx metadata"
- [[ $(grep -U $'\x0D' ./source/onnx-metadata.json) ]] && crlf=1
- venv
- export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
- ${python} ./tools/onnx_script.py
- deactivate
- if [[ -n ${crlf} ]]; then
- unix2dos --quiet --newfile ./source/onnx-metadata.json ./source/onnx-metadata.json
- fi
- }
- while [ "$#" != 0 ]; do
- command="$1" && shift
- case "${command}" in
- "clean") clean;;
- "sync") sync;;
- "install") install;;
- "schema") schema;;
- "metadata") metadata;;
- esac
- done
|