irondash / cargokit

Integrate cargo build with flutter plugins and applications.
Other
51 stars 16 forks source link

Precompiled builds #68

Open vhdirk opened 1 month ago

vhdirk commented 1 month ago

First off, congrats and thanks for this project :clap: .

I know this (the title) is probably orthogonal to your project, but I was hoping to get in touch since rust+flutter is really rather new. For a parser library I'm creating, I wanted to make dart/flutter bindings: https://github.com/vhdirk/dash7-rs/pull/33:

The project was generated with flutter_rust_bridge and then modified a bit to try and make the 'magic' aspect of it a little less hidden. One of my goals is to not require the users of this library (me :) ) to have a working rust toolchain. Rather, I'd like to make builds available on pub, so that I can just use the package as if it where a regular dart/flutter package.

As far as I can tell, there seem to be 2 ways to do this:

For simplicity (from front-end developer POV), I wanted to try out native assets. It seems rather logical that the binaries would be shipped with the package itself. I came across your other project https://github.com/irondash/native_toolchain_rust. I think this is a (albeit very experimental) way to bundle rust libs with a dart/flutter package.

Seeing how iOS is currently still missing from native_toolchain_rust, and me not knowing the tiniest bit about building for iOS in the first place, I was thinking:

Do you think it possible to trigger cargokit from hooks/build.dart, as such that it would then provide (and tell flutter/dart build about) the binaries? Since native_toolchain_cli provides the utilities to specify binaries per platform, I would guess that it shouldn't be that hard.

Which is why I started from the example here: https://github.com/dart-lang/native/blob/main/pkgs/native_assets_cli/example/build/local_asset/hook/build.dart. I am assuming the file asset.txt should end up in build/flutter_assets and referenced in AssetManifest.json , when running flutter build bundle (without arguments).

Is this correct at all? Am I on the right track here?

If you could share some of your wisdom (or point me to a place where I should look instead), I would be very grateful!

knopp commented 1 month ago

Hi,

what do you mean by ios missing from native_toolchain_rust? The iOS support should be all there. Cargokit is basically a hack that was necessary before native assets, and I plan to retire it as soon as possible because it's essentially holds together with duck tape. native_toolchain_rust is the way to go. Though it currently needs flutter main and an experimental flag.

One thing cargokit has that native_toolchain_rust doesn't is support for precompiled binaries, but long term I'd prefer to rely on native_doctor to setup user environment instead of shipping binary blobs.

vhdirk commented 1 month ago

Interesting!

The iOS support should be all there.

Then obviously I was wrong :). The thing that made me jump to that conclusion is the presence of https://github.com/irondash/cargokit/blob/main/build_tool/lib/src/build_pod.dart in cargokit. But as said, my experience with building for iOS is extremely limited.

One thing cargokit has that native_toolchain_rust doesn't is support for precompiled binaries

What do you mean by this? Now I'm confused; I thought the whole point was to compile the binaries 'here' to begin with?

Is flutter main needed only for building the package? or also for consuming?

I will post any further questions on the native_toolchain_rust repo instead.

vhdirk commented 1 month ago

After reading the proposal for native_assets again, I realize I had it all wrong, apparently. My goal of bundling the shared library with the package seems really not what that is all intended for?

If so, I guess I need to go about it in another way: build the native bits with cargokit, place them somewhere so that they get picked up by pub publish, and then use native_assets_cli to hand them over to the app that is being built. Does that sound about right?