Allow building without ONNX Runtime

flutter_onnxruntime downloads ORT natively at build time, and the Linux and
Windows downloads from github.com/microsoft/onnxruntime are unavailable.
scripts/onnx.sh off swaps in a pure-Dart stub via pubspec_overrides.yaml, so no
platform pulls ORT; image messages then show as unavailable, as on web. Linux
CI builds use this mode for now.
This commit is contained in:
zjs81 committed 2026-11-20 16:38:09 -07:00
1 parent 34ea0cb7ca
commit d7fff0533e
12 files changed
+215 -13

No files matched your search

+5 -2
View File
@@ -72,8 +72,11 @@ appdir="$workspace/squashfs-root"
log 'Checking extracted AppImage structure'
[[ -x "$appdir/AppRun" && -f "$appdir/usr/bin/lib/libapp.so" && \
-f "$appdir/usr/bin/data/icudtl.dat" && -d "$appdir/usr/bin/data/flutter_assets" ]]
[[ -f "$appdir/usr/bin/lib/libonnxruntime.so.1" && \
-f "$appdir/usr/share/glib-2.0/schemas/gschemas.compiled" ]]
[[ -f "$appdir/usr/share/glib-2.0/schemas/gschemas.compiled" ]]
# ONNX-free builds (scripts/onnx.sh off) have neither the plugin nor ORT.
if [[ -f "$appdir/usr/bin/lib/libflutter_onnxruntime_plugin.so" ]]; then
[[ -f "$appdir/usr/bin/lib/libonnxruntime.so.1" ]]
fi
log 'Starting bundled ELF architecture audit'
elf_count=0
+54
View File
@@ -0,0 +1,54 @@
#!/usr/bin/env bash
# Switch ONNX Runtime (the image codec's inference engine) on or off.
#
# scripts/onnx.sh off build without ORT: no native plugin, no downloads
# scripts/onnx.sh on default build with ORT
# scripts/onnx.sh status print the current mode
#
# "off" writes pubspec_overrides.yaml, pointing flutter_onnxruntime at the
# pure-Dart stub in third_party/flutter_onnxruntime_stub; "on" removes it.
# Both run `flutter pub get` (set FLUTTER to use another flutter binary).
set -euo pipefail
root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
overrides="$root/pubspec_overrides.yaml"
marker='# Written by scripts/onnx.sh'
flutter_bin="${FLUTTER:-flutter}"
is_ours() {
[[ -f "$overrides" ]] && grep -Fq "$marker" "$overrides"
}
case "${1:-}" in
off)
if [[ -f "$overrides" ]] && ! is_ours; then
echo "pubspec_overrides.yaml exists and was not written by this script; edit it by hand." >&2
exit 1
fi
cat > "$overrides" <<EOF
$marker off. Remove with: scripts/onnx.sh on
dependency_overrides:
flutter_onnxruntime:
path: third_party/flutter_onnxruntime_stub
EOF
;;
on)
if [[ -f "$overrides" ]] && ! is_ours; then
echo "pubspec_overrides.yaml was not written by this script; remove the flutter_onnxruntime override by hand." >&2
exit 1
fi
rm -f "$overrides"
;;
status)
if is_ours; then echo off; else echo on; fi
exit 0
;;
*)
echo "usage: $0 off|on|status" >&2
exit 2
;;
esac
cd "$root"
"$flutter_bin" pub get
echo "ONNX Runtime: $1"