[dart2wasm] Add runner script to streamline running wasm in d8.

Change-Id: I0f891d28419d0df55f94e0229ff33e87b791e7d0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/273280
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Commit-Queue: Joshua Litt <joshualitt@google.com>
This commit is contained in:
Joshua Litt 2022-12-02 19:55:16 +00:00 committed by Commit Queue
parent 72c5a1a900
commit b493cdfc1b
2 changed files with 45 additions and 1 deletions

View file

@ -8,11 +8,15 @@
//
// $> d8 --experimental-wasm-gc --experimental-wasm-stack-switching --experimental-wasm-type-reflection run_wasm.js -- <dart_module>.wasm [<ffi_module>.wasm]
//
// Or with the `run_dart2wasm_d8` helper script:
//
// $> sdk/bin/run_dart2wasm_d8 <dart_module>.wasm [<ffi_module>.wasm]
//
// If an FFI module is specified, it will be instantiated first, and its
// exports will be supplied as imports to the Dart module under the 'ffi'
// module name.
// We would like this itself to be a ES module rather than a script, but
// We would like this itself to be a ES module rather than a script, but
// unfortunately d8 does not return a failed error code if an unhandled
// exception occurs asynchronously in an ES module.
const main = async () => {

40
sdk/bin/run_dart2wasm_d8 Executable file
View file

@ -0,0 +1,40 @@
#!/usr/bin/env bash
# Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.
# Run the output of dart2wasm on d8.
function follow_links() {
file="$1"
while [ -h "$file" ]; do
# On Mac OS, readlink -f doesn't work.
file="$(readlink "$file")"
done
echo "$file"
}
# Unlike $0, $BASH_SOURCE points to the absolute path of this file.
PROG_NAME="$(follow_links "$BASH_SOURCE")"
# Handle the case where dart-sdk/bin has been symlinked to.
PROG_DIR="$(cd "${PROG_NAME%/*}" ; pwd -P)"
SDK_DIR="$(cd "${PROG_DIR}/../.." ; pwd -P)"
D8_DIR="$(cd "${PROG_DIR}/../../third_party/d8" ; pwd -P)"
# Locate D8 executable. Only macos and linux are supported.
if [[ `uname` == 'Darwin' ]]; then
D8_EXEC="$D8_DIR/macos/d8"
else
D8_EXEC="$D8_DIR/linux/d8"
fi
# We allow extra d8 options to be passed in through an environment variable.
if [[ $D8_OPTIONS ]]; then
read -a OPTIONS <<< "$D8_OPTIONS"
EXTRA_D8_OPTIONS+=("${OPTIONS[@]}")
fi
exec "$D8_EXEC" --experimental-wasm-gc --experimental-wasm-stack-switching \
--experimental-wasm-type-reflection "${EXTRA_D8_OPTIONS[@]}" \
pkg/dart2wasm/bin/run_wasm.js -- "$@"