dart-lang / build

A build system for Dart written in Dart
https://pub.dev/packages/build
BSD 3-Clause "New" or "Revised" License
791 stars 211 forks source link

Compile with dart2js and dart2wasm #3737

Closed simolus3 closed 2 months ago

simolus3 commented 3 months ago

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 https://github.com/dart-lang/build/issues/3730.

pattobrien commented 3 months ago

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

See: https://github.com/dart-lang/build/issues/3652

simolus3 commented 3 months ago

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 aac8b6a7d6ad333799d21f7144e0648c295d020b, not sure if that's the best approach though.

github-actions[bot] commented 2 months ago

PR Health

Changelog Entry :heavy_check_mark: | Package | Changed Files | | :--- | :--- | Changes to files need to be [accounted for](https://github.com/dart-lang/ecosystem/wiki/Changelog) in their respective changelogs.
Package publish validation :heavy_check_mark: | 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.
jakemac53 commented 2 months ago

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

simolus3 commented 2 months ago

This is ready from my side :+1:

kevmoo commented 2 months ago

I couldn't wait! Thanks SO MUCH!

kevmoo commented 2 months ago

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 commented 2 months ago

See https://github.com/dart-lang/build/issues/3746 @simolus3 !

kevmoo commented 2 months ago

Also https://github.com/dart-lang/build/issues/3747 @simolus3

kevmoo commented 2 months ago

We're close!!!