From 1ed2a07022ced97778c2b9bcb83763e37e4d2c50 Mon Sep 17 00:00:00 2001 From: Joshua Litt Date: Wed, 26 Oct 2022 17:04:17 +0000 Subject: [PATCH] [dart2wasm] Build product snapshot when building for the SDK. The `dartaotruntime` is built in `product` mode even when we do a release build. This CL wires up a product flag so we always build the Dart2Wasm product snapshot when creating the SDK. Change-Id: Ic8c6a6da180a47a19ba818d7c449f712c9e60123 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/264887 Reviewed-by: Slava Egorov Commit-Queue: Joshua Litt Reviewed-by: Jake Macdonald --- BUILD.gn | 8 ++++++-- build/dart/dart_action.gni | 13 ++++++++++++- sdk/BUILD.gn | 6 +++--- utils/aot_snapshot.gni | 8 ++++++++ utils/dart2wasm/BUILD.gn | 6 ++++++ 5 files changed, 35 insertions(+), 6 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 168a443bd95..7c8b7328749 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -109,8 +109,12 @@ group("dart2wasm_platform") { "utils/dart2wasm:compile_dart2wasm_platform", "utils/dart2wasm:dart2wasm_snapshot", ] - if (defined(is_product) && !is_product) { - deps += [ "utils/dart2wasm:dart2wasm_asserts_snapshot" ] + if (defined(is_product)) { + if (is_product) { + deps += [ "utils/dart2wasm:dart2wasm_product_snapshot" ] + } else { + deps += [ "utils/dart2wasm:dart2wasm_asserts_snapshot" ] + } } } diff --git a/build/dart/dart_action.gni b/build/dart/dart_action.gni index f1e95596f1e..53472a0fe5a 100644 --- a/build/dart/dart_action.gni +++ b/build/dart/dart_action.gni @@ -347,6 +347,10 @@ template("dart_action") { # packages (optional): # The un-rebased path to the package_config.json file. # +# force_product_mode (optional): +# Setting this to true will cause snapshot to be built in product mode even +# if dart_runtime_mode is not product. +# # Forwarded to action() with the usual meaning: # depfile # deps @@ -355,12 +359,19 @@ template("dart_action") { # testonly # visibility template("gen_snapshot_action") { + product_mode = + (defined(dart_runtime_mode) && dart_runtime_mode == "release") || + (defined(invoker.force_product_mode) && invoker.force_product_mode) assert( !defined(invoker.script), "script must not be defined for $target_name. If there is a script use args instead.") if (!_is_fuchsia || !use_prebuilt_dart_sdk) { _built_tool_action(target_name) { - tool = "$_dart_root/runtime/bin:gen_snapshot" + if (product_mode) { + tool = "$_dart_root/runtime/bin:gen_snapshot_product" + } else { + tool = "$_dart_root/runtime/bin:gen_snapshot" + } forward_variables_from(invoker, [ "args", diff --git a/sdk/BUILD.gn b/sdk/BUILD.gn index 9c7748ee777..33abc7713ed 100644 --- a/sdk/BUILD.gn +++ b/sdk/BUILD.gn @@ -43,7 +43,7 @@ declare_args() { # ......snapshots/ # ........analysis_server.dart.snapshot # ........dart2js.dart.snapshot -# ........dart2wasm.dart.snapshot (if not on ia32) +# ........dart2wasm_product.snapshot (if not on ia32) # ........dartdev.dart.snapshot # ........dartdev.dill # ........dartdevc.dart.snapshot @@ -510,9 +510,9 @@ copy("copy_dart2wasm_snapshot") { visibility = [ ":create_full_sdk" ] deps = [ ":copy_libraries", - "../utils/dart2wasm:dart2wasm_snapshot", + "../utils/dart2wasm:dart2wasm_product_snapshot", ] - sources = [ "$root_out_dir/dart2wasm.snapshot" ] + sources = [ "$root_out_dir/dart2wasm_product.snapshot" ] outputs = [ "$root_out_dir/$dart_sdk_output/bin/snapshots/{{source_file_part}}" ] } diff --git a/utils/aot_snapshot.gni b/utils/aot_snapshot.gni index 5527528363b..c93fe836d24 100644 --- a/utils/aot_snapshot.gni +++ b/utils/aot_snapshot.gni @@ -9,6 +9,9 @@ _dart_root = get_path_info("..", "abspath") template("aot_snapshot") { assert(defined(invoker.main_dart), "Must specify 'main_dart'") + product_mode = + (defined(dart_runtime_mode) && dart_runtime_mode == "release") || + (defined(invoker.force_product_mode) && invoker.force_product_mode) gen_kernel_args = [] if (defined(invoker.gen_kernel_args)) { gen_kernel_args = invoker.gen_kernel_args @@ -92,6 +95,9 @@ template("aot_snapshot") { ] args += gen_kernel_args args += [ rebase_path(main_dart) ] + if (product_mode) { + args += [ "-Ddart.vm.product=true" ] + } } # Create a snapshot from kernel built above. @@ -114,5 +120,7 @@ template("aot_snapshot") { ] + gen_snapshot_args args = [ rebase_path(dill) ] + + force_product_mode = product_mode } } diff --git a/utils/dart2wasm/BUILD.gn b/utils/dart2wasm/BUILD.gn index 591b0263659..04275044408 100644 --- a/utils/dart2wasm/BUILD.gn +++ b/utils/dart2wasm/BUILD.gn @@ -35,6 +35,12 @@ aot_snapshot("dart2wasm_asserts_snapshot") { gen_snapshot_args = [ "--enable-asserts" ] } +aot_snapshot("dart2wasm_product_snapshot") { + main_dart = "../../pkg/dart2wasm/bin/dart2wasm.dart" + name = "dart2wasm_product" + force_product_mode = true +} + compile_platform("compile_dart2wasm_platform") { single_root_scheme = "org-dartlang-sdk" single_root_base = rebase_path("$sdk_root/")