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:
1 parent
34ea0cb7ca
commit
d7fff0533e
12 files changed
+215
-13
No files matched your search
@@ -12,6 +12,12 @@ on:
|
||||
- 'v*'
|
||||
pull_request:
|
||||
|
||||
env:
|
||||
# ONNX Runtime for the Linux jobs. Its Linux downloads from
|
||||
# github.com/microsoft/onnxruntime currently 404, so tagged Linux AppImages
|
||||
# ship without image messages until this is set back to "on".
|
||||
MESHCORE_LINUX_ONNX: "off"
|
||||
|
||||
jobs:
|
||||
android:
|
||||
runs-on: ubuntu-latest
|
||||
@@ -71,7 +77,7 @@ jobs:
|
||||
run: |
|
||||
shellcheck scripts/build_appimage.sh scripts/appimage/*.sh scripts/appimage/AppRun
|
||||
bash scripts/appimage/test_packaging.sh
|
||||
- run: flutter pub get
|
||||
- run: scripts/onnx.sh "$MESHCORE_LINUX_ONNX"
|
||||
- run: flutter build linux --release --no-pub
|
||||
- uses: docker/setup-buildx-action@v3
|
||||
- name: Read AppImage base image
|
||||
@@ -141,7 +147,7 @@ jobs:
|
||||
run: |
|
||||
shellcheck scripts/build_appimage.sh scripts/appimage/*.sh scripts/appimage/AppRun
|
||||
bash scripts/appimage/test_packaging.sh
|
||||
- run: flutter pub get
|
||||
- run: scripts/onnx.sh "$MESHCORE_LINUX_ONNX"
|
||||
- run: flutter test --reporter expanded
|
||||
- name: Build ARM64 Linux release
|
||||
run: |
|
||||
|
||||
@@ -38,3 +38,9 @@ jobs:
|
||||
|
||||
- name: Run tests
|
||||
run: flutter test -r github
|
||||
|
||||
- name: Analyze and test without ONNX Runtime
|
||||
run: |
|
||||
scripts/onnx.sh off
|
||||
flutter analyze --fatal-infos --fatal-warnings
|
||||
flutter test -r github
|
||||
@@ -94,3 +94,6 @@ keystore.properties
|
||||
|
||||
# Claude Code local working dir (worktrees, jobs, settings)
|
||||
.claude/
|
||||
|
||||
# Written by scripts/onnx.sh off (ONNX-free build)
|
||||
/pubspec_overrides.yaml
|
||||
@@ -151,6 +151,26 @@ The matrix describes implemented functionality, not a guarantee that every featu
|
||||
flutter run
|
||||
```
|
||||
|
||||
### Building without ONNX Runtime
|
||||
|
||||
ONNX Runtime (ORT) runs only the [image message](documentation/image-messages.md) codec, and every platform build fetches it: Linux and Windows from GitHub releases, Android from Maven Central, iOS and macOS from CocoaPods/SwiftPM. If those downloads fail, build without it:
|
||||
|
||||
```bash
|
||||
scripts/onnx.sh off # stub flutter_onnxruntime, then flutter pub get
|
||||
flutter build apk --release # or linux, windows, ios, macos
|
||||
scripts/onnx.sh on # back to the default build
|
||||
```
|
||||
|
||||
`off` writes a git-ignored `pubspec_overrides.yaml` that points `flutter_onnxruntime` at the pure-Dart stub in `third_party/flutter_onnxruntime_stub`, so no native plugin or ORT library is built, downloaded or bundled. On Windows without bash, create that file by hand:
|
||||
|
||||
```yaml
|
||||
dependency_overrides:
|
||||
flutter_onnxruntime:
|
||||
path: third_party/flutter_onnxruntime_stub
|
||||
```
|
||||
|
||||
Image messages then behave as on web: the app cannot send them or reconstruct received ones, and Settings says the build has no ONNX Runtime. Everything else is unchanged. While the override is active, `flutter pub get` also rewrites the committed plugin registrants (`linux/`, `windows/`, `macos/Flutter/`); switch back before committing. Linux builds in CI (`.github/workflows/build.yml`) currently use this mode because the ORT Linux release downloads are unavailable.
|
||||
|
||||
### Linux AppImage
|
||||
|
||||
`flutter build linux --release` produces the regular Flutter bundle and an
|
||||
|
||||
@@ -5,12 +5,16 @@ MeshCore Open can send a highly compressed image as channel GRP_DATA packets. Un
|
||||
## Requirements and setup
|
||||
|
||||
- Companion firmware version code **11 or later** (identified in the connector as v1.15.0) for the current channel-data layout.
|
||||
- A native runtime with a working ONNX backend. The web build has no image codec backend.
|
||||
- A native runtime with a working ONNX backend. The web build has no image codec backend, and neither does a native build made without ONNX Runtime (see below).
|
||||
- The image model bundle installed through App Settings → Image model, and Enable image messages turned on.
|
||||
- Enough storage for the roughly 1 GB bundle and enough available memory for reconstruction, which can peak above 2 GB. Actual latency and memory usage depend on hardware.
|
||||
|
||||
Downloads use the configured Hugging Face model bundle, support resume, and verify file checksums. Download the model while internet is available. Once installed, encoding and reconstruction run locally; photos are not uploaded for inference. Compatible recipients need the same supported codec/model format.
|
||||
|
||||
### Builds without ONNX Runtime
|
||||
|
||||
`scripts/onnx.sh off` builds the app with a pure-Dart stub in place of `flutter_onnxruntime`, so no platform downloads or bundles ORT ([how to build](../README.md#building-without-onnx-runtime)). In that build image messages are unavailable, exactly as on web: the image button and Settings explain that the build has no ONNX Runtime, the model cannot be downloaded, and received images cannot be reconstructed. `scripts/onnx.sh on` restores the default build. The app detects the stub because its `OnnxRuntime()` constructor throws (`imageCodecRuntimeAvailable` in [image_codec_backend.dart](../lib/services/image_codec_backend.dart)).
|
||||
|
||||
## Send an image
|
||||
|
||||
1. Open channel chat and tap the image button beside the composer.
|
||||
|
||||
@@ -871,14 +871,33 @@ class ImageCodecCancelled implements Exception {
|
||||
String toString() => 'Image processing stopped.';
|
||||
}
|
||||
|
||||
/// Whether this build can run the image codec at all.
|
||||
///
|
||||
/// False on web and in a build made with `scripts/onnx.sh off`, where
|
||||
/// `flutter_onnxruntime` is the pure-Dart stub whose [OnnxRuntime] constructor
|
||||
/// throws [UnsupportedError]. The real constructor has no side effects.
|
||||
final bool imageCodecRuntimeAvailable = _probeOnnxRuntime();
|
||||
|
||||
bool _probeOnnxRuntime() {
|
||||
if (kIsWeb) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
OnnxRuntime();
|
||||
return true;
|
||||
} on UnsupportedError {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Factory used by the codec worker isolate.
|
||||
///
|
||||
/// Returns `null` on web, where there is no local model file and no isolate.
|
||||
/// Everywhere else it returns the real [OnnxImageCodecBackend]; the session
|
||||
/// turns a `null` here into an [ImageCodecUnimplemented], which the service
|
||||
/// surfaces as `lastError` and maps to `ImageCodecAvailability.unavailable`.
|
||||
/// Returns `null` when [imageCodecRuntimeAvailable] is false. Everywhere else
|
||||
/// it returns the real [OnnxImageCodecBackend]; the session turns a `null`
|
||||
/// here into an [ImageCodecUnimplemented], which the service surfaces as
|
||||
/// `lastError` and maps to `ImageCodecAvailability.unavailable`.
|
||||
ImageCodecBackend? createImageCodecBackend() {
|
||||
if (kIsWeb) {
|
||||
if (!imageCodecRuntimeAvailable) {
|
||||
return null;
|
||||
}
|
||||
return OnnxImageCodecBackend();
|
||||
|
||||
@@ -8,7 +8,8 @@ import '../models/image_codec_support.dart';
|
||||
import '../utils/app_logger.dart';
|
||||
import '../widgets/image_send_codec_binding.dart';
|
||||
import 'app_settings_service.dart';
|
||||
import 'image_codec_backend.dart' show kImageCodecBitstreamPathAvailable;
|
||||
import 'image_codec_backend.dart'
|
||||
show imageCodecRuntimeAvailable, kImageCodecBitstreamPathAvailable;
|
||||
import 'image_codec_file_store.dart';
|
||||
import 'image_codec_session.dart';
|
||||
import 'image_codec_settings_store.dart';
|
||||
@@ -177,9 +178,10 @@ class ImageCodecService extends ChangeNotifier implements ImageSendCodec {
|
||||
|
||||
/// Why [availability] is `unavailable`, or null when it is not.
|
||||
///
|
||||
/// EXACTLY THREE CAUSES, all of them permanent properties of the build or the
|
||||
/// EXACTLY FOUR CAUSES, all of them permanent properties of the build or the
|
||||
/// platform, none of them fixable by the user:
|
||||
/// * web, which has no native inference runtime;
|
||||
/// * a build made without ONNX Runtime ([imageCodecRuntimeAvailable]);
|
||||
/// * a build compiled without the entropy path
|
||||
/// ([kImageCodecBitstreamPathAvailable]);
|
||||
/// * a backend that failed to load.
|
||||
@@ -194,6 +196,10 @@ class ImageCodecService extends ChangeNotifier implements ImageSendCodec {
|
||||
return 'The image codec needs a native inference runtime, which the web '
|
||||
'build does not have.';
|
||||
}
|
||||
if (!imageCodecRuntimeAvailable) {
|
||||
return 'This build was made without ONNX Runtime, so it cannot send or '
|
||||
'show image messages.';
|
||||
}
|
||||
if (!kImageCodecBitstreamPathAvailable) {
|
||||
return 'This build ships the image decoder only. Encoding and decoding a '
|
||||
'bitstream also needs the entropy-side graph and the rANS coder, '
|
||||
@@ -510,7 +516,7 @@ class ImageCodecService extends ChangeNotifier implements ImageSendCodec {
|
||||
/// works. [canEncode]/[canDecode] additionally require the entropy path.
|
||||
bool get canRunInference {
|
||||
final model = selectedModel;
|
||||
return !kIsWeb &&
|
||||
return imageCodecRuntimeAvailable &&
|
||||
!_backendMissing &&
|
||||
model != null &&
|
||||
model.localPath.isNotEmpty;
|
||||
|
||||
@@ -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
|
||||
|
||||
Executable
+54
@@ -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"
|
||||
@@ -0,0 +1,35 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/models/image_codec_support.dart';
|
||||
import 'package:meshcore_open/services/app_settings_service.dart';
|
||||
import 'package:meshcore_open/services/image_codec_backend.dart';
|
||||
import 'package:meshcore_open/services/image_codec_service.dart';
|
||||
import 'package:meshcore_open/services/image_codec_settings_store.dart';
|
||||
import 'package:meshcore_open/widgets/image_send_codec_binding.dart';
|
||||
|
||||
/// Runs in both build modes; each half skips in the other (`scripts/onnx.sh`).
|
||||
void main() {
|
||||
ImageCodecService newService() {
|
||||
final service = ImageCodecService(
|
||||
AppSettingsService(),
|
||||
settingsStore: InMemoryImageCodecSettingsStore(
|
||||
const ImageCodecPreferences(enabled: true),
|
||||
),
|
||||
);
|
||||
addTearDown(service.dispose);
|
||||
return service;
|
||||
}
|
||||
|
||||
test('ONNX-free build reports the image codec unavailable', () {
|
||||
final service = newService();
|
||||
expect(createImageCodecBackend(), isNull);
|
||||
expect(service.availability, ImageCodecAvailability.unavailable);
|
||||
expect(service.unavailableReason, contains('without ONNX Runtime'));
|
||||
expect(service.canRunInference, isFalse);
|
||||
}, skip: imageCodecRuntimeAvailable ? 'ONNX Runtime is compiled in' : false);
|
||||
|
||||
test('ONNX build has a codec backend', () {
|
||||
final service = newService();
|
||||
expect(createImageCodecBackend(), isA<OnnxImageCodecBackend>());
|
||||
expect(service.unavailableReason, isNull);
|
||||
}, skip: imageCodecRuntimeAvailable ? false : 'built without ONNX Runtime');
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/// Stand-in for `flutter_onnxruntime` in builds made without ONNX Runtime.
|
||||
///
|
||||
/// Mirrors only the API MeshCore Open uses. [OnnxRuntime] cannot be
|
||||
/// constructed, which is how the app detects this build.
|
||||
library;
|
||||
|
||||
UnsupportedError _unsupported() =>
|
||||
UnsupportedError('This build was made without ONNX Runtime.');
|
||||
|
||||
class OnnxRuntime {
|
||||
OnnxRuntime() {
|
||||
throw _unsupported();
|
||||
}
|
||||
|
||||
Future<OrtSession> createSession(String modelPath) => throw _unsupported();
|
||||
}
|
||||
|
||||
abstract class OrtSession {
|
||||
List<String> get inputNames;
|
||||
|
||||
List<String> get outputNames;
|
||||
|
||||
Future<Map<String, OrtValue>> run(Map<String, OrtValue> inputs);
|
||||
|
||||
Future<void> close();
|
||||
}
|
||||
|
||||
abstract class OrtValue {
|
||||
List<int> get shape;
|
||||
|
||||
static Future<OrtValue> fromList(dynamic data, List<int> shape) =>
|
||||
throw _unsupported();
|
||||
|
||||
Future<List<dynamic>> asFlattenedList();
|
||||
|
||||
Future<void> dispose();
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
name: flutter_onnxruntime
|
||||
description: >-
|
||||
Pure-Dart stand-in for flutter_onnxruntime, used by `scripts/onnx.sh off` to
|
||||
build MeshCore Open without ONNX Runtime. No native plugin, no downloads.
|
||||
version: 1.9.0
|
||||
publish_to: none
|
||||
|
||||
environment:
|
||||
sdk: ^3.7.0
|
||||
Reference in new issue
Block a user