forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemsdk.patch
More file actions
635 lines (592 loc) · 22.8 KB
/
emsdk.patch
File metadata and controls
635 lines (592 loc) · 22.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
diff --git a/bazel/BUILD b/bazel/BUILD
index cb3135c..4d6d92c 100644
--- a/bazel/BUILD
+++ b/bazel/BUILD
@@ -78,6 +78,18 @@ alias(
}),
)
+alias(
+ name = "dwp_files",
+ actual = select({
+ ":linux": "@emscripten_bin_linux//:dwp_files",
+ ":linux_arm64": "@emscripten_bin_linux_arm64//:dwp_files",
+ ":macos": "@emscripten_bin_mac//:dwp_files",
+ ":macos_arm64": "@emscripten_bin_mac_arm64//:dwp_files",
+ ":windows": "@emscripten_bin_win//:dwp_files",
+ "//conditions:default": ":empty",
+ }),
+)
+
platform(
name = "platform_wasm",
constraint_values = [
diff --git a/bazel/emscripten_deps.bzl b/bazel/emscripten_deps.bzl
index 9d020bd..f466edb 100644
--- a/bazel/emscripten_deps.bzl
+++ b/bazel/emscripten_deps.bzl
@@ -96,6 +96,13 @@ filegroup(
],
),
)
+
+filegroup(
+ name = "dwp_files",
+ srcs = [
+ "bin/llvm-dwp{bin_extension}",
+ ],
+)
"""
def emscripten_deps(emscripten_version = "latest"):
@@ -173,38 +180,3 @@ def emscripten_deps(emscripten_version = "latest"):
build_file_content = BUILD_FILE_CONTENT_TEMPLATE.format(bin_extension = ".exe"),
type = "zip",
)
-
- if "emscripten_npm_linux" not in excludes:
- npm_translate_lock(
- name = "emscripten_npm_linux",
- data = ["@emscripten_bin_linux//:emscripten/package.json"],
- npm_package_lock = "@emscripten_bin_linux//:emscripten/package-lock.json",
- )
-
- if "emscripten_npm_linux_arm64" not in excludes:
- npm_translate_lock(
- name = "emscripten_npm_linux_arm64",
- data = ["@emscripten_bin_linux_arm64//:emscripten/package.json"],
- npm_package_lock = "@emscripten_bin_linux_arm64//:emscripten/package-lock.json",
- )
-
- if "emscripten_npm_mac" not in excludes:
- npm_translate_lock(
- name = "emscripten_npm_mac",
- data = ["@emscripten_bin_mac//:emscripten/package.json"],
- npm_package_lock = "@emscripten_bin_mac//:emscripten/package-lock.json",
- )
-
- if "emscripten_npm_mac_arm64" not in excludes:
- npm_translate_lock(
- name = "emscripten_npm_mac",
- data = ["@emscripten_bin_mac_arm64//:emscripten/package.json"],
- npm_package_lock = "@emscripten_bin_mac_arm64//:emscripten/package-lock.json",
- )
-
- if "emscripten_npm_win" not in excludes:
- npm_translate_lock(
- name = "emscripten_npm_win",
- data = ["@emscripten_bin_win//:emscripten/package.json"],
- npm_package_lock = "@emscripten_bin_win//:emscripten/package-lock.json",
- )
diff --git a/bazel/emscripten_toolchain/BUILD.bazel b/bazel/emscripten_toolchain/BUILD.bazel
index a989450..4f1c213 100644
--- a/bazel/emscripten_toolchain/BUILD.bazel
+++ b/bazel/emscripten_toolchain/BUILD.bazel
@@ -1,3 +1,4 @@
+load("@python3_12//:defs.bzl", "py_binary")
load(":toolchain.bzl", "emscripten_cc_toolchain_config_rule")
package(default_visibility = ["//visibility:public"])
@@ -9,6 +10,7 @@ filegroup(
"env.sh",
"env.bat",
"@nodejs//:node_files",
+ "@python3_12//:files",
],
)
@@ -43,12 +45,25 @@ filegroup(
],
)
+filegroup(
+ name = "dwp_files",
+ srcs = [
+ "emdwp-emscripten_bin_linux_arm64.sh",
+ "emdwp-emscripten_bin_linux.sh",
+ "emdwp-emscripten_bin_mac_arm64.sh",
+ "emdwp-emscripten_bin_mac.sh",
+ "emdwp-emscripten_bin_win.bat",
+ "@emsdk//:dwp_files",
+ ],
+)
+
filegroup(
name = "all_files",
srcs = [
":ar_files",
":compiler_files",
":linker_files",
+ ":dwp_files",
],
)
@@ -63,9 +78,9 @@ emscripten_cc_toolchain_config_rule(
em_config = "@emscripten_cache//:emscripten_config",
emscripten_binaries = "@emsdk//:compiler_files",
nodejs_bin = "@nodejs//:node",
- script_extension = select({
- "@bazel_tools//src/conditions:host_windows": "bat",
- "//conditions:default": "sh",
+ is_windows = select({
+ "@bazel_tools//src/conditions:host_windows": True,
+ "//conditions:default": False,
}),
)
@@ -75,7 +90,7 @@ cc_toolchain(
ar_files = ":ar_files",
as_files = ":empty",
compiler_files = ":compiler_files",
- dwp_files = ":empty",
+ dwp_files = ":dwp_files",
linker_files = ":linker_files",
objcopy_files = ":empty",
strip_files = ":empty",
diff --git a/bazel/emscripten_toolchain/dwp.bat b/bazel/emscripten_toolchain/dwp.bat
new file mode 100644
index 0000000..85ed4b5
--- /dev/null
+++ b/bazel/emscripten_toolchain/dwp.bat
@@ -0,0 +1,4 @@
+@echo off
+REM Dummy dwp script for emscripten toolchain
+REM Since wasm doesn't support split debug info, this is a no-op
+exit /b 0
diff --git a/bazel/emscripten_toolchain/dwp.sh b/bazel/emscripten_toolchain/dwp.sh
new file mode 100644
index 0000000..50a1d80
--- /dev/null
+++ b/bazel/emscripten_toolchain/dwp.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+# Dummy dwp script for emscripten toolchain
+# Since wasm doesn't support split debug info, this is a no-op
+# Just echo the command for debugging and exit successfully
+
+echo "DWP called with args: $@" >&2
+exit 0
diff --git a/bazel/emscripten_toolchain/emar.bat b/bazel/emscripten_toolchain/emar.bat
index b8e9125..844c378 100644
--- a/bazel/emscripten_toolchain/emar.bat
+++ b/bazel/emscripten_toolchain/emar.bat
@@ -2,4 +2,4 @@
call external\emsdk\emscripten_toolchain\env.bat
-py -3 %EMSCRIPTEN%\emar.py %*
+%EMSDK_PYTHON% %EMSCRIPTEN%\emar.py %*
diff --git a/bazel/emscripten_toolchain/emar.sh b/bazel/emscripten_toolchain/emar.sh
index b4ead6e..d57222f 100755
--- a/bazel/emscripten_toolchain/emar.sh
+++ b/bazel/emscripten_toolchain/emar.sh
@@ -2,4 +2,11 @@
source $(dirname $0)/env.sh
-exec python3 $EMSCRIPTEN/emar.py "$@"
+if [[ "$EMSDK_PYTHON" != /* ]]; then
+ EMSDK_PYTHON="$ROOT_DIR/$EMSDK_PYTHON"
+fi
+
+PYBINPATH="$(dirname "${EMSDK_PYTHON}")"
+export PATH=$PYBINPATH:$PATH
+
+exec $EMSDK_PYTHON $EMSCRIPTEN/emar.py "$@"
diff --git a/bazel/emscripten_toolchain/emcc.bat b/bazel/emscripten_toolchain/emcc.bat
index aba66f4..b302736 100644
--- a/bazel/emscripten_toolchain/emcc.bat
+++ b/bazel/emscripten_toolchain/emcc.bat
@@ -2,4 +2,4 @@
call external\emsdk\emscripten_toolchain\env.bat
-py -3 %EMSCRIPTEN%\emcc.py %*
+%EMSDK_PYTHON% %EMSCRIPTEN%\emcc.py %*
diff --git a/bazel/emscripten_toolchain/emcc.sh b/bazel/emscripten_toolchain/emcc.sh
index 5fdaf9c..f0f36ab 100755
--- a/bazel/emscripten_toolchain/emcc.sh
+++ b/bazel/emscripten_toolchain/emcc.sh
@@ -1,5 +1,12 @@
-#!/bin/bash
+#!/bin/bash -e
source $(dirname $0)/env.sh
-exec python3 $EMSCRIPTEN/emcc.py "$@"
+if [[ "$EMSDK_PYTHON" != /* ]]; then
+ EMSDK_PYTHON="$ROOT_DIR/$EMSDK_PYTHON"
+fi
+
+PYBINPATH="$(dirname "${EMSDK_PYTHON}")"
+export PATH=$PYBINPATH:$PATH
+
+exec $EMSDK_PYTHON $EMSCRIPTEN/emcc.py "$@"
diff --git a/bazel/emscripten_toolchain/emcc_base.sh b/bazel/emscripten_toolchain/emcc_base.sh
new file mode 100755
index 0000000..e9ddd2c
--- /dev/null
+++ b/bazel/emscripten_toolchain/emcc_base.sh
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+source $(dirname $0)/env.sh
+
+PYTHON3="${PYTHON3:-python3}"
+
+exec $PYTHON3 $EMSCRIPTEN/emcc.py "$@"
diff --git a/bazel/emscripten_toolchain/emcc_link.bat b/bazel/emscripten_toolchain/emcc_link.bat
index 8e5a6eb..fef6501 100644
--- a/bazel/emscripten_toolchain/emcc_link.bat
+++ b/bazel/emscripten_toolchain/emcc_link.bat
@@ -2,4 +2,4 @@
call external\emsdk\emscripten_toolchain\env.bat
-py -3 external\emsdk\emscripten_toolchain\link_wrapper.py %*
+%EMSDK_PYTHON% external\emsdk\emscripten_toolchain\link_wrapper.py %*
diff --git a/bazel/emscripten_toolchain/emcc_link.sh b/bazel/emscripten_toolchain/emcc_link.sh
index 44f3235..950e529 100755
--- a/bazel/emscripten_toolchain/emcc_link.sh
+++ b/bazel/emscripten_toolchain/emcc_link.sh
@@ -2,4 +2,11 @@
source $(dirname $0)/env.sh
-exec python3 $(dirname $0)/link_wrapper.py "$@"
+if [[ "$EMSDK_PYTHON" != /* ]]; then
+ EMSDK_PYTHON="$ROOT_DIR/$EMSDK_PYTHON"
+fi
+
+PYBINPATH="$(dirname "${EMSDK_PYTHON}")"
+export PATH=$PYBINPATH:$PATH
+
+exec $EMSDK_PYTHON $(dirname $0)/link_wrapper.py "$@"
diff --git a/bazel/emscripten_toolchain/emdwp-emscripten_bin_linux.sh b/bazel/emscripten_toolchain/emdwp-emscripten_bin_linux.sh
new file mode 100755
index 0000000..513feee
--- /dev/null
+++ b/bazel/emscripten_toolchain/emdwp-emscripten_bin_linux.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+#
+# This script differs in form from emcc.{py,bat}/…, because bazel are limited/bugged in the way of executing dwp tool.
+# Bazel dwp action configuration does not pass environment variables, so we cannot use them in this script.
+# For more info, see PR discussion and bazel issue:
+# - https://github.com/emscripten-core/emsdk/pull/1531#discussion_r1962090650
+# - https://github.com/bazelbuild/bazel/issues/25336
+#
+
+exec external/emscripten_bin_linux/bin/llvm-dwp "$@"
diff --git a/bazel/emscripten_toolchain/emdwp-emscripten_bin_linux_arm64.sh b/bazel/emscripten_toolchain/emdwp-emscripten_bin_linux_arm64.sh
new file mode 100755
index 0000000..f6f3383
--- /dev/null
+++ b/bazel/emscripten_toolchain/emdwp-emscripten_bin_linux_arm64.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+#
+# This script differs in form from emcc.{py,bat}/…, because bazel are limited/bugged in the way of executing dwp tool.
+# Bazel dwp action configuration does not pass environment variables, so we cannot use them in this script.
+# For more info, see PR discussion and bazel issue:
+# - https://github.com/emscripten-core/emsdk/pull/1531#discussion_r1962090650
+# - https://github.com/bazelbuild/bazel/issues/25336
+#
+
+exec external/emscripten_bin_linux_arm64/bin/llvm-dwp "$@"
diff --git a/bazel/emscripten_toolchain/emdwp-emscripten_bin_mac.sh b/bazel/emscripten_toolchain/emdwp-emscripten_bin_mac.sh
new file mode 100755
index 0000000..0f97690
--- /dev/null
+++ b/bazel/emscripten_toolchain/emdwp-emscripten_bin_mac.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+#
+# This script differs in form from emcc.{py,bat}/…, because bazel are limited/bugged in the way of executing dwp tool.
+# Bazel dwp action configuration does not pass environment variables, so we cannot use them in this script.
+# For more info, see PR discussion and bazel issue:
+# - https://github.com/emscripten-core/emsdk/pull/1531#discussion_r1962090650
+# - https://github.com/bazelbuild/bazel/issues/25336
+#
+
+exec external/emscripten_bin_mac/bin/llvm-dwp "$@"
diff --git a/bazel/emscripten_toolchain/emdwp-emscripten_bin_mac_arm64.sh b/bazel/emscripten_toolchain/emdwp-emscripten_bin_mac_arm64.sh
new file mode 100755
index 0000000..4ae033c
--- /dev/null
+++ b/bazel/emscripten_toolchain/emdwp-emscripten_bin_mac_arm64.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+#
+# This script differs in form from emcc.{py,bat}/…, because bazel are limited/bugged in the way of executing dwp tool.
+# Bazel dwp action configuration does not pass environment variables, so we cannot use them in this script.
+# For more info, see PR discussion and bazel issue:
+# - https://github.com/emscripten-core/emsdk/pull/1531#discussion_r1962090650
+# - https://github.com/bazelbuild/bazel/issues/25336
+#
+
+exec external/emscripten_bin_mac_arm64/bin/llvm-dwp "$@"
diff --git a/bazel/emscripten_toolchain/emdwp-emscripten_bin_win.bat b/bazel/emscripten_toolchain/emdwp-emscripten_bin_win.bat
new file mode 100644
index 0000000..3cb1f2e
--- /dev/null
+++ b/bazel/emscripten_toolchain/emdwp-emscripten_bin_win.bat
@@ -0,0 +1,10 @@
+::
+:: This script differs in form from emcc.{py,bat}/…, because bazel are limited/bugged in the way of executing dwp tool.
+:: Bazel dwp action configuration does not pass environment variables, so we cannot use them in this script.
+:: For more info, see PR discussion and bazel issue:
+:: - https://github.com/emscripten-core/emsdk/pull/1531#discussion_r1962090650
+:: - https://github.com/bazelbuild/bazel/issues/25336
+::
+@ECHO OFF
+
+call external\emscripten_bin_win\bin\llvm-dwp %*
diff --git a/bazel/emscripten_toolchain/link_wrapper.py b/bazel/emscripten_toolchain/link_wrapper.py
index 6a6fe2f..6dcacf8 100644
--- a/bazel/emscripten_toolchain/link_wrapper.py
+++ b/bazel/emscripten_toolchain/link_wrapper.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
"""wrapper around emcc link step.
This wrapper currently serves the following purposes.
diff --git a/bazel/emscripten_toolchain/toolchain.bzl b/bazel/emscripten_toolchain/toolchain.bzl
index c8cec07..9559cd1 100644
--- a/bazel/emscripten_toolchain/toolchain.bzl
+++ b/bazel/emscripten_toolchain/toolchain.bzl
@@ -54,6 +54,11 @@ CROSSTOOL_DEFAULT_WARNINGS = [
"-Wall",
]
+def _os_path(ctx, path):
+ if ctx.attr.is_windows:
+ path = path.replace("/", "\\")
+ return path
+
def _impl(ctx):
target_cpu = ctx.attr.cpu
toolchain_identifier = "emscripten-" + target_cpu
@@ -72,12 +77,15 @@ def _impl(ctx):
emscripten_dir = ctx.attr.emscripten_binaries.label.workspace_root
nodejs_path = ctx.file.nodejs_bin.path
+ emscripten_name = ctx.attr.emscripten_binaries.label.workspace_name
builtin_sysroot = emscripten_dir + "/emscripten/cache/sysroot"
- emcc_script = "emcc.%s" % ctx.attr.script_extension
- emcc_link_script = "emcc_link.%s" % ctx.attr.script_extension
- emar_script = "emar.%s" % ctx.attr.script_extension
+ script_extension = "bat" if ctx.attr.is_windows else "sh"
+ emcc_script = "emcc.%s" % script_extension
+ emcc_link_script = "emcc_link.%s" % script_extension
+ emar_script = "emar.%s" % script_extension
+ emdwp_script = "emdwp-%s.%s" % (emscripten_name, script_extension)
################################################################
# Tools
@@ -99,6 +107,7 @@ def _impl(ctx):
tool_path(name = "nm", path = "NOT_USED"),
tool_path(name = "objdump", path = "/bin/false"),
tool_path(name = "strip", path = "NOT_USED"),
+ tool_path(name = "dwp", path = emdwp_script),
]
################################################################
@@ -460,6 +469,49 @@ def _impl(ctx):
feature(
name = "wasm_standalone",
),
+ # Support for debug fission. In short, debugging fission should:
+ # * reduce linking time, RAM usage and disk usage
+ # * speed up incremental builds
+ # * speed up debugger work (reduce startup and breakpoint time)
+ # (to use this, follow the --fission=yes flag)
+ # https://developer.chrome.com/blog/faster-wasm-debugging
+ # https://bazel.build/docs/user-manual#fission
+ feature(
+ name = "per_object_debug_info",
+ flag_sets = [
+ flag_set(
+ actions = [
+ ACTION_NAMES.c_compile,
+ ACTION_NAMES.cpp_compile,
+ ACTION_NAMES.cpp_module_codegen,
+ ACTION_NAMES.assemble,
+ ACTION_NAMES.preprocess_assemble,
+ ],
+ flag_groups = [
+ flag_group(
+ flags = ["-g", "-gsplit-dwarf", "-gdwarf-5", "-gpubnames"],
+ expand_if_available = "per_object_debug_info_file",
+ ),
+ ],
+ ),
+ ],
+ enabled = True,
+ ),
+ feature(
+ name = "fission_support",
+ flag_sets = [
+ flag_set(
+ actions = all_link_actions,
+ flag_groups = [
+ flag_group(
+ flags = ["-sWASM_BIGINT"], # WASM_BIGINT required to support dwarf-5
+ expand_if_available = "is_using_fission",
+ ),
+ ],
+ ),
+ ],
+ enabled = True,
+ )
]
crosstool_default_flag_sets = [
@@ -1046,6 +1098,16 @@ def _impl(ctx):
),
]
+ python_files = ctx.attr._python_interpreter[DefaultInfo].files.to_list()
+ python_bin_path = None
+ for f in python_files:
+ if f.basename == "python3" or f.path.endswith("/bin/python3"):
+ python_bin_path = f.path
+ break
+
+ if not python_bin_path:
+ fail("Could not find python3 binary in " + str(ctx.attr._python_interpreter))
+
crosstool_default_env_sets = [
# Globals
env_set(
@@ -1065,6 +1127,10 @@ def _impl(ctx):
key = "NODE_JS_PATH",
value = nodejs_path,
),
+ env_entry(
+ key = "EMSDK_PYTHON",
+ value = _os_path(ctx, python_bin_path),
+ ),
],
),
# Use llvm backend. Off by default, enabled via --features=llvm_backend
@@ -1140,7 +1206,8 @@ emscripten_cc_toolchain_config_rule = rule(
"em_config": attr.label(mandatory = True, allow_single_file = True),
"emscripten_binaries": attr.label(mandatory = True, cfg = "exec"),
"nodejs_bin": attr.label(mandatory = True, allow_single_file = True),
- "script_extension": attr.string(mandatory = True, values = ["sh", "bat"]),
+ "is_windows": attr.bool(mandatory = True),
+ "_python_interpreter": attr.label(cfg = "exec", default = Label("@python3_12//:files")),
},
provides = [CcToolchainConfigInfo],
)
diff --git a/bazel/emscripten_toolchain/wasm_binary.py b/bazel/emscripten_toolchain/wasm_binary.py
index d7d6142..0da7f55 100644
--- a/bazel/emscripten_toolchain/wasm_binary.py
+++ b/bazel/emscripten_toolchain/wasm_binary.py
@@ -14,6 +14,7 @@ WebAssembly binary into a larger web application.
import argparse
import os
import tarfile
+import shutil
def ensure(f):
@@ -26,11 +27,20 @@ def main():
parser = argparse.ArgumentParser()
parser.add_argument('--archive', help='The archive to extract from.')
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.')
+ parser.add_argument('--dwp_file', help='Optional dwp input file, generated when fission flags set.')
parser.add_argument('--allow_empty_outputs', help='If an output listed in --outputs does not exist, create it anyways.', action='store_true')
args = parser.parse_args()
args.archive = os.path.normpath(args.archive)
args.outputs = args.outputs.split(",")
+ args.dwp_file = os.path.normpath(args.dwp_file) if args.dwp_file else None
+
+ if args.dwp_file:
+ for idx, output in enumerate(args.outputs):
+ if output.endswith(".dwp"): # also update extension 'binary.dwp' to 'binary.wasm.dwp'
+ shutil.copy2(args.dwp_file, output)
+ args.outputs.pop(idx)
+ break
tar = tarfile.open(args.archive)
diff --git a/bazel/emscripten_toolchain/wasm_cc_binary.bzl b/bazel/emscripten_toolchain/wasm_cc_binary.bzl
index 6ea4f12..fcc3391 100644
--- a/bazel/emscripten_toolchain/wasm_cc_binary.bzl
+++ b/bazel/emscripten_toolchain/wasm_cc_binary.bzl
@@ -69,6 +69,7 @@ _ALLOW_OUTPUT_EXTNAMES = [
".fetch.js",
".js.symbols",
".wasm.debug.wasm",
+ ".wasm.dwp",
".html",
".aw.js",
]
@@ -107,10 +108,11 @@ _WASM_BINARY_COMMON_ATTRS = {
}
def _wasm_cc_binary_impl(ctx):
- args = ctx.actions.args()
cc_target = ctx.attr.cc_target[0]
+ dwp_file = cc_target[DebugPackageInfo].dwp_file if DebugPackageInfo in cc_target else None
+ outputs = ctx.outputs.outputs
- for output in ctx.outputs.outputs:
+ for output in outputs:
valid_extname = False
for allowed_extname in _ALLOW_OUTPUT_EXTNAMES:
if output.path.endswith(allowed_extname):
@@ -119,28 +121,35 @@ def _wasm_cc_binary_impl(ctx):
if not valid_extname:
fail("Invalid output '{}'. Allowed extnames: {}".format(output.basename, ", ".join(_ALLOW_OUTPUT_EXTNAMES)))
+ inputs = ctx.files.cc_target
+ args = ctx.actions.args()
args.add_all("--archive", ctx.files.cc_target)
- args.add_joined("--outputs", ctx.outputs.outputs, join_with = ",")
+ args.add_joined("--outputs", outputs, join_with = ",")
+
+ if dwp_file:
+ args.add("--dwp_file", dwp_file)
+ inputs = inputs + [dwp_file]
ctx.actions.run(
- inputs = ctx.files.cc_target,
- outputs = ctx.outputs.outputs,
+ inputs = inputs,
+ outputs = outputs,
arguments = [args],
executable = ctx.executable._wasm_binary_extractor,
)
return [
DefaultInfo(
- files = depset(ctx.outputs.outputs),
+ files = depset(outputs),
# This is needed since rules like web_test usually have a data
# dependency on this target.
- data_runfiles = ctx.runfiles(transitive_files = depset(ctx.outputs.outputs)),
+ data_runfiles = ctx.runfiles(transitive_files = depset(outputs)),
),
OutputGroupInfo(_wasm_tar = cc_target.files),
]
def _wasm_cc_binary_legacy_impl(ctx):
cc_target = ctx.attr.cc_target[0]
+ dwp_file = cc_target[DebugPackageInfo].dwp_file if DebugPackageInfo in cc_target else None
outputs = [
ctx.outputs.loader,
ctx.outputs.wasm,
@@ -151,20 +160,31 @@ def _wasm_cc_binary_legacy_impl(ctx):
ctx.outputs.data,
ctx.outputs.symbols,
ctx.outputs.dwarf,
+ ctx.outputs.dwp,
ctx.outputs.html,
ctx.outputs.audio_worklet,
]
+ inputs = ctx.files.cc_target
args = ctx.actions.args()
args.add("--allow_empty_outputs")
args.add_all("--archive", ctx.files.cc_target)
args.add_joined("--outputs", outputs, join_with = ",")
+ if dwp_file:
+ args.add("--dwp_file", dwp_file)
+ inputs = inputs + [dwp_file]
+
+ py_toolchain = ctx.toolchains["@rules_python//python:toolchain_type"]
+ python_path = py_toolchain.py3_runtime.interpreter.path
+ env = dict(ctx.configuration.default_shell_env)
+ env["PATH"] = "%s:/usr/bin:/bin" % python_path.rpartition("/")[0]
ctx.actions.run(
- inputs = ctx.files.cc_target,
+ inputs = inputs + py_toolchain.py3_runtime.files.to_list(),
outputs = outputs,
- arguments = [args],
executable = ctx.executable._wasm_binary_extractor,
+ arguments = [args],
+ env = env,
)
return [
@@ -202,6 +222,7 @@ def _wasm_binary_legacy_outputs(name, cc_target):
"data": "{}/{}.data".format(name, basename),
"symbols": "{}/{}.js.symbols".format(name, basename),
"dwarf": "{}/{}.wasm.debug.wasm".format(name, basename),
+ "dwp": "{}/{}.wasm.dwp".format(name, basename),
"html": "{}/{}.html".format(name, basename),
"audio_worklet": "{}/{}.aw.js".format(name, basename)
}
@@ -212,6 +233,7 @@ _wasm_cc_binary_legacy = rule(
implementation = _wasm_cc_binary_legacy_impl,
attrs = _WASM_BINARY_COMMON_ATTRS,
outputs = _wasm_binary_legacy_outputs,
+ toolchains = ["@rules_python//python:toolchain_type"],
)
# Wraps a C++ Blaze target, extracting the appropriate files.