Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Build Web SDK in wasm build tree #36520

Merged
merged 19 commits into from
Oct 14, 2022
Merged

Conversation

eyebrowsoffire
Copy link
Contributor

@eyebrowsoffire eyebrowsoffire commented Sep 30, 2022

This makes some improvements to the web build process.

  • felt test no longer requires any build folder at all, unless --use-local-canvaskit is specified. To compile tests, it now uses whatever dart sdk that felt.dart is invoked with (which is by default the prebuilt dart sdk)
  • felt build only invokes the --wasm --runtime-mode=release of the gn build, and that build now produces the flutter_web_sdk and the .zip artifact. This build also no longer relies on building or copying the dart sdk to the output folder, it just uses the prebuilt sdk where it is.
  • We don't produce a random unused xcodeproj in the wasm build anymore

We need to do some followup recipe changes to take full advantage of this, which I've outlined here: flutter/flutter#113303

The ultimate goal is going to be:

  1. The engine build produces a single flutter-web-sdk.zip artifact that rolls into the framework, and no longer has platform specific artifacts.
  2. The flutter tool consumes the flutter-web-sdk.zip artifact instead of the platform specific artifacts
  3. The host build no longer builds the flutter_web_sdk targets at all
  4. We don't do host builds at all to do any web engine CI stuff.

@eyebrowsoffire eyebrowsoffire added the Work in progress (WIP) Not ready (yet) for review! label Sep 30, 2022
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@flutter-dashboard flutter-dashboard bot added platform-web Code specifically for the web engine needs tests labels Sep 30, 2022
}
print('Running gn...');
const List<String> gnArgs = <String>[
'--wasm',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that this target is going to be used for all of flutter web (not just for wasm), does it make sense to change the name to flutter_web or similar?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there was some extensive discussion about this with the rest of the engine team, I'd like to ask @hterkelsen what their concerns were and why they landed on this. In any case, the --wasm can't be immediately deleted because the recipes use it, but if we are going to migrate to some different flag I should at least add it as an option here so the recipes can switch to it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My concern with using --wasm to mean "build the Flutter Web SDK" is that the Flutter Web SDK bits aren't WASM (for now, anyway). The fact that we can invoke kernel compiler when using the WASM toolchain seems to just be a lucky coincidence. I think we should have a --web flag in GN which sets the default CPU to WASM and builds CanvasKit and the Flutter Web SDK.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. I think I get what you're going for. Let me make some changes and see what I can do.

@eyebrowsoffire eyebrowsoffire added autosubmit Merge PR when tree becomes green via auto submit App and removed Work in progress (WIP) Not ready (yet) for review! labels Oct 14, 2022
@auto-submit auto-submit bot merged commit 7a1be8b into flutter:main Oct 14, 2022
Copy link
Member

@zanderso zanderso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DBC

@@ -0,0 +1,24 @@
import("//flutter/common/config.gni")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file needs a copyright header

Copy link
Member

@zanderso zanderso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More DBC

I'm skeptical that creating the dart_sdk subdirectory that contains only the BUILD.gn file is needed. What's the reasoning behind that?

@@ -12,6 +12,8 @@ import("//third_party/dart/build/dart/copy_tree.gni")

# Whether to build the dartdevc sdk, libraries, and source files
# required for the flutter web sdk.
# TODO(jacksongardner): remove this poorly named argument once the recipes stop
# using it.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please link to a github issue for all TODOs.

@@ -0,0 +1,24 @@
import("//flutter/common/config.gni")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things:

  1. What is the reason for moving this?
  2. GN files need a copyright header.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original reason for moving this was that the flutter/BUILD.gn file is not wasm friendly (it transitively pulls in a bunch of .gni files that have platform checks that choke when the target os/arch is wasm). Since I was trying to build the web sdk in the wasm build, it was pulling in the flutter/BUILD.gn file when it had a dependency on the dart-sdk target, so I separated it out and simplified it so that we wouldn't have to pull in the whole of flutter/BUILD.gn when building the web sdk.

After some additional changes though, the web sdk build now uses the prebuilt sdk in-place and so does not have a dependency on the dart_sdk target anymore, so I can actually move it back if this bothers you.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to allow Dart SDK hackers to test Dart SDK builds with local source changes, so we may end up with this dependency again. If it's better to have it split out into a standalone BUILD.gn I think I'd rather keep it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to allow Dart SDK hackers to test Dart SDK builds with local source changes, so we may end up with this dependency again. If it's better to have it split out into a standalone BUILD.gn I think I'd rather keep it.

I don't follow how that's related. The existing way to hack on the Dart SDK in the engine tree is to make changes under third_party/dart, and to use the --no-prebuilt-dart-sdk flag to the gn script. Does that not work for some reason?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the dart-sdk target is in flutter/BUILD.gn, then the wasm build cannot consume or use it because the wasm build can't actually touch flutter/BUILD.gn without pulling in transitive dependencies that break under a wasm build. The transitive dependencies break even if you aren't building any of their targets, and they are dependencies we don't necessarily have control over.

That being said, we aren't actually using the dart-sdk target for the web build anymore, we just use prebuilts. I also don't actually see us adding a dependency on the dart-sdk target in the future either, and if we did it would be in a different manner that would probably build it with the non-default toolchain, since it's weird to pull host artifacts into the wasm build tree. So actually for our purposes I don't care anymore, and if you want me to refactor that target back into flutter/BUILD.gn I don't have any real practical objection, but I don't actually understand why that would be desirable. flutter/BUILD.gn is a bit of a kitchen sink and probably would be easier to work with if it were broken up into smaller logical components, and so having the dart-sdk separated into a different file seems better to me than keeping it in flutter/BUILD.gn. But again we don't really depend on either any more, so I don't mind either way you want to go with it.

@@ -22,6 +22,8 @@ declare_args() {

# Whether to use a prebuilt Dart SDK instead of building one.
flutter_prebuilt_dart_sdk = false

build_flutter_web_sdk = false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment for this arg.

@@ -627,6 +633,12 @@ def to_gn_wasm_args(args, gn_args):
gn_args['skia_canvaskit_enable_webgpu'] = False
is_profile_build = args.runtime_mode == 'profile' or args.runtime_mode == 'debug'
gn_args['skia_canvaskit_profile_build'] = is_profile_build
gn_args['flutter_prebuilt_dart_sdk'] = True

# TODO(jacksongardner): Make this based off of the input argument rather
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto comment about linking TODOs to github issues.

action='store_true',
help='build canvaskit from source'
)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For other args there's no extra newline between the arg and the --no version.

if (target_os == "wasm") {
output = "flutter-web-sdk.zip"
} else {
# TODO(jacksongardner): remove this once we stop making platform-specific
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

@eyebrowsoffire eyebrowsoffire added revert Label used to revert changes in a closed and merged pull request. and removed revert Label used to revert changes in a closed and merged pull request. labels Oct 17, 2022
eyebrowsoffire added a commit to eyebrowsoffire/engine that referenced this pull request Oct 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
autosubmit Merge PR when tree becomes green via auto submit App needs tests platform-web Code specifically for the web engine
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants