[dart2wasm] Build snapshot as part of the SDK.

Change-Id: Iea75c14b6709f2347fe82af2ef226a1ed068d8a6
Cq-Include-Trybots: luci.dart.try:dart-sdk-linux-try,dart-sdk-mac-arm64-try,dart-sdk-mac-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/261502
Reviewed-by: Alexander Thomas <athom@google.com>
Commit-Queue: Joshua Litt <joshualitt@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
diff --git a/BUILD.gn b/BUILD.gn
index 1773913..7c566ef 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -103,12 +103,18 @@
   deps = [ "utils/compiler:dart2js" ]
 }
 
-group("dart2wasm") {
+group("dart2wasm_platform") {
   deps = [
     ":runtime_precompiled",
     "utils/dart2wasm:compile_dart2wasm_platform",
     "utils/dart2wasm:dart2wasm_asserts_snapshot",
     "utils/dart2wasm:dart2wasm_snapshot",
+  ]
+}
+
+group("dart2wasm") {
+  deps = [
+    ":dart2wasm_platform",
     "utils/dart2wasm:test_wasm_modules",
   ]
 }
diff --git a/sdk/BUILD.gn b/sdk/BUILD.gn
index 63ff6ff..f33fb05 100644
--- a/sdk/BUILD.gn
+++ b/sdk/BUILD.gn
@@ -38,10 +38,12 @@
 # ......dartaotruntime or dartaotruntime.exe (executable)
 # ......dart2js
 # ......dartdevc
+# ......run_wasm.js (if not on ia32)
 # ......utils/gen_snapshot or utils/gen_snapshot.exe (if not on ia32)
 # ......snapshots/
 # ........analysis_server.dart.snapshot
 # ........dart2js.dart.snapshot
+# ........dart2wasm.dart.snapshot (if not on ia32)
 # ........dartdev.dart.snapshot
 # ........dartdev.dill
 # ........dartdevc.dart.snapshot
@@ -67,6 +69,8 @@
 # ........dart2js_platform_unsound.dill
 # ........dart2js_server_platform.dill
 # ........dart2js_server_platform_unsound.dill
+# ........dart2wasm_platform.dill (if not on ia32)
+# ........dart2wasm_outline.dill (if not on ia32)
 # ........vm_platform_strong.dill
 # ........dev_compiler/
 # ......async/
@@ -481,6 +485,37 @@
       [ "$root_out_dir/$dart_sdk_output/lib/_internal/{{source_file_part}}" ]
 }
 
+copy("copy_dart2wasm_platform") {
+  visibility = [ ":create_full_sdk" ]
+  deps = [
+    ":copy_libraries",
+    "../:dart2wasm_platform",
+    "../utils/dart2wasm:compile_dart2wasm_platform",
+  ]
+  sources = [
+    "$root_out_dir/dart2wasm_outline.dill",
+    "$root_out_dir/dart2wasm_platform.dill",
+  ]
+  outputs =
+      [ "$root_out_dir/$dart_sdk_output/lib/_internal/{{source_file_part}}" ]
+}
+
+copy("copy_dart2wasm_runtime") {
+  visibility = [ ":create_full_sdk" ]
+  sources = [ "../pkg/dart2wasm/bin/run_wasm.js" ]
+  outputs = [ "$root_out_dir/$dart_sdk_output/bin/{{source_file_part}}" ]
+}
+
+copy("copy_dart2wasm_snapshot") {
+  visibility = [ ":create_full_sdk" ]
+  deps = [
+    ":copy_libraries",
+    "../utils/dart2wasm:dart2wasm_snapshot",
+  ]
+  sources = [ "$root_out_dir/dart2wasm.snapshot" ]
+  outputs = [ "$root_out_dir/$dart_sdk_output/snapshots/{{source_file_part}}" ]
+}
+
 # Copies DDC's SDK weak outline .dill to lib/_internal
 # TODO(nshahan) Fix the outline to be consistent and merge with below as a
 # breaking change.
@@ -775,6 +810,14 @@
     ":copy_full_sdk_scripts",
     ":copy_full_sdk_snapshots",
   ]
+
+  if (dart_target_arch != "ia32" && dart_target_arch != "x86") {
+    public_deps += [
+      ":copy_dart2wasm_platform",
+      ":copy_dart2wasm_runtime",
+      ":copy_dart2wasm_snapshot",
+    ]
+  }
 }
 
 # Build a SDK with less stuff. It excludes dart2js, ddc, and web libraries.