Skip to content

Commit 6271d26

Browse files
eyebrowsoffireCommit Queue
authored and
Commit Queue
committed
[dart2wasm] Include wasm-opt in the shipped dart-sdk.
Change-Id: Ib224f0b92fa28019ad3cf67d7ba2bef5c31b92ef Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/280840 Reviewed-by: Martin Kustermann <[email protected]> Commit-Queue: Jackson Gardner <[email protected]> Reviewed-by: Aske Simon Christensen <[email protected]>
1 parent 0a93b04 commit 6271d26

File tree

5 files changed

+49
-1
lines changed

5 files changed

+49
-1
lines changed

build/config/compiler/BUILD.gn

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,15 @@ config("no_rtti") {
729729
}
730730
}
731731

732+
config("enable_exceptions") {
733+
if (is_win) {
734+
cflags_cc = [ "/EHsc" ]
735+
defines = [ "_HAS_EXCEPTIONS=1" ]
736+
} else if (is_clang) {
737+
cflags_cc = [ "-fexceptions" ]
738+
}
739+
}
740+
732741
# Optimization -----------------------------------------------------------------
733742
#
734743
# Note that BUILDCONFIG.gn sets up a variable "default_optimization_config"

build/toolchain/win/tool_wrapper.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"""
99

1010
import os
11+
import pathlib
1112
import re
1213
import shutil
1314
import subprocess
@@ -149,7 +150,28 @@ def ExecLinkWrapper(self, arch, use_separate_mspdbsrv, *args):
149150
not line.startswith('Generating code') and
150151
not line.startswith('Finished generating code')):
151152
print(line)
152-
return link.wait()
153+
link_result = link.wait()
154+
155+
if link_result != 0:
156+
return link_result
157+
158+
# The toolchain configuration in gn always expects a .lib file to be
159+
# included in the output of the link step. However, this only happens
160+
# when the output has exports, and that is not always the case. In
161+
# order to satisfy the expected outputs, we create a dummy .lib file
162+
# in cases where the link step didn't actually create one.
163+
for arg in args:
164+
m = _LINK_EXE_OUT_ARG.match(arg)
165+
if m:
166+
output_filename = m.group('out')
167+
(basename, extension) = os.path.splitext(output_filename)
168+
if extension == '.exe':
169+
lib_path = pathlib.Path(basename + ".lib")
170+
if not os.path.exists(lib_path):
171+
lib_path.touch()
172+
break
173+
174+
return link_result
153175

154176
def ExecMidlWrapper(self, arch, outdir, tlb, h, dlldata, iid, proxy, idl,
155177
*flags):

sdk/BUILD.gn

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ declare_args() {
2727
dart_precompiled_runtime_stripped_binary = "dart_precompiled_runtime_product"
2828
gen_snapshot_stripped_binary = "gen_snapshot_product"
2929
analyze_snapshot_binary = "analyze_snapshot"
30+
wasm_opt_stripped_binary = "wasm-opt"
3031
}
3132

3233
# The directory layout of the SDK is as follows:
@@ -518,6 +519,16 @@ copy("copy_dart2wasm_snapshot") {
518519
[ "$root_out_dir/$dart_sdk_output/bin/snapshots/{{source_file_part}}" ]
519520
}
520521

522+
copy("copy_wasm_opt") {
523+
visibility = [ ":create_full_sdk" ]
524+
deps = [
525+
":copy_libraries",
526+
"../third_party/binaryen:wasm-opt",
527+
]
528+
sources = [ "$root_out_dir/${wasm_opt_stripped_binary}${executable_suffix}" ]
529+
outputs = [ "$root_out_dir/$dart_sdk_output/bin/utils/{{source_file_part}}" ]
530+
}
531+
521532
# Copies DDC's SDK full and outline .dill files to lib/_internal.
522533
copy("copy_dev_compiler_dills") {
523534
visibility = [ ":copy_dev_compiler_sdk" ]
@@ -755,6 +766,7 @@ group("create_full_sdk") {
755766
public_deps += [
756767
":copy_dart2wasm_platform",
757768
":copy_dart2wasm_snapshot",
769+
":copy_wasm_opt",
758770
]
759771
}
760772
}

third_party/binaryen/BUILD.gn

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ source_set("binaryen_sources") {
5959

6060
# Ensure generated config.h file is include path.
6161
include_dirs += [ "$target_gen_dir" ]
62+
63+
configs += [ "//build/config/compiler:enable_exceptions" ]
6264
}
6365

6466
template("wasm_tool") {
@@ -72,6 +74,8 @@ template("wasm_tool") {
7274
include_dirs = [ "src/src" ]
7375
deps = [ ":binaryen_sources" ]
7476
forward_variables_from(invoker, "*")
77+
78+
configs += [ "//build/config/compiler:enable_exceptions" ]
7579
}
7680
}
7781

tools/gn.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ def ToGnArgs(args, mode, arch, target_os, sanitizer, verify_sdk_hash):
300300
gn_args['gen_snapshot_stripped_binary'] = (
301301
'exe.stripped/gen_snapshot_product')
302302
gn_args['analyze_snapshot_binary'] = ('exe.stripped/analyze_snapshot')
303+
gn_args['wasm_opt_stripped_binary'] = 'exe.stripped/wasm-opt'
303304

304305
# Setup the user-defined sysroot.
305306
if UseSysroot(args, gn_args):

0 commit comments

Comments
 (0)