Skip to content

Commit 325a96d

Browse files
committed
[Bazel] Support for feature debug fission in emsdk-bazel-toolchain emscripten-core#1479
1 parent 85390ce commit 325a96d

10 files changed

+91
-3
lines changed

bazel/BUILD

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,18 @@ alias(
7878
}),
7979
)
8080

81+
alias(
82+
name = "dwp_files",
83+
actual = select({
84+
":linux": "@emscripten_bin_linux//:dwp_files",
85+
":linux_arm64": "@emscripten_bin_linux_arm64//:dwp_files",
86+
":macos": "@emscripten_bin_mac//:dwp_files",
87+
":macos_arm64": "@emscripten_bin_mac_arm64//:dwp_files",
88+
":windows": "@emscripten_bin_win//:dwp_files",
89+
"//conditions:default": ":empty",
90+
}),
91+
)
92+
8193
platform(
8294
name = "platform_wasm",
8395
constraint_values = [

bazel/emscripten_deps.bzl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ filegroup(
9696
],
9797
),
9898
)
99+
100+
filegroup(
101+
name = "dwp_files",
102+
srcs = [
103+
"bin/llvm-dwp{bin_extension}",
104+
],
105+
)
99106
"""
100107

101108
def emscripten_deps(emscripten_version = "latest"):

bazel/emscripten_toolchain/BUILD.bazel

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,25 @@ filegroup(
4343
],
4444
)
4545

46+
filegroup(
47+
name = "dwp_files",
48+
srcs = [
49+
"emdwp-emscripten_bin_linux_arm64.sh",
50+
"emdwp-emscripten_bin_linux.sh",
51+
"emdwp-emscripten_bin_mac_arm64.sh",
52+
"emdwp-emscripten_bin_mac.sh",
53+
"emdwp-emscripten_bin_win.bat",
54+
"@emsdk//:dwp_files",
55+
],
56+
)
57+
4658
filegroup(
4759
name = "all_files",
4860
srcs = [
4961
":ar_files",
5062
":compiler_files",
5163
":linker_files",
64+
":dwp_files",
5265
],
5366
)
5467

@@ -75,7 +88,7 @@ cc_toolchain(
7588
ar_files = ":ar_files",
7689
as_files = ":empty",
7790
compiler_files = ":compiler_files",
78-
dwp_files = ":empty",
91+
dwp_files = ":dwp_files",
7992
linker_files = ":linker_files",
8093
objcopy_files = ":empty",
8194
strip_files = ":empty",
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
exec external/emscripten_bin_linux/bin/llvm-dwp "$@"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
exec external/emscripten_bin_linux_arm64/bin/llvm-dwp "$@"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
exec external/emscripten_bin_mac/bin/llvm-dwp "$@"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
exec external/emscripten_bin_mac_arm64/bin/llvm-dwp "$@"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@ECHO OFF
2+
3+
call external\emscripten_bin_win\bin\llvm-dwp %*

bazel/emscripten_toolchain/toolchain.bzl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,14 @@ def _impl(ctx):
7272

7373
emscripten_dir = ctx.attr.emscripten_binaries.label.workspace_root
7474
nodejs_path = ctx.file.nodejs_bin.path
75+
emscripten_name = ctx.attr.emscripten_binaries.label.repo_name
7576

7677
builtin_sysroot = emscripten_dir + "/emscripten/cache/sysroot"
7778

7879
emcc_script = "emcc.%s" % ctx.attr.script_extension
7980
emcc_link_script = "emcc_link.%s" % ctx.attr.script_extension
8081
emar_script = "emar.%s" % ctx.attr.script_extension
82+
emdwp_script = "emdwp-%s.%s" % (emscripten_name, ctx.attr.script_extension)
8183

8284
################################################################
8385
# Tools
@@ -87,6 +89,7 @@ def _impl(ctx):
8789
link_tool = tool(path = emcc_link_script)
8890
archive_tool = tool(path = emar_script)
8991
strip_tool = tool(path = "NOT_USED_STRIP_TOOL")
92+
dwarf_tool = tool(path = emdwp_script) # TODO @unused
9093

9194
#### Legacy tool paths (much of this is redundant with action_configs, but
9295
#### these are still used for some things)
@@ -99,6 +102,7 @@ def _impl(ctx):
99102
tool_path(name = "nm", path = "NOT_USED"),
100103
tool_path(name = "objdump", path = "/bin/false"),
101104
tool_path(name = "strip", path = "NOT_USED"),
105+
tool_path(name = "dwp", path = emdwp_script),
102106
]
103107

104108
################################################################
@@ -460,6 +464,34 @@ def _impl(ctx):
460464
feature(
461465
name = "wasm_standalone",
462466
),
467+
# Support for debug fission. In short, debugging fission should:
468+
# * reduce linking time, RAM usage and disk usage
469+
# * speed up incremental builds
470+
# * speed up debugger work (reduce startup and breakpoint time)
471+
# (to use this, follow the --fission=yes flag)
472+
# https://developer.chrome.com/blog/faster-wasm-debugging
473+
# https://bazel.build/docs/user-manual#fission
474+
feature(
475+
name = "per_object_debug_info",
476+
flag_sets = [
477+
flag_set(
478+
actions = [
479+
ACTION_NAMES.c_compile,
480+
ACTION_NAMES.cpp_compile,
481+
ACTION_NAMES.cpp_module_codegen,
482+
ACTION_NAMES.assemble,
483+
ACTION_NAMES.preprocess_assemble,
484+
],
485+
flag_groups = [
486+
flag_group(
487+
flags = ["-g", "-gsplit-dwarf", "-gdwarf-5", "-gpubnames"],
488+
expand_if_available = "per_object_debug_info_file",
489+
),
490+
],
491+
),
492+
],
493+
enabled = True,
494+
),
463495
]
464496

465497
crosstool_default_flag_sets = [

bazel/emscripten_toolchain/wasm_cc_binary.bzl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,17 @@ def _wasm_cc_binary_impl(ctx):
129129
executable = ctx.executable._wasm_binary_extractor,
130130
)
131131

132+
outputs = ctx.outputs.outputs
133+
dwp_file = cc_target[DebugPackageInfo].dwp_file if DebugPackageInfo in cc_target else None
134+
if dwp_file:
135+
outputs = outputs + [dwp_file]
136+
132137
return [
133138
DefaultInfo(
134-
files = depset(ctx.outputs.outputs),
139+
files = depset(outputs),
135140
# This is needed since rules like web_test usually have a data
136141
# dependency on this target.
137-
data_runfiles = ctx.runfiles(transitive_files = depset(ctx.outputs.outputs)),
142+
data_runfiles = ctx.runfiles(transitive_files = depset(outputs)),
138143
),
139144
OutputGroupInfo(_wasm_tar = cc_target.files),
140145
]
@@ -167,6 +172,10 @@ def _wasm_cc_binary_legacy_impl(ctx):
167172
executable = ctx.executable._wasm_binary_extractor,
168173
)
169174

175+
dwp_file = cc_target[DebugPackageInfo].dwp_file if DebugPackageInfo in cc_target else None
176+
if dwp_file:
177+
outputs = outputs + [dwp_file]
178+
170179
return [
171180
DefaultInfo(
172181
executable = ctx.outputs.wasm,

0 commit comments

Comments
 (0)