diff --git a/apps/maple-research/frontend/src-tauri/scripts/onnxruntime-nuget.sh b/apps/maple-research/frontend/src-tauri/scripts/onnxruntime-nuget.sh new file mode 100644 index 000000000..88a91199b --- /dev/null +++ b/apps/maple-research/frontend/src-tauri/scripts/onnxruntime-nuget.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +# Extracts one native library from Microsoft's official ONNX Runtime NuGet +# package. The package is checked against its pin before anything is read from +# it. The caller must still check the extracted library against that library's +# own pin. +# +# The sourcing script provides onnxruntime-pins.sh and verify_sha256. +onnxruntime_nuget_extract_library() ( + set -euo pipefail + + version="$1" + entry="$2" + destination="$3" + + url="$(onnxruntime_nuget_package_url_for_version "${version}")" + expected="$(onnxruntime_nuget_package_sha256_for_version "${version}")" + destination_dir="$(dirname "${destination}")" + mkdir -p "${destination_dir}" + package="$(mktemp "${destination_dir}/.onnxruntime-nuget.XXXXXX")" + staged="$(mktemp "${destination}.XXXXXX")" + trap 'rm -f "${package}" "${staged}"' EXIT + + curl -fL --retry 5 --retry-delay 2 --retry-all-errors \ + "${url}" \ + --output "${package}" + verify_sha256 "ONNX Runtime NuGet package" "${package}" "${expected}" || exit 1 + + entry_count="$(unzip -Z1 "${package}" | grep -Fxc -- "${entry}" || true)" + if [ "${entry_count}" != "1" ]; then + echo "Expected exactly one ${entry} in the ONNX Runtime NuGet package; found ${entry_count}." >&2 + exit 1 + fi + + unzip -p "${package}" "${entry}" > "${staged}" || exit 1 + chmod 0755 "${staged}" + mv "${staged}" "${destination}" +) diff --git a/apps/maple-research/frontend/src-tauri/scripts/onnxruntime-pins.sh b/apps/maple-research/frontend/src-tauri/scripts/onnxruntime-pins.sh index ce6b55e44..26c1c38b5 100644 --- a/apps/maple-research/frontend/src-tauri/scripts/onnxruntime-pins.sh +++ b/apps/maple-research/frontend/src-tauri/scripts/onnxruntime-pins.sh @@ -1,24 +1,19 @@ #!/usr/bin/env bash -onnxruntime_linux_x64_archive_sha256_for_version() { - case "$1" in - 1.23.2) - printf '%s\n' "1fa4dcaef22f6f7d5cd81b28c2800414350c10116f5fdd46a2160082551c5f9b" - ;; - *) - echo "No pinned Linux x64 ONNX Runtime archive SHA-256 for version '$1'." >&2 - return 1 - ;; - esac +# Linux and Windows take their library from Microsoft's official NuGet package. +# The package pin guards the download; the per-platform library pins below are +# what a build is held to. +onnxruntime_nuget_package_url_for_version() { + printf '%s\n' "https://api.nuget.org/v3-flatcontainer/microsoft.ml.onnxruntime/$1/microsoft.ml.onnxruntime.$1.nupkg" } -onnxruntime_linux_aarch64_archive_sha256_for_version() { +onnxruntime_nuget_package_sha256_for_version() { case "$1" in 1.23.2) - printf '%s\n' "7c63c73560ed76b1fac6cff8204ffe34fe180e70d6582b5332ec094810241e5c" + printf '%s\n' "25fe172f7fcdf34f2b5b02c8b997f6b88abc282956849d4af4335af23d0c4e4a" ;; *) - echo "No pinned Linux aarch64 ONNX Runtime archive SHA-256 for version '$1'." >&2 + echo "No pinned ONNX Runtime NuGet package SHA-256 for version '$1'." >&2 return 1 ;; esac @@ -72,18 +67,6 @@ onnxruntime_macos_universal2_dylib_sha256_for_version() { esac } -onnxruntime_windows_x64_archive_sha256_for_version() { - case "$1" in - 1.23.2) - printf '%s\n' "0b38df9af21834e41e73d602d90db5cb06dbd1ca618948b8f1d66d607ac9f3cd" - ;; - *) - echo "No pinned Windows x64 ONNX Runtime archive SHA-256 for version '$1'." >&2 - return 1 - ;; - esac -} - onnxruntime_windows_x64_dll_sha256_for_version() { case "$1" in 1.23.2) diff --git a/apps/maple-research/frontend/src-tauri/scripts/provide-linux-onnxruntime.sh b/apps/maple-research/frontend/src-tauri/scripts/provide-linux-onnxruntime.sh index 8cc903244..049ea237c 100755 --- a/apps/maple-research/frontend/src-tauri/scripts/provide-linux-onnxruntime.sh +++ b/apps/maple-research/frontend/src-tauri/scripts/provide-linux-onnxruntime.sh @@ -4,16 +4,17 @@ set -euo pipefail ORT_VERSION="${ORT_VERSION:-1.23.2}" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source "${SCRIPT_DIR}/onnxruntime-pins.sh" +source "${SCRIPT_DIR}/onnxruntime-nuget.sh" case "$(uname -m)" in x86_64 | amd64) ORT_ARCH="x64" - ORT_ARCHIVE_SHA256_FUNC="onnxruntime_linux_x64_archive_sha256_for_version" + ORT_NUGET_RUNTIME="linux-x64" ORT_DYLIB_SHA256_FUNC="onnxruntime_linux_x64_dylib_sha256_for_version" ;; aarch64 | arm64) ORT_ARCH="aarch64" - ORT_ARCHIVE_SHA256_FUNC="onnxruntime_linux_aarch64_archive_sha256_for_version" + ORT_NUGET_RUNTIME="linux-arm64" ORT_DYLIB_SHA256_FUNC="onnxruntime_linux_aarch64_dylib_sha256_for_version" ;; *) @@ -25,10 +26,8 @@ esac TAURI_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)" ORT_ROOT="${TAURI_DIR}/onnxruntime-linux" ORT_DIR="${ORT_ROOT}/onnxruntime-linux-${ORT_ARCH}-${ORT_VERSION}" -ORT_ARCHIVE="onnxruntime-linux-${ORT_ARCH}-${ORT_VERSION}.tgz" -ORT_URL="https://github.com/microsoft/onnxruntime/releases/download/v${ORT_VERSION}/${ORT_ARCHIVE}" +ORT_NUGET_ENTRY="runtimes/${ORT_NUGET_RUNTIME}/native/libonnxruntime.so" ORT_DYLIB="${ORT_DIR}/lib/libonnxruntime.so.${ORT_VERSION}" -ORT_ARCHIVE_SHA256="$("${ORT_ARCHIVE_SHA256_FUNC}" "${ORT_VERSION}")" ORT_DYLIB_SHA256="$("${ORT_DYLIB_SHA256_FUNC}" "${ORT_VERSION}")" sha256_file() { @@ -63,16 +62,7 @@ verify_sha256() { if [ ! -f "${ORT_DYLIB}" ]; then rm -rf "${ORT_ROOT}" - mkdir -p "${ORT_ROOT}" - archive_path="${ORT_ROOT}/${ORT_ARCHIVE}" - - curl -fL --retry 5 --retry-delay 2 --retry-all-errors \ - "${ORT_URL}" \ - --output "${archive_path}" - - verify_sha256 "ONNX Runtime archive" "${archive_path}" "${ORT_ARCHIVE_SHA256}" - tar -xzf "${archive_path}" -C "${ORT_ROOT}" - rm -f "${archive_path}" + onnxruntime_nuget_extract_library "${ORT_VERSION}" "${ORT_NUGET_ENTRY}" "${ORT_DYLIB}" fi verify_sha256 "ONNX Runtime shared library" "${ORT_DYLIB}" "${ORT_DYLIB_SHA256}" diff --git a/apps/maple-research/frontend/src-tauri/scripts/provide-windows-onnxruntime.sh b/apps/maple-research/frontend/src-tauri/scripts/provide-windows-onnxruntime.sh index 713b5487c..0afd5e652 100755 --- a/apps/maple-research/frontend/src-tauri/scripts/provide-windows-onnxruntime.sh +++ b/apps/maple-research/frontend/src-tauri/scripts/provide-windows-onnxruntime.sh @@ -4,14 +4,13 @@ set -euo pipefail ORT_VERSION="${ORT_VERSION:-1.23.2}" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source "${SCRIPT_DIR}/onnxruntime-pins.sh" +source "${SCRIPT_DIR}/onnxruntime-nuget.sh" TAURI_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)" ORT_ROOT="${TAURI_DIR}/onnxruntime-windows" ORT_DIR="${ORT_ROOT}/onnxruntime-win-x64-${ORT_VERSION}" -ORT_ARCHIVE="onnxruntime-win-x64-${ORT_VERSION}.zip" -ORT_URL="https://github.com/microsoft/onnxruntime/releases/download/v${ORT_VERSION}/${ORT_ARCHIVE}" +ORT_NUGET_ENTRY="runtimes/win-x64/native/onnxruntime.dll" ORT_DLL="${ORT_DIR}/lib/onnxruntime.dll" -ORT_ARCHIVE_SHA256="$(onnxruntime_windows_x64_archive_sha256_for_version "${ORT_VERSION}")" ORT_DLL_SHA256="$(onnxruntime_windows_x64_dll_sha256_for_version "${ORT_VERSION}")" sha256_file() { @@ -61,16 +60,7 @@ to_native_path() { if [ ! -f "${ORT_DLL}" ]; then rm -rf "${ORT_ROOT}" - mkdir -p "${ORT_ROOT}" - archive_path="${ORT_ROOT}/${ORT_ARCHIVE}" - - curl -fL --retry 5 --retry-delay 2 --retry-all-errors \ - "${ORT_URL}" \ - --output "${archive_path}" - - verify_sha256 "ONNX Runtime archive" "${archive_path}" "${ORT_ARCHIVE_SHA256}" - unzip -q "${archive_path}" -d "${ORT_ROOT}" - rm -f "${archive_path}" + onnxruntime_nuget_extract_library "${ORT_VERSION}" "${ORT_NUGET_ENTRY}" "${ORT_DLL}" fi verify_sha256 "ONNX Runtime DLL" "${ORT_DLL}" "${ORT_DLL_SHA256}"