4
0

fetch-onnxruntime.sh 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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|linux-aarch64|macos> <output folder> (linux = x86_64)
  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. # linux-aarch64 (Linux arm64, round 190oy) comes from the NuGet package only (its runtimes/linux-arm64 library, pinned
  17. # below): GitHub's archive answered 404 when it was added, so its hash could not be pinned, and no LYNX release before
  18. # 0.1.31 had an arm64 package to fall back on.
  19. set -euo pipefail
  20. PLATFORM="$1"; OUT="$2"
  21. VERSION=1.23.2
  22. case "$PLATFORM" in
  23. windows) ASSET="onnxruntime-win-x64-$VERSION.zip"; SHA=0b38df9af21834e41e73d602d90db5cb06dbd1ca618948b8f1d66d607ac9f3cd; LIB=lib/onnxruntime.dll ;;
  24. linux) ASSET="onnxruntime-linux-x64-$VERSION.tgz"; SHA=1fa4dcaef22f6f7d5cd81b28c2800414350c10116f5fdd46a2160082551c5f9b; LIB="lib/libonnxruntime.so.$VERSION" ;;
  25. linux-aarch64) ASSET=; SHA=; LIB="lib/libonnxruntime.so.$VERSION" ;;
  26. macos) ASSET="onnxruntime-osx-universal2-$VERSION.tgz"; SHA=49ae8e3a66ccb18d98ad3fe7f5906b6d7887df8a5edd40f49eb2b14e20885809; LIB="lib/libonnxruntime.$VERSION.dylib" ;;
  27. *) echo "unknown platform: $PLATFORM" >&2; exit 1 ;;
  28. esac
  29. NUGET_URL="https://api.nuget.org/v3-flatcontainer/microsoft.ml.onnxruntime/$VERSION/microsoft.ml.onnxruntime.$VERSION.nupkg"
  30. NUGET_SHA=25fe172f7fcdf34f2b5b02c8b997f6b88abc282956849d4af4335af23d0c4e4a
  31. case "$PLATFORM" in
  32. windows) NUGET_LIBS="runtimes/win-x64/native/onnxruntime.dll=dec964ab1ee36cc9b0ae247d13b376627992fc57dec0454354017ab8fd84f1ea" ;;
  33. linux) NUGET_LIBS="runtimes/linux-x64/native/libonnxruntime.so=13ab8084954fa4a47c777880180b90810d6020f021441395712b48a75b74c68b" ;;
  34. linux-aarch64) NUGET_LIBS="runtimes/linux-arm64/native/libonnxruntime.so=648ffa64fbe027ae27139109410900cf776a030dec2dbbac51053318cc44c286" ;;
  35. macos) NUGET_LIBS="runtimes/osx-arm64/native/libonnxruntime.dylib=d306d2bc768540766c7ed8a1e0ff05d2870c77a934ebeee4a7bafa1b732ef299
  36. runtimes/osx-x64/native/libonnxruntime.dylib=8c9c78de65ea3786f987c0d980e9c1b13a3a5fbc6b3e2965ba05b450e6e4c054" ;;
  37. esac
  38. FB_VER=0.1.30-alpha
  39. FB_URL="https://github.com/Ka1-S/LYNX-SHARE/releases/download/v$FB_VER"
  40. case "$PLATFORM" in
  41. windows) FB_ASSET=LYNX-$FB_VER-windows-x64.zip; FB_LIB=LYNX-$FB_VER-windows-x64/onnxruntime.dll
  42. FB_SHA=dec964ab1ee36cc9b0ae247d13b376627992fc57dec0454354017ab8fd84f1ea ;;
  43. linux) FB_ASSET=LYNX-$FB_VER-linux-x86_64.tar.gz; FB_LIB="LYNX-$FB_VER-linux-x86_64/libonnxruntime.so.$VERSION"
  44. FB_SHA=13ab8084954fa4a47c777880180b90810d6020f021441395712b48a75b74c68b ;;
  45. macos) FB_ASSET=LYNX-$FB_VER-macos-universal.dmg; FB_LIB="LYNX.app/Contents/Frameworks/libonnxruntime.$VERSION.dylib"
  46. FB_SHA=2e33c254d60eb81dbf3417a9f27d843cef8cd34344dbdd483e7bcd7d185ec909 ;;
  47. esac
  48. sha_ok() { if command -v sha256sum > /dev/null; then echo "$1 $2" | sha256sum -c -; else echo "$1 $2" | shasum -a 256 -c -; fi; }
  49. WORK="$(mktemp -d)"; trap 'rm -rf "$WORK"' EXIT
  50. mkdir -p "$OUT"
  51. # The library's file name inside LYNX's package (what src/ui/OnnxRuntime.h loads).
  52. DEST="$(basename "$LIB")"
  53. # 2. Microsoft's NuGet package: prints "ok" and installs when it worked; any failure falls through to 3.
  54. from_nuget() {
  55. curl -fsSL --retry 3 -o "$WORK/ort.nupkg" "$NUGET_URL" || return 1
  56. sha_ok "$NUGET_SHA" "$WORK/ort.nupkg" || return 1
  57. local parts=() entry name sha
  58. while IFS= read -r entry; do
  59. name="${entry%%=*}"; sha="${entry#*=}"
  60. python3 -c 'import sys, zipfile; open(sys.argv[3], "wb").write(zipfile.ZipFile(sys.argv[1]).read(sys.argv[2]))' \
  61. "$WORK/ort.nupkg" "$name" "$WORK/part${#parts[@]}" || return 1
  62. sha_ok "$sha" "$WORK/part${#parts[@]}" || return 1
  63. parts+=("$WORK/part${#parts[@]}")
  64. done <<< "$NUGET_LIBS"
  65. if [ "${#parts[@]}" -gt 1 ]; then
  66. command -v lipo > /dev/null || { echo "fetch-onnxruntime: no lipo here to join NuGet's macOS libraries"; return 1; }
  67. lipo -create "${parts[@]}" -output "$WORK/$DEST" || return 1
  68. else
  69. mv "${parts[0]}" "$WORK/$DEST"
  70. fi
  71. install -m 755 "$WORK/$DEST" "$OUT/"
  72. }
  73. if [ -z "$ASSET" ]; then
  74. from_nuget && exit 0
  75. echo "fetch-onnxruntime: Microsoft's NuGet package of ONNX Runtime $VERSION can't be downloaded or checked" >&2
  76. exit 1
  77. fi
  78. if ! curl -fsSL --retry 3 -o "$WORK/$ASSET" "https://github.com/microsoft/onnxruntime/releases/download/v$VERSION/$ASSET"; then
  79. echo "::warning::fetch-onnxruntime: Microsoft's $ASSET can't be downloaded from GitHub; trying Microsoft's NuGet package"
  80. if [ -z "${LYNX_ORT_SKIP_NUGET:-}" ] && from_nuget; then exit 0; fi
  81. echo "::warning::fetch-onnxruntime: taking ONNX Runtime $VERSION from LYNX SHARE $FB_VER's $FB_ASSET"
  82. curl -fsSL --retry 3 -o "$WORK/$FB_ASSET" "$FB_URL/$FB_ASSET"
  83. lib="$WORK/$(basename "$FB_LIB")"
  84. case "$FB_ASSET" in
  85. *.zip) python3 -c 'import sys, zipfile; open(sys.argv[3], "wb").write(zipfile.ZipFile(sys.argv[1]).read(sys.argv[2]))' \
  86. "$WORK/$FB_ASSET" "$FB_LIB" "$lib" ;;
  87. *.tar.gz) tar xzf "$WORK/$FB_ASSET" -C "$WORK" "$FB_LIB" && mv "$WORK/$FB_LIB" "$lib" ;;
  88. *.dmg) if command -v hdiutil > /dev/null; then
  89. hdiutil attach -nobrowse -readonly -mountpoint "$WORK/mnt" "$WORK/$FB_ASSET" > /dev/null
  90. cp "$WORK/mnt/$FB_LIB" "$lib"; hdiutil detach "$WORK/mnt" > /dev/null
  91. else 7zz e -y -o"$WORK" "$WORK/$FB_ASSET" "LYNX SHARE $FB_VER/$FB_LIB" > /dev/null; fi ;;
  92. esac
  93. sha_ok "$FB_SHA" "$lib"
  94. install -m 755 "$lib" "$OUT/"
  95. exit 0
  96. fi
  97. sha_ok "$SHA" "$WORK/$ASSET"
  98. case "$ASSET" in
  99. *.zip) python3 -c 'import sys, zipfile; zipfile.ZipFile(sys.argv[1]).extractall(sys.argv[2])' "$WORK/$ASSET" "$WORK" ;;
  100. *) tar xzf "$WORK/$ASSET" -C "$WORK" ;;
  101. esac
  102. mkdir -p "$OUT"
  103. install -m 755 "$WORK/${ASSET%.*}/$LIB" "$OUT/"