[dart2wasm] Have binaryen/wasm-opt flags in one place (dart compile exe), make all other places take it from there

Golem build configuration is setup in a way that includes the `pkg/`
folder entirely, so the shell scripts should have access to the
`dart compile exe` sources.

Change-Id: I5395413ce85f11098d14eacbd6ce392f665ddce5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/347021
Reviewed-by: Slava Egorov <vegorov@google.com>
This commit is contained in:
Martin Kustermann
2024-01-19 07:47:52 +00:00
parent e5f53ce005
commit 1d92908169
3 changed files with 39 additions and 8 deletions
+4 -1
View File
@@ -30,6 +30,9 @@ PROG_NAME="$(follow_links "$BASH_SOURCE")"
PROG_DIR="$(cd "${PROG_NAME%/*}" ; pwd -P)"
SDK_DIR="$(cd "${PROG_DIR}/../../.." ; pwd -P)"
# Use same binaryen flags as `dart compile exe`
BINARYEN_FLAGS="$(sed -n '/binaryenFlags =/,/end of binaryenFlags/ p' $SDK_DIR/pkg/dartdev/lib/src/commands/compile.dart | sed '1d' | sed '$d' | tr '\n' ' ')"
# Locate build directory, containing executables, snapshots and platform dill.
if [[ `uname` == 'Darwin' ]]; then
OUT_DIR="$SDK_DIR/xcodebuild"
@@ -62,7 +65,7 @@ function measure_size() {
dart2wasm_command=("$DART2WASM" "$1" "$2" $COMPILE_FLAGS)
# Keep in sync with sdk/bin/dart2wasm.
binaryen_command=("$BINARYEN" -all --closed-world -tnh --type-unfinalizing -O3 --type-ssa --gufa -O3 --type-merging -O1 --type-finalizing "$2" -o "$2")
binaryen_command=("$BINARYEN" $BINARYEN_FLAGS "$2" -o "$2")
if [ -n "$COMPILE_BENCHMARK_BASE_NAME" ]; then
measure ${dart2wasm_command[@]}
+30 -4
View File
@@ -21,6 +21,28 @@ import '../sdk.dart';
import '../utils.dart';
import '../vm_interop_handler.dart';
// The unique place where we store dart2wasm binaryen flags.
//
// Other uses (e.g. in shell scripts) will grep in this file for the flags. So
// please keep it as a simple multi-line string of flags.
final List<String> binaryenFlags = '''
--all-features
--closed-world
--traps-never-happen
--type-unfinalizing
-O3
--type-ssa
--gufa
-O3
--type-merging
-O1
--type-finalizing
''' // end of binaryenFlags
.split('\n')
.map((line) => line.trim())
.where((line) => line.isNotEmpty)
.toList();
const int compileErrorExitCode = 64;
class Option {
@@ -394,10 +416,14 @@ class CompileWasmCommand extends CompileSubcommandCommand {
final String optimizer = path.join(
binDir.path, 'utils', Platform.isWindows ? 'wasm-opt.exe' : 'wasm-opt');
String optimizerFlags(bool outputNames) =>
'-all --closed-world -tnh --type-unfinalizing -O3 --type-ssa'
' --gufa -O3 --type-merging -O1 --type-finalizing'
'${outputNames ? ' -g' : ''}';
String optimizerFlags(bool outputNames) {
final flags = [
...binaryenFlags,
if (outputNames) '-g',
];
return flags.join(' ');
}
static const String unoptExtension = '.unopt';
CompileWasmCommand({bool verbose = false})
+5 -3
View File
@@ -24,6 +24,9 @@ PROG_NAME="$(follow_links "$BASH_SOURCE")"
PROG_DIR="$(cd "${PROG_NAME%/*}" ; pwd -P)"
SDK_DIR="$(cd "${PROG_DIR}/../.." ; pwd -P)"
# Use same binaryen flags as `dart compile exe`
BINARYEN_FLAGS="$(sed -n '/binaryenFlags =/,/end of binaryenFlags/ p' $SDK_DIR/pkg/dartdev/lib/src/commands/compile.dart | sed '1d' | sed '$d' | tr '\n' ' ')"
# Locate build directory, containing executables, snapshots and platform dill.
if [[ `uname` == 'Darwin' ]]; then
OUT_DIR="$SDK_DIR/xcodebuild"
@@ -127,7 +130,6 @@ set -e
"$DART_PRECOMPILED_RUNTIME" "--packages=$DART_ROOT/.packages" "${EXTRA_VM_OPTIONS[@]}" "$SNAPSHOT" "$SDK_ARG" "$PLATFORM_ARG" "${ARGS[@]}"
if [[ "$OPTIMIZED" == 1 ]]; then
# Keep optimization parameters after `-g` in sync with pkg/dart2wasm/tool/compile_benchmark.
# Last argument must be the .wasm file.
"$BIN_DIR"/wasm-opt -g -all --closed-world -tnh --type-unfinalizing -O3 --type-ssa --gufa -O3 --type-merging -O1 --type-finalizing "${ARGS[-1]}" -o "${ARGS[-1]}"
# Keep the name section by passing `-g`.
"$BIN_DIR"/wasm-opt -g $BINARYEN_FLAGS "${ARGS[-1]}" -o "${ARGS[-1]}"
fi