Skip to content

Fix macOS LiteRT-LM runtime packaging#196

Closed
leehack wants to merge 1 commit into
mainfrom
fix-macos-litert-runtime
Closed

Fix macOS LiteRT-LM runtime packaging#196
leehack wants to merge 1 commit into
mainfrom
fix-macos-litert-runtime

Conversation

@leehack
Copy link
Copy Markdown
Owner

@leehack leehack commented Jun 4, 2026

Summary

  • Update the LiteRT-LM native runtime pin to leehack/litert-lm-native@v0.13.1, where StreamProxy is merged into the LiteRT-LM artifacts instead of shipped as standalone libraries.
  • Stop emitting macOS LiteRT-LM dylibs as Flutter native assets; keep them in the hook cache and copy/sign the original upstream dylibs into Contents/Frameworks/LiteRtLmRuntime for app bundles.
  • Update the native runtime loader to prefer app-local macOS LiteRT-LM libraries, then cache/framework fallbacks.
  • Simplify the LiteRT-LM hook metadata: derive archive names, release URLs, cache paths, and archive source prefixes from the bundle key, and validate caches by required libraries instead of maintaining per-archive SHA-256 markers.
  • Add OS-level llamadart_native_runtimes overrides (ios, macos, android, linux, windows) with exact target keys taking precedence, and document the package-size config path.

Validation

  • dart test test/unit/hook/build_hook_integration_test.dart test/unit/hook/build_hook_litert_lm_integration_test.dart test/unit/hook/native_bundle_config_test.dart
  • dart test test/unit/backends/litert_lm/litert_lm_runtime_test.dart test/unit/tooling/macos_litert_lm_prepare_app_script_test.dart
  • dart analyze

Additional macOS runtime validation performed before the final parser/docs/hook-metadata extension:

  • dart run tool/macos_litert_lm_engine_smoke.dart .dart_tool/litert_lm_models/gemma-4-E2B-it.litertlm gpu
  • flutter test --run-skipped -t local-only integration_test/litert_lm_chat_service_e2e_test.dart -d macos --dart-define=LITERT_LM_MODEL_URL=http://127.0.0.1:8765/gemma-4-E2B-it.litertlm --dart-define=LITERT_LM_E2E_BACKEND=cpu
  • flutter test --run-skipped -t local-only integration_test/litert_lm_chat_service_e2e_test.dart -d macos --dart-define=LITERT_LM_MODEL_URL=http://127.0.0.1:8765/gemma-4-E2B-it.litertlm --dart-define=LITERT_LM_E2E_BACKEND=auto
  • codesign --verify --deep --strict --verbose=2 build/macos/Build/Products/Debug/llamadart_chat_example.app

@leehack leehack marked this pull request as ready for review June 4, 2026 17:01
Copilot AI review requested due to automatic review settings June 4, 2026 17:01
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 4, 2026

Chat app preview removed for leehack/llamadart-chat-pr-196.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request updates LiteRT-LM native runtime packaging and loading behavior (especially on macOS) to match the upstream artifact changes in litert-lm-native@v0.13.1 (StreamProxy merged into the runtime), while also expanding native runtime selection config to support OS-level overrides.

Changes:

  • Bump LiteRT-LM native runtime pin to v0.13.1 and remove standalone StreamProxy library expectations across hooks/tests.
  • Change macOS bundling strategy: keep LiteRT-LM dylibs in the hook cache and provide a prepare script that copies/signs upstream dylibs into Contents/Frameworks/LiteRtLmRuntime.
  • Extend llamadart_native_runtimes parsing to support OS-level keys (e.g., ios, macos) with exact target keys taking precedence; add/adjust test coverage accordingly.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tool/macos_litert_lm_prepare_app.sh Switches macOS app preparation from embedding frameworks to copying/signing upstream dylibs into LiteRtLmRuntime.
tool/macos_fair_litert_vs_llamadart.sh Updates benchmark helper script to align with StreamProxy no longer being a standalone framework.
hook/build.dart Updates LiteRT-LM artifact pin, required libraries, extraction filtering, and skips emitting macOS LiteRT-LM libraries as code assets.
lib/src/backends/litert_lm/litert_lm_runtime.dart Updates loader logic to prefer app-local macOS libraries, updates iOS/macOS candidate lists, and loads StreamProxy symbols from the LiteRT-LM library.
lib/src/hook/native_bundle_config.dart Adds OS-level platform key support + aliases, with exact bundle keys taking precedence.
README.md Documents OS-level + exact-target overrides and updates pinned LiteRT-LM runtime version.
test/unit/tooling/macos_litert_lm_prepare_app_script_test.dart Updates tests to validate the new LiteRtLmRuntime dylib copy behavior instead of frameworks.
test/unit/hook/native_bundle_config_test.dart Adds coverage for OS-level platform map shapes and precedence rules.
test/unit/hook/build_hook_litert_lm_integration_test.dart Updates integration expectations for new artifact layout and macOS caching behavior; removes StreamProxy expectations.
test/unit/hook/build_hook_integration_test.dart Adds integration coverage for OS-level runtime selection and updates expected LiteRT-LM library lists.
test/unit/hook/build_hook_android_integration_test.dart Removes StreamProxy expectations from Android LiteRT-LM bundle tests.
test/unit/hook/build_hook_linux_integration_test.dart Removes StreamProxy expectations from Linux LiteRT-LM bundle tests.
test/unit/backends/litert_lm/litert_lm_runtime_test.dart Updates runtime candidate/required-library assertions to match StreamProxy-merged artifacts and macOS library loading.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread hook/build.dart
Comment on lines +404 to +410
if (code.targetOS == OS.macOS) {
log.info(
'Keeping macOS LiteRT-LM libraries in the hook cache at '
'${bundleDir.path}; the runtime loads them directly to avoid Flutter '
'rewriting upstream install names during app bundling.',
);
return;
@leehack leehack force-pushed the fix-macos-litert-runtime branch 2 times, most recently from 4276c7b to b2b05b4 Compare June 4, 2026 17:18
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Jun 4, 2026

Codecov Report

❌ Patch coverage is 88.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.62%. Comparing base (a0f6b4c) to head (e6c20d9).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
lib/src/hook/native_bundle_config.dart 86.36% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #196      +/-   ##
==========================================
+ Coverage   80.57%   80.62%   +0.04%     
==========================================
  Files          85       85              
  Lines       11392    11400       +8     
==========================================
+ Hits         9179     9191      +12     
+ Misses       2213     2209       -4     
Flag Coverage Δ
unittests 80.62% <88.00%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@leehack leehack force-pushed the fix-macos-litert-runtime branch 6 times, most recently from f3bcc1b to 03ff9c5 Compare June 4, 2026 19:25
@leehack
Copy link
Copy Markdown
Owner Author

leehack commented Jun 4, 2026

@copilot review

Copy link
Copy Markdown

Copilot AI commented Jun 4, 2026

@copilot review

The review comment about the silent return has already been addressed in this PR. In commit 03ff9c5, _emitLiteRtLmAssets now emits a log.warning(...) before returning when bundleSpec is null (lines 356–363 of hook/build.dart), so users will see a clear message pointing them to configure llamadart_native_runtimes to exclude litert_lm for unsupported targets.

@leehack leehack force-pushed the fix-macos-litert-runtime branch from 03ff9c5 to e6c20d9 Compare June 4, 2026 19:47
@leehack
Copy link
Copy Markdown
Owner Author

leehack commented Jun 5, 2026

Folded this into #198, which now targets main as the single Apple SPM/native-runtime PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants