dart2wasm: Prepare standalone target
When compiled to WebAssembly, the Dart SDK needs access to external host functions to implement regular expressions, stack traces, timers and more. Currently, `dart2wasm` relies on `js_interop` definition to implement these functions in JavaScript. As discussed in https://github.com/dart-lang/sdk/issues/53884, an alternative is to use `wasm:import` annotations to let an arbitrary embedder that doesn't necessarily run in a JavaScript context inject implementations for these host functions. This would allow running `dart2wasm` apps by e.g. - using a runtime like wasmtime and defining host functions in Rust. - defining a wrapper module implementing required functions by delegating to WASI definitions, and then using say `wasm-merge` to run the app in any WASI-compatible runtime. This prepares the `--standalone` flag on `dart2wasm` to do just that. When enabled, the compiler uses a different SDK platform to use imports instead of JS interop. For now, these platforms are almost identical: I've ported the timer logic to use wasm imports as a demo, but the rest is still based on existing patch files. We can revisit in subsequent CLs to incrementally reduce `js_interop` dependencies before removing that library from the `dart2wasm_standalone` target entirely. Change-Id: I3f406afbf2dab65506094de5c3f4067f4db66f3e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/486380 Reviewed-by: Slava Egorov <vegorov@google.com> Reviewed-by: Martin Kustermann <kustermann@google.com> Commit-Queue: Martin Kustermann <kustermann@google.com>
This commit is contained in:
committed by
Commit Queue
parent
bf200e436e
commit
b4cfeb1093
@@ -75,6 +75,22 @@ compile_platform("compile_dart2wasm_js_compatibility_platform") {
|
||||
]
|
||||
}
|
||||
|
||||
compile_platform("compile_dart2wasm_standalone_platform") {
|
||||
single_root_scheme = "org-dartlang-sdk"
|
||||
single_root_base = rebase_path("$sdk_root/")
|
||||
libraries_specification_uri = "org-dartlang-sdk:///lib/libraries.json"
|
||||
|
||||
outputs = [
|
||||
"$root_out_dir/dart2wasm_standalone_platform.dill",
|
||||
"$root_out_dir/dart2wasm_standalone_outline.dill",
|
||||
]
|
||||
|
||||
args = [
|
||||
"--target=dart2wasm_standalone",
|
||||
"dart:core",
|
||||
]
|
||||
}
|
||||
|
||||
wasm_module("ffi_native_test_wasm_module") {
|
||||
module_name = "ffi_native_test_module"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user