Skip to content

Commit b82fc0b

Browse files
authored
Experimental wasm support (#1777)
- Adds the experimental platform `experimental-chrome-wasm`. This requires chrome beta and a very recent SDK to run. - This platform will be deleted eventually, and replaced with a [--compiler](#1776) flag. - Adds `wasm` to the boolean selector variables, and an `isWasm` field to `Runtime` (defaults to false, so should be non-breaking). Note that the integration test for this will initially be failing, as there is one more change needed from the SDK, but once that lands we can update this to point at the new location for the wasm runtime, update the min SDK, re-run the tests, and land.
1 parent 262bc7b commit b82fc0b

28 files changed

+941
-198
lines changed

.github/workflows/dart.yml

+157-51
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integration_tests/wasm/dart_test.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
platforms: [experimental-chrome-wasm]

integration_tests/wasm/mono_pkg.yaml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# See https://pub.dev/packages/mono_repo
2+
3+
sdk:
4+
- main
5+
6+
stages:
7+
- analyze_and_format:
8+
- group:
9+
- format
10+
- analyze: --fatal-infos
11+
- unit_test:
12+
- group:
13+
- command:
14+
- pushd /tmp
15+
- wget https://dl.google.com/linux/direct/google-chrome-beta_current_amd64.deb
16+
- sudo dpkg -i google-chrome-beta_current_amd64.deb
17+
- popd
18+
- which google-chrome-beta
19+
os:
20+
- linux
21+
- test:
22+
os:
23+
- linux

integration_tests/wasm/pubspec.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: wasm_tests
2+
environment:
3+
sdk: ">=2.18.0 <3.0.0"
4+
dev_dependencies:
5+
test: any
6+
dependency_overrides:
7+
test:
8+
path: ../../pkgs/test
9+
test_api:
10+
path: ../../pkgs/test_api
11+
test_core:
12+
path: ../../pkgs/test_core
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
@TestOn('wasm')
5+
import 'package:test/test.dart';
6+
7+
void main() {
8+
test('1 == 1', () {
9+
expect(1, equals(1));
10+
});
11+
}

pkgs/test/CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 1.22.0-dev
2+
3+
* Add the `experimental-chrome-wasm` platform. This is very unstable and will
4+
eventually be deleted, to be replaced by a `--compiler` flag. See
5+
https://github.com/dart-lang/test/issues/1776 for more information on future
6+
plans.
7+
18
## 1.21.7
29

310
* Support `package:matcher` version `0.12.13`.

pkgs/test/lib/src/executable.dart

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'package:test_core/src/runner/hack_register_platform.dart'; // ignore: im
99

1010
import 'runner/browser/platform.dart';
1111
import 'runner/node/platform.dart';
12+
import 'runner/wasm/platform.dart';
1213

1314
void main(List<String> args) async {
1415
registerPlatformPlugin([Runtime.nodeJS], () => NodePlatform());
@@ -18,6 +19,9 @@ void main(List<String> args) async {
1819
Runtime.safari,
1920
Runtime.internetExplorer
2021
], () => BrowserPlatform.start());
22+
registerPlatformPlugin([
23+
Runtime.experimentalChromeWasm,
24+
], () => BrowserWasmPlatform.start());
2125

2226
await executable.main(args);
2327
}

pkgs/test/lib/src/runner/browser/browser_manager.dart

+1
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ class BrowserManager {
155155
ExecutableSettings settings, Configuration configuration) {
156156
switch (browser.root) {
157157
case Runtime.chrome:
158+
case Runtime.experimentalChromeWasm:
158159
return Chrome(url, configuration, settings: settings);
159160
case Runtime.firefox:
160161
return Firefox(url, settings: settings);

pkgs/test/lib/src/runner/browser/dom.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ extension WindowExtension on Window {
2121
void postMessage(Object message, String targetOrigin,
2222
[List<MessagePort>? messagePorts]) =>
2323
js_util.callMethod(this, 'postMessage', <Object?>[
24-
message,
24+
js_util.jsify(message),
2525
targetOrigin,
2626
if (messagePorts != null) js_util.jsify(messagePorts)
2727
]);

pkgs/test/lib/src/runner/browser/platform.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import 'package:shelf_web_socket/shelf_web_socket.dart';
1818
// ignore: deprecated_member_use
1919
import 'package:test_api/backend.dart'
2020
show Runtime, StackTraceMapper, SuitePlatform;
21-
import 'package:test_core/src/runner/compiler_pool.dart'; // ignore: implementation_imports
2221
import 'package:test_core/src/runner/configuration.dart'; // ignore: implementation_imports
22+
import 'package:test_core/src/runner/dart2js_compiler_pool.dart'; // ignore: implementation_imports
2323
import 'package:test_core/src/runner/load_exception.dart'; // ignore: implementation_imports
2424
import 'package:test_core/src/runner/package_version.dart'; // ignore: implementation_imports
2525
import 'package:test_core/src/runner/platform.dart'; // ignore: implementation_imports
@@ -85,8 +85,8 @@ class BrowserPlatform extends PlatformPlugin
8585
/// A [PathHandler] used to serve compiled JS.
8686
final _jsHandler = PathHandler();
8787

88-
/// The [CompilerPool] managing active instances of `dart2js`.
89-
final _compilers = CompilerPool();
88+
/// The [Dart2JsCompilerPool] managing active instances of `dart2js`.
89+
final _compilers = Dart2JsCompilerPool();
9090

9191
/// The temporary directory in which compiled JS is emitted.
9292
final String? _compiledDir;

pkgs/test/lib/src/runner/node/platform.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import 'package:stream_channel/stream_channel.dart';
1515
import 'package:test_api/backend.dart'
1616
show Runtime, StackTraceMapper, SuitePlatform;
1717
import 'package:test_core/src/runner/application_exception.dart'; // ignore: implementation_imports
18-
import 'package:test_core/src/runner/compiler_pool.dart'; // ignore: implementation_imports
1918
import 'package:test_core/src/runner/configuration.dart'; // ignore: implementation_imports
19+
import 'package:test_core/src/runner/dart2js_compiler_pool.dart'; // ignore: implementation_imports
2020
import 'package:test_core/src/runner/load_exception.dart'; // ignore: implementation_imports
2121
import 'package:test_core/src/runner/package_version.dart'; // ignore: implementation_imports
2222
import 'package:test_core/src/runner/platform.dart'; // ignore: implementation_imports
@@ -41,8 +41,8 @@ class NodePlatform extends PlatformPlugin
4141
/// The test runner configuration.
4242
final Configuration _config;
4343

44-
/// The [CompilerPool] managing active instances of `dart2js`.
45-
final _compilers = CompilerPool(['-Dnode=true', '--server-mode']);
44+
/// The [Dart2JsCompilerPool] managing active instances of `dart2js`.
45+
final _compilers = Dart2JsCompilerPool(['-Dnode=true', '--server-mode']);
4646

4747
/// The temporary directory in which compiled JS is emitted.
4848
final _compiledDir = createTempDir();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'dart:collection';
6+
7+
import 'package:test_api/src/backend/runtime.dart'; // ignore: implementation_imports
8+
import '../executable_settings.dart';
9+
10+
/// Default settings for starting browser executables with the wasm runtime.
11+
final defaultSettings = UnmodifiableMapView({
12+
Runtime.experimentalChromeWasm: ExecutableSettings(
13+
linuxExecutable: 'google-chrome-beta',
14+
macOSExecutable: null,
15+
windowsExecutable: null,
16+
arguments: [
17+
'--js-flags=--experimental-wasm-gc --wasm-gc-js-interop '
18+
'--experimental-wasm-stack-switching '
19+
'--experimental-wasm-type-reflection'
20+
]),
21+
});

0 commit comments

Comments
 (0)