fzyzcjy / flutter_rust_bridge

Flutter/Dart <-> Rust binding generator, feature-rich, but seamless and simple.
https://fzyzcjy.github.io/flutter_rust_bridge/
MIT License
4.29k stars 301 forks source link

Allow `flutter_rust_bridge_codegen` to use `fvm flutter` #2300

Closed BriceCroix closed 2 weeks ago

BriceCroix commented 2 months ago

Hi, first of all thank you all for this awesome project.

I would like to know if it is possible to use flutter_rust_bridge_codegen utility with fvm flutter. I do not have the regular flutter command on my computer and do not wish to install it. If you do not know FVM it is an elegant solution to manage the flutter version used by each specific project, here is its main website.

As of now, the executable exits with the following error message :

+ & "flutter" "pub" "add" "rust_lib_myproject" "--path=rust_builder"
+   ~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (flutter:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

I could not find any information about fvm in the documentation of this repository but perhaps I did not look at the right place.

If this is not possible right now, I think it would be great to add something like a --use-fvm or --flutter-path /path/to/fvm/flutter option to the codegen call.

Thanks a lot for your time !

welcome[bot] commented 2 months ago

Hi! Thanks for opening your first issue here! :smile:

fzyzcjy commented 2 months ago

Looks reasonable and feel free to PR (since this does not look very hard)! Alternatively I may work on it later.

We may need to determine how to know whether to use fvm or normal flutter binary. One way may be, try to see whether fvm exists (maybe execute fvm --help and see return code is zero or nonzero), and if exists use it, otherwise do not use it.

Btw, we may also handle fvm dart (instead of dart) as well.

I guess code change may be near https://github.com/fzyzcjy/flutter_rust_bridge/blob/17fdf93e375d30969ddb31d88b26de6f7f5a6d65/frb_codegen/src/library/utils/dart_repository/dart_toolchain.rs#L36

BriceCroix commented 2 months ago

Thanks for looking into this ! I think the best way to determine if flutter must be used from global install or from fvm is to look for a .fvmrc file in the project directory.

Alternatively before its version 3.0, fvm used to get its configuration from the .fvm/fvm_config.json project file. One may also look for this file.

I agree that supporting pure fvm dart would also be great, I will look into how fvm configures itself in that case.

fzyzcjy commented 2 months ago

I think the best way to determine if flutter must be used from global install or from fvm is to look for a .fvmrc file in the project directory.

Looks reasonable! Sometimes .fvm directory is from parent folder, so we may need to recursively check as well.

Alternatively before its version 3.0

Looks like we only need to support latest fvm and no worries about old versions

patmuk commented 1 month ago

@BriceCroix, if you can't wait for the fix, why don't you create an alias so that flutter calls fvm flutter, as described in https://fvm.app/documentation/guides/running-flutter#call-sdk-directly ?

Alternatively I can recommend using nix flake. I use it in my project.

BriceCroix commented 1 month ago

@BriceCroix, if you can't wait for the fix, why don't you create an alias so that flutter calls fvm flutter, as described in https://fvm.app/documentation/guides/running-flutter#call-sdk-directly ?

Alternatively I can recommend using nix flake. I use it in my project.

Yes I ended up adding fvm's internal directories to my path so that flutter is found, this is a nice workaround but I still think calling the version of flutter required by a specific project through the .fvmrc would be a great feature.

I started to look into but but hadn't had much time to come up with something

patmuk commented 1 month ago

Yes I ended up adding fvm's internal directories to my path so that flutter is found, this is a nice workaround but I still think calling the version of flutter required by a specific project through the .fvmrc would be a great feature.

Ah, great :) Hmm, I understood that this is solved as well, that

sudo echo 'fvm flutter ${@:1}' > "/usr/local/bin/flutter" && sudo chmod +x /usr/local/bin/flutter

is binding the command flutter to fvm flutter - and thus fvm takes care to take the flutter version specified in the project.

github-actions[bot] commented 3 days ago

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new issue.