搜尋套件、儲存庫與 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 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。

所在榜單