Thank you for your interest in contributing to llamadart! We welcome contributions from the community to help improve this package.
Before you begin, ensure you have the following installed:
- Dart SDK: >= 3.10.7
- Flutter SDK: >= 3.38.0 (optional, for running UI examples)
- CMake: >= 3.10
- C++ Compiler:
- macOS: Xcode Command Line Tools (
xcode-select --install) - Linux: GCC/G++ (
build-essential) or Clang - Windows: Visual Studio 2022 (Desktop development with C++).
- Tip: Install
ccacheorsccacheviachoco install sccacheto speed up local builds.
- Tip: Install
- macOS: Xcode Command Line Tools (
The project follows a modular, decoupled architecture:
lib/src/core/engine/: Core orchestration (LlamaEngine,ChatSession).lib/src/core/template/: Chat template routing, handlers, parser logic.lib/src/backends/: Platform-agnostic backend interface and native/web backends.lib/src/core/models/: Shared data models (messages, params, tools, config).lib/src/core/: Shared utilities (exceptions, logger, grammar helpers).
Native source and build orchestration now live in
leehack/llamadart-native.
- Zero Direct Modifications: Do not patch upstream
llama.cppsources in this repository. - Sync-Only in this repo: This repository consumes released native bundles and generated bindings.
- Build logic lives elsewhere: Native build scripts and backend matrix changes belong in
llamadart-native.
llamadart uses a modern binary distribution lifecycle:
Native binaries are built and released from
leehack/llamadart-native.
That repository publishes multi-library native bundles for
Android, iOS, macOS, Linux, and Windows.
Web bridge source/build and published runtime assets are managed in:
llamadart consumes pinned bridge assets from llama-web-bridge-assets
for example/chat_app and web backend testing via
scripts/fetch_webgpu_bridge_assets.sh.
When a user adds llamadart as a dependency and runs their app:
- The
hook/build.dartscript executes automatically. - It detects the user's current target OS and architecture.
- It downloads the matching pre-compiled native bundle from
leehack/llamadart-nativeGitHub Releases. - It reports the required shared libraries to the Dart VM as
CodeAssets, includingpackage:llamadart/llamadart.
- The library uses
@Nativetop-level bindings inlib/src/backends/llama_cpp/bindings.dart. - The Dart VM automatically resolves these calls to the downloaded binary reported by the hook.
- This provides a "Zero-Setup" experience while maintaining high-performance native execution.
-
Clone the repository:
git clone https://github.com/leehack/llamadart.git cd llamadart -
Initialize:
dart pub get
-
Build/Fetch Native Library: In most cases, simply running the examples will handle everything:
cd example/basic_app dart runThe
hook/build.dartwill automatically download the correct pre-compiled binaries for your platform.
Maintainers often keep related repositories as siblings one level above
llamadart:
../llamadart
../llamadart-native
../llama-web-bridge
../llama-web-bridge-assets
This is a convenience convention, not a hard requirement. Always verify paths in your environment before using them.
- If changing native runtime behavior: edit
../llamadart-native, release there, then sync/updatellamadart. - If changing web bridge runtime behavior: edit
../llama-web-bridge, publish assets to../llama-web-bridge-assets, then update pinned tag/docs inllamadart. - Keep ownership boundaries clear: this repo should avoid direct upstream source patching for native/web runtime internals.
We take testing seriously. CI enforces >=70% line coverage on maintainable lib/ code. Auto-generated files are excluded when they are marked with // coverage:ignore-file.
We use dart_test.yaml and @TestOn tags to manage multi-platform execution.
Running dart test will run VM and Chrome-compatible tests. Tests tagged
local-only are intentionally skipped in default and CI runs.
# Run default suite (VM + Chrome-compatible tests)
dart test
# Run local-only E2E tests
dart test --run-skipped -t local-onlyYou can still target specific platforms if needed:
# Run only VM tests
dart test -p vm
# Run only Chrome tests
dart test -p chrome
# Verify architecture boundaries (shared/web-safe code has no dart:io/dart:ffi)
dart run tool/testing/check_platform_boundaries.dartTo collect and view coverage reports:
# 1. Run VM tests with coverage
dart test -p vm --coverage=coverage
# 2. Format into LCOV (respects // coverage:ignore-file)
dart pub global run coverage:format_coverage --lcov --in=coverage/test --out=coverage/lcov.info --report-on=lib --check-ignore
# 3. Enforce >=70% threshold
dart run tool/testing/check_lcov_threshold.dart coverage/lcov.info 70- Structure:
- Unit tests live in
test/unit/and mirrorlib/src/paths. - Generated/native-bridge files are excluded from strict mirroring when marked with
// coverage:ignore-file. - Scenario, regression, and diagnostic tests live in
test/integration/. - Slow, local-machine scenarios live in
test/e2e/with@Tags(['local-only']).
- Unit tests live in
- Refactoring: If you refactor shared logic, ensure both Native and Web tests pass.
- New Features: Every new public API or feature must include unit or integration tests.
- Platform-Safety:
LlamaEnginemust remaindart:ffianddart:iofree to maintain web support.
If you need to build binaries for a new release:
-
Use the native build repository:
git clone https://github.com/leehack/llamadart-native.git cd llamadart-native git submodule update --init --recursive -
Build/release with the native pipeline:
- Run
Native Build & Releaseinllamadart-native(.github/workflows/native_release.yml), or - Build locally via
python3 tools/build.py ...as documented in that repository.
- Run
-
Sync
llamadarthook pin:- Run
Sync Native Version & Bindings(.github/workflows/sync_native_bindings.yml) in this repository to:- resolve a
llamadart-nativerelease tag, - sync headers from the matching release header bundle,
- regenerate Dart bindings from the matching native headers,
- open an automated PR with the updates.
- resolve a
- For local regeneration, run:
tool/native/sync_native_headers_and_bindings.sh --tag latest
- Run
-
cd example/basic_app dart run
-
cd example/chat_app flutter run -d macos # or linux, windows, android, ios
- Code Style: We follow standard Dart linting rules. Run
dart format .before committing. - Native Assets: The package uses the modern Dart Native Assets (hooks) mechanism.
- Testing: Add unit tests for new features where possible. Use
dart testfor full integration and unit verification.
- Fork the repository.
- Create a new branch (
git checkout -b feature/my-feature). - Commit your changes.
- Push to your fork and submit a Pull Request.
Thank you for contributing!