Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build hook for Flutter Web? #138992

Closed
2 tasks done
fzyzcjy opened this issue Nov 25, 2023 · 10 comments
Closed
2 tasks done

Build hook for Flutter Web? #138992

fzyzcjy opened this issue Nov 25, 2023 · 10 comments
Labels
c: new feature Nothing broken; request for a new capability c: proposal A detailed proposal for a change to Flutter r: solved Issue is closed as solved team-tool Owned by Flutter Tool team tool Affects the "flutter" command-line tool. See also t: labels.

Comments

@fzyzcjy
Copy link
Contributor

fzyzcjy commented Nov 25, 2023

Is there an existing issue for this?

Use case

Hi thanks for the great framework! When developing https://github.com/fzyzcjy/flutter_rust_bridge v2, we are having the following scenario: We need to compile some Rust code into WASM, which is used by Flutter code.

For the native platforms, the build can be invoked easily. For example, in Android, we can just modify the build.gradle and let it invoke the build commands; similar for iOS, windows, macos, linux. However, IMHO there is no place to inject such "hooks" when building.

Surely, we can just create another tool that wraps the "build rust + call flutter run" process (that's what we are doing currently) - but that looks suboptimal.

I guess it is somehow related to the native assets dart-lang/sdk#50565 / #129757, but this is just a (small) part of what native asset system is going to cover, and seems to be also possibly orthogonal (e.g. today's Android/iOS/... build hook can be implemented, but without native assets), so I make a separate issue here.

Proposal

(see above)

@jonahwilliams
Copy link
Member

Surely, we can just create another tool that wraps the "build rust + call flutter run" process (that's what we are doing currently) - but that looks suboptimal.

Why? This could be as cheap as flutter build web && ./your_tool

@fzyzcjy
Copy link
Contributor Author

fzyzcjy commented Nov 25, 2023

@jonahwilliams Thanks for the good question! There may be some cases, for example:

  • If someone wants to publish a pub.dev package with native (say Rust) code, it is not very great to require every user of the package to execute this extra tool when they want to run their app
  • People may not be using flutter run -p chrome / flutter build web, but use VSCode / Intellij IDEA / other tools. For example, suppose one clicks the "run" button in Intellij IDEA. In that case, to ensure the extra Rust compilation happens, it is not super trivial.
  • In the 5 native platforms (android/ios/...), there already exists build hook. Flutter aims uniform experience across platforms, so why not for web ;)

Personally speaking, I want to make V2 of https://github.com/fzyzcjy/flutter_rust_bridge as convenient to use as possible.

@danagbemava-nc danagbemava-nc added in triage Presently being triaged by the triage team c: new feature Nothing broken; request for a new capability tool Affects the "flutter" command-line tool. See also t: labels. platform-web Web applications specifically c: proposal A detailed proposal for a change to Flutter team-web Owned by Web platform team and removed in triage Presently being triaged by the triage team labels Nov 27, 2023
@harryfei
Copy link

We need this

@yjbanov
Copy link
Contributor

yjbanov commented Jan 4, 2024

Flutter's web build tool is pretty simple. It knows how to build the Flutter bits, but it has no opinion about how to build anything other than Flutter. Unlike the Android toolchain, which includes gradle, our web tools do not include any fancy build systems, like NPM, WebPack, etc. If you need to combine Flutter Web with non-Flutter code, I think the best place to put that functionality is above Flutter, rather than inside it. For example, you could use make or bazel to call into flutter build, but also invoke the Rust tools.

@yjbanov yjbanov added team-tool Owned by Flutter Tool team and removed platform-web Web applications specifically team-web Owned by Web platform team labels Jan 4, 2024
@yjbanov
Copy link
Contributor

yjbanov commented Jan 4, 2024

cc @dcharkes who is working on something related

@dcharkes
Copy link
Contributor

dcharkes commented Jan 4, 2024

Yes, I envision having an asset type "wasm" in the future, which would then be consumed by the flutter tooling. Flutter web should then start invoking build.dart just like we do for flutter mobile/desktop.

I had some discussions with @eyebrowsoffire about this recently. Some notes can be found in:

Some earlier issues filed relevant for this:

Flutter's web build tool is pretty simple. It knows how to build the Flutter bits, but it has no opinion about how to build anything other than Flutter. Unlike the Android toolchain, which includes gradle, our web tools do not include any fancy build systems, like NPM, WebPack, etc. If you need to combine Flutter Web with non-Flutter code, I think the best place to put that functionality is above Flutter, rather than inside it. For example, you could use make or bazel to call into flutter build, but also invoke the Rust tools.

I was having a similar discussion recently with @mosuem in our quest of adding tree-shakable data assets to Dart/Flutter (dart-lang/native#153). The web frameworks on Dart all wrap dart2js or dart2wasm and don't have a full bundle format. So we need to do some exploration on how to address that. (E.g. lazy loading, modules, where are WASM modules hosted etc.)

@fzyzcjy
Copy link
Contributor Author

fzyzcjy commented Jan 4, 2024

Get it, thank you!

@christopherfujino
Copy link
Member

Thank you for filing this. I am going to close this however, as given the work with native assets and yjbanov's point about composing complex web builds with some higher level tool, I don't think we would accept a proposal for ANOTHER way to do this.

@fzyzcjy
Copy link
Contributor Author

fzyzcjy commented Jan 5, 2024

You are welcome, and also thank you all!

Copy link

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 bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
c: new feature Nothing broken; request for a new capability c: proposal A detailed proposal for a change to Flutter r: solved Issue is closed as solved team-tool Owned by Flutter Tool team tool Affects the "flutter" command-line tool. See also t: labels.
Projects
None yet
Development

No branches or pull requests

7 participants