Skip to content

Commit cbde772

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

File tree

2 files changed

+32
-16
lines changed

2 files changed

+32
-16
lines changed

bazel/emscripten_toolchain/wasm_binary.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import argparse
1515
import os
1616
import tarfile
17-
17+
import shutil
1818

1919
def ensure(f):
2020
if not os.path.exists(f):
@@ -26,11 +26,20 @@ def main():
2626
parser = argparse.ArgumentParser()
2727
parser.add_argument('--archive', help='The archive to extract from.')
2828
parser.add_argument('--outputs', help='Comma separated list of files that should be extracted from the archive. Only the extname has to match a file in the archive.')
29+
parser.add_argument('--dwp_file', help='Optional dwp input file, generated when fission flags set.')
2930
parser.add_argument('--allow_empty_outputs', help='If an output listed in --outputs does not exist, create it anyways.', action='store_true')
3031
args = parser.parse_args()
3132

3233
args.archive = os.path.normpath(args.archive)
3334
args.outputs = args.outputs.split(",")
35+
args.dwp_file = os.path.normpath(args.dwp_file) if args.dwp_file else None
36+
37+
if args.dwp_file:
38+
for idx, output in enumerate(args.outputs):
39+
if output.endswith(".dwp"): # also update extension 'binary.dwp' to 'binary.wasm.dwp'
40+
shutil.copy2(args.dwp_file, output)
41+
args.outputs.pop(idx)
42+
break
3443

3544
tar = tarfile.open(args.archive)
3645

bazel/emscripten_toolchain/wasm_cc_binary.bzl

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ _ALLOW_OUTPUT_EXTNAMES = [
6969
".fetch.js",
7070
".js.symbols",
7171
".wasm.debug.wasm",
72+
".wasm.dwp",
7273
".html",
7374
".aw.js",
7475
]
@@ -107,10 +108,11 @@ _WASM_BINARY_COMMON_ATTRS = {
107108
}
108109

109110
def _wasm_cc_binary_impl(ctx):
110-
args = ctx.actions.args()
111111
cc_target = ctx.attr.cc_target[0]
112+
dwp_file = cc_target[DebugPackageInfo].dwp_file if DebugPackageInfo in cc_target else None
113+
outputs = ctx.outputs.outputs
112114

113-
for output in ctx.outputs.outputs:
115+
for output in outputs:
114116
valid_extname = False
115117
for allowed_extname in _ALLOW_OUTPUT_EXTNAMES:
116118
if output.path.endswith(allowed_extname):
@@ -119,21 +121,22 @@ def _wasm_cc_binary_impl(ctx):
119121
if not valid_extname:
120122
fail("Invalid output '{}'. Allowed extnames: {}".format(output.basename, ", ".join(_ALLOW_OUTPUT_EXTNAMES)))
121123

124+
inputs = ctx.files.cc_target
125+
args = ctx.actions.args()
122126
args.add_all("--archive", ctx.files.cc_target)
123-
args.add_joined("--outputs", ctx.outputs.outputs, join_with = ",")
127+
args.add_joined("--outputs", outputs, join_with = ",")
128+
129+
if dwp_file:
130+
args.add("--dwp_file", dwp_file)
131+
inputs = inputs + [dwp_file]
124132

125133
ctx.actions.run(
126-
inputs = ctx.files.cc_target,
127-
outputs = ctx.outputs.outputs,
134+
inputs = inputs,
135+
outputs = outputs,
128136
arguments = [args],
129137
executable = ctx.executable._wasm_binary_extractor,
130138
)
131139

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-
137140
return [
138141
DefaultInfo(
139142
files = depset(outputs),
@@ -146,6 +149,7 @@ def _wasm_cc_binary_impl(ctx):
146149

147150
def _wasm_cc_binary_legacy_impl(ctx):
148151
cc_target = ctx.attr.cc_target[0]
152+
dwp_file = cc_target[DebugPackageInfo].dwp_file if DebugPackageInfo in cc_target else None
149153
outputs = [
150154
ctx.outputs.loader,
151155
ctx.outputs.wasm,
@@ -156,26 +160,28 @@ def _wasm_cc_binary_legacy_impl(ctx):
156160
ctx.outputs.data,
157161
ctx.outputs.symbols,
158162
ctx.outputs.dwarf,
163+
ctx.outputs.dwp,
159164
ctx.outputs.html,
160165
ctx.outputs.audio_worklet,
161166
]
162167

168+
inputs = ctx.files.cc_target
163169
args = ctx.actions.args()
164170
args.add("--allow_empty_outputs")
165171
args.add_all("--archive", ctx.files.cc_target)
166172
args.add_joined("--outputs", outputs, join_with = ",")
167173

174+
if dwp_file:
175+
args.add("--dwp_file", dwp_file)
176+
inputs = inputs + [dwp_file]
177+
168178
ctx.actions.run(
169-
inputs = ctx.files.cc_target,
179+
inputs = inputs,
170180
outputs = outputs,
171181
arguments = [args],
172182
executable = ctx.executable._wasm_binary_extractor,
173183
)
174184

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-
179185
return [
180186
DefaultInfo(
181187
executable = ctx.outputs.wasm,
@@ -211,6 +217,7 @@ def _wasm_binary_legacy_outputs(name, cc_target):
211217
"data": "{}/{}.data".format(name, basename),
212218
"symbols": "{}/{}.js.symbols".format(name, basename),
213219
"dwarf": "{}/{}.wasm.debug.wasm".format(name, basename),
220+
"dwp": "{}/{}.wasm.dwp".format(name, basename),
214221
"html": "{}/{}.html".format(name, basename),
215222
"audio_worklet": "{}/{}.aw.js".format(name, basename)
216223
}

0 commit comments

Comments
 (0)