Skip to content

Commit 57e9d91

Browse files
fkrause98igamigommagician
authored
docs: document wasm debug process (0xMiden#1341)
* docs: document wasm debug process * docs: debug * lint: fix typo * fix: extension link * pr-comments: more details in guide * Update crates/web-client/docs/debug.md Co-authored-by: igamigo <ignacio.amigo@lambdaclass.com> * trigger workflow * trigger workflow * Apply suggestions from code review Co-authored-by: igamigo <ignacio.amigo@lambdaclass.com> * remove bullet point * run tests with release mode * chore: update test:clean target * feat: re-do debug symbols setup * feat: restore package.json from next * Update crates/web-client/docs/debug.md Co-authored-by: Marti <marti@miden.team> * Update crates/web-client/docs/debug.md Co-authored-by: Marti <marti@miden.team> * Update crates/web-client/docs/debug.md Co-authored-by: Marti <marti@miden.team> * Update crates/web-client/docs/debug.md Co-authored-by: Marti <marti@miden.team> * pr-comments * format * fix md formatting * docs: pr feedback --------- Co-authored-by: igamigo <ignacio.amigo@lambdaclass.com> Co-authored-by: Marti <marti@miden.team>
1 parent c1b486c commit 57e9d91

File tree

8 files changed

+77
-1
lines changed

8 files changed

+77
-1
lines changed

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,12 @@ install-tools: ## Installs Rust + Node tools required by the Makefile
211211
yarn --silent
212212
yarn
213213
@echo "Development tools installation complete!"
214+
215+
## --- Debug --------------------------------------------------------------------------------------
216+
.PHONY: build-web-client-debug
217+
build-web-client-debug: # build the web-client with debug symbols for the WASM-generated rust code
218+
cd crates/web-client && yarn build-dev
219+
220+
.PHONY: link-web-client-dep
221+
link-web-client-dep: # links the local web-client for debugging JS applications.
222+
cd crates/web-client && yarn link
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Debugging WASM
2+
3+
When debugging WASM, it can be tricky to trace the origin of an error since stack traces are not often noisy and difficult to read.
4+
To better trace these errors, a build with debug symbols can be generated. This doc explains how to set it up.
5+
6+
## Requirements
7+
- yarn
8+
- Compatible Rust version
9+
- Chrome browser
10+
- [wasm-debugging-extension](https://goo.gle/wasm-debugging-extension).
11+
12+
## Building with debug symbols
13+
14+
1. Clone the miden-client repo:
15+
```bash
16+
git clone git@github.com:0xMiden/miden-client.git
17+
```
18+
2. Build miden-client with debug-symbols:
19+
```bash
20+
make build-web-client-debug
21+
```
22+
Once it finishes, the Rust build log should print this:
23+
```
24+
Finished `release` profile [optimized + debuginfo] target(s) in 38.33s
25+
```
26+
27+
## Using the debug symbols
28+
29+
Once you have both the debug WASM and the Chrome extension, we need to link
30+
the dependency to the JS app we're debugging.
31+
32+
1. Once you have the web client built with debug symbols, we have to use it as a dependency,
33+
for that we'll use [yarn link](https://classic.yarnpkg.com/lang/en/docs/cli/link/),
34+
run this in your local copy of miden-client:
35+
```
36+
make link-web-client-dep
37+
```
38+
2. Then, run this command in the root of the project that needs to be debugged:
39+
```
40+
yarn link "@demox-labs/miden-sdk"
41+
```
42+
Essentially,`yarn link` makes the project use the local modified version of the sdk instead of the NPM hosted one. Now, when you open the devtools with chrome, you will see an output like this:
43+
44+
45+
![dev-tools-output](./devtools-output.png).
46+
47+
48+
You should also be able to see the rust source in the devtools source tab:
49+
![source-example](./source-example.png)
50+
51+
52+
Also, you should see friendlier stack-traces:
53+
![stack-trace-example](./stack-trace-example.png)
64.9 KB
Loading
919 KB
Loading
484 KB
Loading

crates/web-client/rollup.config.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ import copy from "rollup-plugin-copy";
66
// Flag that indicates if the build is meant for development purposes.
77
// If true, wasm-opt is not applied.
88
const devMode = process.env.MIDEN_WEB_DEV === "true";
9+
10+
// Arguments to tell cargo to add debug symbols
11+
// to the generated .wasm file.
12+
const cargoArgsUseDebugSymbols = [
13+
// Generate debug symbols for the release cargo profile.
14+
"--config",
15+
"profile.release.debug='full'",
16+
// Do not remove debug symbols from the final binary,
17+
"--config",
18+
"profile.release.strip='none'",
19+
];
20+
921
const wasmOptArgs = [
1022
devMode ? "-O0" : "-O3",
1123
"--enable-bulk-memory",
@@ -19,7 +31,7 @@ const baseCargoArgs = [
1931
"--config",
2032
`build.rustflags=["-C", "target-feature=+atomics,+bulk-memory,+mutable-globals", "-C", "link-arg=--max-memory=4294967296", "-C", "panic=abort"]`,
2133
"--no-default-features",
22-
];
34+
].concat(devMode ? cargoArgsUseDebugSymbols : []);
2335

2436
/**
2537
* Rollup configuration file for building a Cargo project and creating a WebAssembly (WASM) module,
@@ -59,6 +71,8 @@ export default [
5971
extraArgs: {
6072
cargo: [...baseCargoArgs],
6173
wasmOpt: wasmOptArgs,
74+
// Keep debug symbols if in dev mode.
75+
wasmBindgen: devMode ? ["--keep-debug"] : [],
6276
},
6377
experimental: {
6478
typescriptDeclarationDir: "dist/crates",
64.8 KB
Loading
64.8 KB
Loading

0 commit comments

Comments
 (0)