搜索插件、代码仓与 APP 分类

插件详情v1.1.1

native_toolchain_rust

Dart 构建钩子的 Rust 支持。自动将您的 Rust 代码与 Dart 代码一起构建和打包!

AndroidiOSLinuxmacOSWindows
近 30 天下载
8.4万
喜欢数
29
Pub 分数
160

安装插件

flutter pub add native_toolchain_rust

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个 Flutter/Dart 包,可实现 Rust 代码与 Dart 项目的无缝集成。它使用构建钩子自动编译并打包 Rust 库,与 Dart 代码一同构建,简化跨语言开发。适用于加密、数据处理或系统级操作等对性能要求较高的组件。支持所有主要平台,包括 Android、iOS、Linux、macOS 和 Windows。

适合场景

  • 将高性能 Rust 库集成到 Flutter 应用中
  • 使用 Rust 构建加密函数
  • 优化数据密集型计算
  • 创建平台特定的原生扩展
  • 启用安全的低级别系统访问

主要特点

  • 通过构建钩子自动编译 Rust
  • 跨平台支持(Android、iOS、Linux、macOS、Windows)
  • 无缝的 Dart-Rust 互操作性
  • 最小化样板设置
  • 内置依赖管理

适合对象

  • 需要在 Flutter 中使用高性能原生代码的开发者
  • 使用 Rust 编写核心逻辑的团队
  • 需要安全、快速计算的项目
  • 跨平台原生扩展
  • Dart 开发人员探索 Rust 集成

使用建议

  • 需要在主机上安装 Rust 工具链
  • 由于 Rust 编译,构建时间可能增加
  • 对 Rust 代码的调试支持有限
  • 可能需要特定于平台的构建配置
  • Rust 初学者的学习曲线

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

🧱 native_toolchain_rust 🦀

Build Status Github Stars MIT License


Rust support for Dart's build hooks.

Why native_toolchain_rust?

  1. It's opinionated. That might sound bad, but it's opinionated in the way that keeps you from shooting yourself in the foot.
  2. Does more with less. The API is incredibly easy to use: the only thing you need to provide is assetName, and the rest is auto-magically figured out. (But you can still tweak the functionality as much as you need to!)

Getting Started

  1. Install rustup, for Rust, on your development computer (if you are a library author, consumers of your package will have to do the same)
  2. Run flutter pub add native_toolchain_rust hooks for Flutter or dart pub add native_toolchain_rust hooks for Dart-only
  3. See Code Setup

Code Setup

native_toolchain_rust will look (by default) for native/ or rust/ (customizable) in your Dart package's root. If you haven't already, create a Cargo.toml and rust-toolchain.toml in your chosen Rust directory; keep reading for what these two files must contain (but don't worry if you forget, you'll get a helpful error message).

hook/build.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',
      // ...maybe enable some Cargo features or something in here too
    ).run(input: input, output: output);
  });
}
Cargo.toml

Keep at least the following in your Cargo.toml.

[package]
name = "my-crate-name" # pick a name, doesn't matter

[lib]
crate-type = ["staticlib", "cdylib"] # THESE ARE IMPORTANT!
rust-toolchain.toml

Keep at least the following in your rust-toolchain.toml.

[toolchain]
# WARNING: *do not* use `stable`, `beta`, or `nightly` (alone) for the channel!
# You must specify a version number/date in order to ensure reproducible builds.
channel = "1.90.0" # or newer. another example: `nightly-2025-01-01`

# The targets you want to support; these are the default:
targets = [
  # Android
  "armv7-linux-androideabi",
  "aarch64-linux-android",
  "x86_64-linux-android",

  # iOS (device + simulator)
  "aarch64-apple-ios",
  "aarch64-apple-ios-sim",
  "x86_64-apple-ios",

  # Windows
  "aarch64-pc-windows-msvc",
  "x86_64-pc-windows-msvc",

  # Linux
  "aarch64-unknown-linux-gnu",
  "x86_64-unknown-linux-gnu",

  # macOS
  "aarch64-apple-darwin",
  "x86_64-apple-darwin",
]

所属分类

依赖

依赖清单 6 项

源码仓库

使用此插件的项目

暂无相关数据。

所在榜单