fetch-onnxruntime.sh 6.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/usr/bin/env bash
  2. # Puts ONNX Runtime's library for one platform into a folder, checksum verified. LYNX loads it at run time for
  3. # "Extract stems from sample". 1.23.2 is the last release with a universal macOS build (Intel Macs are still supported).
  4. #
  5. # usage: scripts/fetch-onnxruntime.sh <windows|linux|macos> <output folder>
  6. #
  7. # Sources, in order (round 190nk found github.com/microsoft/onnxruntime answering 404 on 2026-11-20; round 190nr saw the
  8. # same later that day, repository and API included):
  9. # 1. Microsoft's release archive on GitHub (archive SHA-256 pinned below).
  10. # 2. Microsoft's NuGet package Microsoft.ML.OnnxRuntime 1.23.2 from nuget.org (package and library SHA-256 pinned).
  11. # Its win-x64 onnxruntime.dll and linux-x64 libonnxruntime.so are byte for byte the libraries of the GitHub
  12. # archives (the same hashes LYNX 0.1.24-0.1.30 shipped). It has no universal macOS library: the arm64 and x86_64
  13. # ones are joined with lipo (macOS only; package-macos.sh re-signs the bundle ad hoc anyway).
  14. # 3. LYNX SHARE 0.1.30's release package, which holds the same 1.23.2 libraries (hashes checked: Windows / Linux =
  15. # Microsoft's files; macOS = the universal library 0.1.24-0.1.30 shipped).
  16. set -euo pipefail
  17. PLATFORM="$1"; OUT="$2"
  18. VERSION=1.23.2
  19. case "$PLATFORM" in
  20. windows) ASSET="onnxruntime-win-x64-$VERSION.zip"; SHA=0b38df9af21834e41e73d602d90db5cb06dbd1ca618948b8f1d66d607ac9f3cd; LIB=lib/onnxruntime.dll ;;
  21. linux) ASSET="onnxruntime-linux-x64-$VERSION.tgz"; SHA=1fa4dcaef22f6f7d5cd81b28c2800414350c10116f5fdd46a2160082551c5f9b; LIB="lib/libonnxruntime.so.$VERSION" ;;
  22. macos) ASSET="onnxruntime-osx-universal2-$VERSION.tgz"; SHA=49ae8e3a66ccb18d98ad3fe7f5906b6d7887df8a5edd40f49eb2b14e20885809; LIB="lib/libonnxruntime.$VERSION.dylib" ;;
  23. *) echo "unknown platform: $PLATFORM" >&2; exit 1 ;;
  24. esac
  25. NUGET_URL="https://api.nuget.org/v3-flatcontainer/microsoft.ml.onnxruntime/$VERSION/microsoft.ml.onnxruntime.$VERSION.nupkg"
  26. NUGET_SHA=25fe172f7fcdf34f2b5b02c8b997f6b88abc282956849d4af4335af23d0c4e4a
  27. case "$PLATFORM" in
  28. windows) NUGET_LIBS="runtimes/win-x64/native/onnxruntime.dll=dec964ab1ee36cc9b0ae247d13b376627992fc57dec0454354017ab8fd84f1ea" ;;
  29. linux) NUGET_LIBS="runtimes/linux-x64/native/libonnxruntime.so=13ab8084954fa4a47c777880180b90810d6020f021441395712b48a75b74c68b" ;;
  30. macos) NUGET_LIBS="runtimes/osx-arm64/native/libonnxruntime.dylib=d306d2bc768540766c7ed8a1e0ff05d2870c77a934ebeee4a7bafa1b732ef299
  31. runtimes/osx-x64/native/libonnxruntime.dylib=8c9c78de65ea3786f987c0d980e9c1b13a3a5fbc6b3e2965ba05b450e6e4c054" ;;
  32. esac
  33. FB_VER=0.1.30-alpha
  34. FB_URL="https://github.com/Ka1-S/LYNX-SHARE/releases/download/v$FB_VER"
  35. case "$PLATFORM" in
  36. windows) FB_ASSET=LYNX-$FB_VER-windows-x64.zip; FB_LIB=LYNX-$FB_VER-windows-x64/onnxruntime.dll
  37. FB_SHA=dec964ab1ee36cc9b0ae247d13b376627992fc57dec0454354017ab8fd84f1ea ;;
  38. linux) FB_ASSET=LYNX-$FB_VER-linux-x86_64.tar.gz; FB_LIB="LYNX-$FB_VER-linux-x86_64/libonnxruntime.so.$VERSION"
  39. FB_SHA=13ab8084954fa4a47c777880180b90810d6020f021441395712b48a75b74c68b ;;
  40. macos) FB_ASSET=LYNX-$FB_VER-macos-universal.dmg; FB_LIB="LYNX.app/Contents/Frameworks/libonnxruntime.$VERSION.dylib"
  41. FB_SHA=2e33c254d60eb81dbf3417a9f27d843cef8cd34344dbdd483e7bcd7d185ec909 ;;
  42. esac
  43. sha_ok() { if command -v sha256sum > /dev/null; then echo "$1 $2" | sha256sum -c -; else echo "$1 $2" | shasum -a 256 -c -; fi; }
  44. WORK="$(mktemp -d)"; trap 'rm -rf "$WORK"' EXIT
  45. mkdir -p "$OUT"
  46. # The library's file name inside LYNX's package (what src/ui/OnnxRuntime.h loads).
  47. DEST="$(basename "$LIB")"
  48. # 2. Microsoft's NuGet package: prints "ok" and installs when it worked; any failure falls through to 3.
  49. from_nuget() {
  50. curl -fsSL --retry 3 -o "$WORK/ort.nupkg" "$NUGET_URL" || return 1
  51. sha_ok "$NUGET_SHA" "$WORK/ort.nupkg" || return 1
  52. local parts=() entry name sha
  53. while IFS= read -r entry; do
  54. name="${entry%%=*}"; sha="${entry#*=}"
  55. python3 -c 'import sys, zipfile; open(sys.argv[3], "wb").write(zipfile.ZipFile(sys.argv[1]).read(sys.argv[2]))' \
  56. "$WORK/ort.nupkg" "$name" "$WORK/part${#parts[@]}" || return 1
  57. sha_ok "$sha" "$WORK/part${#parts[@]}" || return 1
  58. parts+=("$WORK/part${#parts[@]}")
  59. done <<< "$NUGET_LIBS"
  60. if [ "${#parts[@]}" -gt 1 ]; then
  61. command -v lipo > /dev/null || { echo "fetch-onnxruntime: no lipo here to join NuGet's macOS libraries"; return 1; }
  62. lipo -create "${parts[@]}" -output "$WORK/$DEST" || return 1
  63. else
  64. mv "${parts[0]}" "$WORK/$DEST"
  65. fi
  66. install -m 755 "$WORK/$DEST" "$OUT/"
  67. }
  68. if ! curl -fsSL --retry 3 -o "$WORK/$ASSET" "https://github.com/microsoft/onnxruntime/releases/download/v$VERSION/$ASSET"; then
  69. echo "::warning::fetch-onnxruntime: Microsoft's $ASSET can't be downloaded from GitHub; trying Microsoft's NuGet package"
  70. if [ -z "${LYNX_ORT_SKIP_NUGET:-}" ] && from_nuget; then exit 0; fi
  71. echo "::warning::fetch-onnxruntime: taking ONNX Runtime $VERSION from LYNX SHARE $FB_VER's $FB_ASSET"
  72. curl -fsSL --retry 3 -o "$WORK/$FB_ASSET" "$FB_URL/$FB_ASSET"
  73. lib="$WORK/$(basename "$FB_LIB")"
  74. case "$FB_ASSET" in
  75. *.zip) python3 -c 'import sys, zipfile; open(sys.argv[3], "wb").write(zipfile.ZipFile(sys.argv[1]).read(sys.argv[2]))' \
  76. "$WORK/$FB_ASSET" "$FB_LIB" "$lib" ;;
  77. *.tar.gz) tar xzf "$WORK/$FB_ASSET" -C "$WORK" "$FB_LIB" && mv "$WORK/$FB_LIB" "$lib" ;;
  78. *.dmg) if command -v hdiutil > /dev/null; then
  79. hdiutil attach -nobrowse -readonly -mountpoint "$WORK/mnt" "$WORK/$FB_ASSET" > /dev/null
  80. cp "$WORK/mnt/$FB_LIB" "$lib"; hdiutil detach "$WORK/mnt" > /dev/null
  81. else 7zz e -y -o"$WORK" "$WORK/$FB_ASSET" "LYNX SHARE $FB_VER/$FB_LIB" > /dev/null; fi ;;
  82. esac
  83. sha_ok "$FB_SHA" "$lib"
  84. install -m 755 "$lib" "$OUT/"
  85. exit 0
  86. fi
  87. sha_ok "$SHA" "$WORK/$ASSET"
  88. case "$ASSET" in
  89. *.zip) python3 -c 'import sys, zipfile; zipfile.ZipFile(sys.argv[1]).extractall(sys.argv[2])' "$WORK/$ASSET" "$WORK" ;;
  90. *) tar xzf "$WORK/$ASSET" -C "$WORK" ;;
  91. esac
  92. mkdir -p "$OUT"
  93. install -m 755 "$WORK/${ASSET%.*}/$LIB" "$OUT/"