dart-lang/build

Wasm compile crashes as build time

kevmoo opened this issue · 2 comments

At 49d83f4

with this build.yaml

# See https://github.com/dart-lang/build/tree/master/build_web_compilers#configuration
targets:
  $default:
    builders:
      build_web_compilers|dart2js_archive_extractor:
        options:
          filter_outputs: false
      build_web_compilers|entrypoint:
        generate_for:
          - web/**.dart
        options:
          compilers:
            dart2wasm:
              args:
                - -O4
                - --no-strip-wasm
            dart2js:
              args:
                - --dump-info
                - --no-source-maps
                - --show-package-warnings
                - -O4

get this error

type 'YamlMap' is not a subtype of type 'Map<String, Object?>?' in type cast
dart:_internal                                                      MappedIterator.moveNext
package:build_web_compilers/src/web_entrypoint_builder.dart 171:62  new EntrypointBuilderOptions.fromOptions
package:build_web_compilers/src/web_entrypoint_builder.dart 279:58  new WebEntrypointBuilder.fromOptions
package:build_web_compilers/builders.dart 16:26                     webEntrypointBuilder
package:build_runner                                                BuildCommand._run
package:args/command_runner.dart 212:13                             CommandRunner.runCommand
package:build_runner                                                run
.dart_tool/build/entrypoint/build.dart 145:16                       main

CC @jakemac53

Here's a patch with the fix. Of course it'll need a test

diff --git a/build_web_compilers/lib/src/web_entrypoint_builder.dart b/build_web_compilers/lib/src/web_entrypoint_builder.dart
index b3bad5a4..a880d5c6 100644
--- a/build_web_compilers/lib/src/web_entrypoint_builder.dart
+++ b/build_web_compilers/lib/src/web_entrypoint_builder.dart
@@ -10,6 +10,7 @@ import 'package:build/build.dart';
 import 'package:build_modules/build_modules.dart';
 import 'package:collection/collection.dart';
 import 'package:path/path.dart' as p;
+import 'package:yaml/yaml.dart';
 
 import 'common.dart';
 import 'dart2js_bootstrap.dart';
@@ -163,17 +164,17 @@ final class EntrypointBuilderOptions {
     // dart2js + dart2wasm). Since the default builder configuration doesn't
     // use the compilers key, we preserve backwards compatibility.
     if (config.containsKey(compilersOption)) {
-      var configuredCompilers = (config[compilersOption] as Map?)
-              ?.cast<String, Map<String, Object?>?>() ??
-          const {};
+      var configuredCompilers =
+          (config[compilersOption] as YamlMap?)?.cast<String, YamlMap?>() ??
+              const {};
       var hasDart2Wasm = false;
 
       for (var MapEntry(:key, :value) in configuredCompilers.entries) {
         const extensionOption = 'extension';
         const argsOption = 'args';
         const supportedOptions = [extensionOption, argsOption];
-        validateOptions(value ?? const {}, supportedOptions,
-            'build_web_compilers:entrypoint');
+        validateOptions(Map<String, dynamic>.from(value ?? const {}),
+            supportedOptions, 'build_web_compilers:entrypoint');
 
         var compiler = WebCompiler.fromOptionName(key);
         compilers.add(EnabledEntrypointCompiler(

I can open a PR with that patch and a fix for the Safari issue with tests.