Dart Native Assets for macOS/iOS#681
Conversation
Ran Code Formatter
| sdk: ">=3.5.0 <4.0.0" | ||
| flutter: ">=3.24.0" | ||
| sdk: ">=3.10.0 <4.0.0" | ||
| flutter: ">=3.38.0" |
There was a problem hiding this comment.
Raises the package floor to the first Dart/Flutter toolchain that can actually resolve Native Assets hooks, and adds the hook/build dependencies (code_assets, hooks, native_toolchain_rust, logging, path) needed to build the Rust crate from Dart instead of CocoaPods on Apple.
| const _hubPath = 'native/hub'; | ||
|
|
||
| void main(List<String> args) async { | ||
| await build(args, (input, output) async { |
There was a problem hiding this comment.
Adds the Native Assets build hook entrypoint for rinf. This is the core migration: Flutter now invokes this hook during Apple builds so Rust compilation is orchestrated from Dart’s native asset pipeline rather than from Podspec script phases.
| final cratePath = _resolveCratePath(input); | ||
| logger.info('Building Rust crate from $cratePath'); | ||
|
|
||
| await RustBuilder( |
There was a problem hiding this comment.
Uses native_toolchain_rust.RustBuilder to compile the hub crate as a code asset named rinf.dart, and maps Flutter’s build configuration to Rust build mode so debug simulator runs stay debug while linked/release builds use release mode.
| }); | ||
| } | ||
|
|
||
| String _resolveCratePath(BuildInput input) { |
There was a problem hiding this comment.
Resolves the Rust crate path to the native/hub location and validates that it exists. This intentionally preserves Rinf’s longstanding cross-platform convention.
| return './$relative'; | ||
| } | ||
|
|
||
| Uri _resolveAppRoot(BuildInput input) { |
There was a problem hiding this comment.
Derives the consuming app root from the hook runner output path, which is what allows the package-local hook to find the app-local native/hub crate. This is the key piece that makes Native Assets workable without extra pubspec.yaml configuration.
|
|
||
| flutter: | ||
| config: | ||
| enable-swift-package-manager: false |
There was a problem hiding this comment.
Disables Flutter Swift Package Manager in the example app so the Apple Native Assets proof-of-concept is validated in isolation.
| @@ -0,0 +1,22 @@ | |||
| [toolchain] | |||
| channel = "1.91.0" | |||
There was a problem hiding this comment.
Pinned a toolchain with all targets that rinf supports so testing is consistent across platforms. Included a template that can be added to new projects as well.
|
CI was using an older version of flutter that did not have |
Changes
Implemented Dart Native Assets strictly for macOS/iOS
Partial completion of #641
Closes #673 (satisfies migrating away from CocoaPods)
This replaces the Apple-side Rust build path with a hook/build.dart Native Assets build hook in flutter_package, using native_toolchain_rust to compile the app-local native/hub crate during Flutter builds. The Apple proof path now works without CocoaPods driving Rust compilation, while keeping the existing native/hub project layout intact.
The implementation is intentionally scoped to macOS and iOS only. Other platforms remain on their existing build integrations, so the crate location stays consistently fixed at native/hub across the whole project. To match that existing cross-platform assumption, the hook does not introduce a configurable crate-path override. Instead it derives the consuming app root and resolves native/hub from there.
This also updates the package/toolchain floor to the first viable Native Assets generation and adds rust-toolchain.toml scaffolding for the hub crate template/example so the Rust hook build has a stable toolchain definition. The example app and template were adjusted only as needed to validate the Apple Native Assets path.
Before Committing
Done ✅