Skip to content
pubscout

native_toolchain_rust

1.1.1, released 6 days ago by gsconrad.com

Build and bundle Rust code into a Dart/Flutter project via build hooks.

$ flutter pub add native_toolchain_rust
Source repository

What it does

It automates compiling Rust libraries for all supported platforms and packages the binaries as assets that Dart can load. The only required input is the asset name; the rest is inferred from Cargo.toml and rust-toolchain.toml.

AI-written summary of version 1.0.7, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need native performance or system libraries written in Rust.
  • You want reproducible builds across Android, iOS, Windows, macOS, and Linux.
  • You prefer a declarative build setup over manual Cargo commands.

Skip it when

  • You only target a single platform and prefer manual Cargo integration.
  • You need fine‑grained control over the Rust build process beyond what the hook offers.

Strengths

  • Zero‑config Rust integration after initial Cargo setup.
  • Cross‑platform builds with a single command.
  • Automatic dependency discovery and rebuild triggers.
  • Supports both staticlib and cdylib targets.

Weaknesses

  • Requires rustup and a Rust toolchain on the developer machine.
  • Limited to the platforms listed; adding new targets needs code changes.

Setup

Kind
Pure Dart
Effort
Medium
Code generation
No
Direct dependencies
6

Add rustup, create Cargo.toml and rust-toolchain.toml, run flutter pub add native_toolchain_rust hooks, then add a build.dart hook that calls RustBuilder.

```dart
import 'package:hooks/hooks.dart';
import 'package:native_toolchain_rust/native_toolchain_rust.dart';

void main(List<String> args) async {
  await build(args, (input, output) async {
    await RustBuilder(assetName: 'src/my_ffi_bindings.g.dart').run(input: input, output: output);
  });
}
```

Alternatives

Packages that do the same job and could replace native_toolchain_rust.

Works with

Packages commonly used together with native_toolchain_rust: ones it builds on, ones built on it, and its own family.