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

Compile with dart2js and dart2wasm #3737

Merged
merged 14 commits into from
Sep 10, 2024
Merged

Conversation

simolus3
Copy link
Contributor

@simolus3 simolus3 commented Aug 21, 2024

This adds support for compiling with multiple compilers, typically with dart2js and dart2wasm. The updated readme explains how this works, but this essentially boils down to:

targets:
  $default:
    builders:
      build_web_compilers:entrypoint:
        options:
          compilers:
            dart2js:
              args:
                - O2
            dart2wasm:
              args:
                - O3

This doesn't change the defaults yet, we continue to use ddc for dev builds and dart2js for release builds.

Closes #3730.

@pattobrien
Copy link

pattobrien commented Aug 21, 2024

Any chance that this work would/could allow for custom entrypoints / preambles, e.g. for node js runtimes?

See: #3652

@simolus3
Copy link
Contributor Author

I agree that we should support custom entrypoints, I'm not sure about the best way to allow that though. I've added a simple template as a builder option in aac8b6a, not sure if that's the best approach though.

Copy link

github-actions bot commented Sep 4, 2024

PR Health

Changelog Entry ✔️
Package Changed Files

Changes to files need to be accounted for in their respective changelogs.

Package publish validation ✔️
Package Version Status
package:build 2.4.2-wip WIP (no publish necessary)
package:build_config 1.1.2-wip WIP (no publish necessary)
package:build_daemon 4.0.3-wip WIP (no publish necessary)
package:build_modules 5.0.10-wip WIP (no publish necessary)
package:build_resolvers 2.4.3-wip WIP (no publish necessary)
package:build_runner 2.4.13-wip WIP (no publish necessary)
package:build_runner_core 7.3.3-wip WIP (no publish necessary)
package:build_test 2.2.3-wip WIP (no publish necessary)
package:build_web_compilers 4.1.0-wip WIP (no publish necessary)
package:scratch_space 1.0.3-wip WIP (no publish necessary)

Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automation.

build_web_compilers/build.yaml Outdated Show resolved Hide resolved
build_web_compilers/lib/src/dart2js_bootstrap.dart Outdated Show resolved Hide resolved
build_web_compilers/lib/src/loader.js Outdated Show resolved Hide resolved
build_web_compilers/lib/src/loader.js Outdated Show resolved Hide resolved
@simolus3 simolus3 marked this pull request as ready for review September 9, 2024 11:59
@kevmoo kevmoo changed the title WIP: Compile with dart2js and dart2wasm Compile with dart2js and dart2wasm Sep 9, 2024
```sh
webdev serve -- '--define=build_web_compilers:ddc=environment={"SOME_VAR":"changed"}'
```
Note that the `compiler` option takes precedence over the new `compilers` and
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably make this an error during option parsing

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 readme is outdated now, I've changed it so that compilers takes precedence.

This is a bit unfortunate, but we can't make this an error because the keys from the user's build.yaml are merged with the defaults in build_web_compilers - so we can't assume that something's off just because both are set.
The current approach is to use the existing compiler option in the defaults (so that compilers never appears in the map unless explicitly enabled) and then have compilers take precedence.

I wonder if we should unify these into a single option, where compiler is either a string (old) or a map (new)? That makes it harder to be in an ambiguous state.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think how you have it is fine. The plural reads nicer now that multiple can be configured, and it is a cleaner break.

@jakemac53
Copy link
Contributor

@simolus3 let me know when this is ready to merge from your perspective and I will push the button!

@simolus3
Copy link
Contributor Author

simolus3 commented Sep 10, 2024

This is ready from my side 👍

@kevmoo kevmoo merged commit 49d83f4 into dart-lang:master Sep 10, 2024
76 checks passed
@kevmoo
Copy link
Member

kevmoo commented Sep 10, 2024

I couldn't wait!
Thanks SO MUCH!

@simolus3 simolus3 deleted the multi-compilation branch September 10, 2024 22:06
@kevmoo
Copy link
Member

kevmoo commented Sep 10, 2024

Gah! I shouldn't have merged before trying it

  1. There is a cast error w/ Yaml I'm hitting. I have a fix.
  2. Loading JS fails in Safari with (wasm loads fine in Chrome and Safari Tech preview)
[Error] Unhandled Promise Rejection: ReferenceError: Can't find variable: joinPathSegments
	resolveUrlWithSegments (main.dart.js:3)
	(anonymous function) (main.dart.js:25)
	(anonymous function) (main.dart.js:1)
	Global Code (main.dart.js:29)

@kevmoo
Copy link
Member

kevmoo commented Sep 10, 2024

See #3746 @simolus3 !

@kevmoo
Copy link
Member

kevmoo commented Sep 10, 2024

Also #3747 @simolus3

@kevmoo
Copy link
Member

kevmoo commented Sep 10, 2024

We're close!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multi compiler support in dart_web_compilers
5 participants