Zig support for Dart's build hooks. Automatically builds and bundles your Zig code with your Dart/Flutter application.
https://pub.dev/packages/native_toolchain_zig β// momentum
// why it's here
- Active: last commit today
- Built almost entirely by one person
- Has issues labelled for new contributors
- Health 76/100 with only 10 stars
// how to help
// readme
π§ native_toolchain_zig
Build Zig libraries with Dartβs [build hooks][dart_hooks] and generate Dart FFI bindings from exported Zig declarations. The build hook compiles and bundles the native library; the bindings CLI generates the Dart API that calls it.
The generator reads Zig source directly and uses zig translate-c for supported
@cImport declarations. You can generate bindings without maintaining a separate
C header for your exported Zig functions.
Prerequisites
- Dart SDK 3.14.0 or later, within the Dart 3 release series.
- [Zig][zig_download] installed and available as
zigonPATH. CI covers Zig 0.15.2, 0.16.0, and 0.17.1.
Installation
dart pub add hooks native_toolchain_zig
Project Setup
- Create your Zig project in
my_project/zig/:
my_package/
βββ bin/
β βββ main.dart
βββ hook/
β βββ build.dart
βββ lib/
β βββ my_package.dart
βββ zig/
β βββ src/
β β βββ lib.zig
β βββ build.zig
β βββ build.zig.zon
βββ pubspec.yaml
- Create
hook/build.dart: