This repository has been archived by the owner on May 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
# Mixed Debugging Between JavaScript and Rust | ||
|
||
This discussion aims to illustrate the method for mixed debugging between JavaScript and Rust. | ||
|
||
## Prerequisites | ||
|
||
To illustrate this process, I'll use an example. Let's start by introduce the environment and example I have used. | ||
|
||
- System: macos | ||
- IDE: vscode | ||
- Debugging target: `rspack build ${projectRoot}/basic` | ||
|
||
Firstly, you need to build rspack in debug mode. To do this, execute the following commands in the project's root directory: | ||
|
||
```bash | ||
npm run build:binding:debug | ||
npm run build:js | ||
``` | ||
|
||
## Configure `launch.json` in vscode | ||
|
||
It's necessary to configure two debug configurations within `.vscode/launch.json.` | ||
|
||
- attach for node: | ||
|
||
```jsonc | ||
{ | ||
"name": "attach:node”, | ||
"request": "attach", // refer: https://code.visualstudio.com/docs/editor/debugging#_launch-versus-attach-configurations | ||
"type": "node", | ||
// `9229` is the default port of message | ||
"port": 9229 | ||
} | ||
``` | ||
- and launch for lldb | ||
```jsonc | ||
{ | ||
"name": "launch:rust-from-node", | ||
"request": "launch”, | ||
"type": "lldb", // it means we use `lldb` to launch the binary file of `node` | ||
"program": "node”, | ||
"args": [ | ||
"--inspect", | ||
"--enable-source-maps", | ||
"${workspaceFolder}/packages/rspack-cli/bin/rspack", | ||
"build", | ||
"-c", | ||
"${workspaceFolder}/examples/basic/rspack.config.js", | ||
], | ||
// `cwd` is just for repack find the correclty entry. | ||
"cwd": "${workspaceFolder}/examples/basic/" | ||
} | ||
``` | ||
Next, we can utilize [compounds](https://code.visualstudio.com/docs/editor/debugging#_compound-launch-configurations) to amalgamate the two commands: | ||
```json | ||
{ | ||
"name": "mix-debug", | ||
"configurations": [ | ||
"attach:node", | ||
"launch:rust-from-node" | ||
] | ||
} | ||
``` | ||
Finally, your `launch.json` should appear as follows: | ||
```json | ||
{ | ||
"configurations": [ | ||
{ | ||
"name": "attach:node", | ||
"request": "attach", | ||
"type": "node", | ||
"port": 9229 | ||
}, | ||
{ | ||
"name": "launch:rust-from-node", | ||
"request": "launch", | ||
"type": "lldb", | ||
"program": "node", | ||
"args": [ | ||
"--inspect", | ||
"--enable-source-maps", | ||
"${workspaceFolder}/packages/rspack-cli/bin/rspack", | ||
"build", | ||
"-c", | ||
"${workspaceFolder}/examples/basic/rspack.config.js", | ||
], | ||
"cwd": "${workspaceFolder}/examples/basic/" | ||
} | ||
], | ||
"compounds": [ | ||
{ | ||
"name": "mix-debug", | ||
"configurations": [ | ||
"attach:node", | ||
"launch:rust-from-node" | ||
] | ||
} | ||
] | ||
} | ||
``` | ||
## Debugging Attempt | ||
Next, we can introduce some breakpoints and commence debugging. | ||
The result appears as follows: | ||
<video width="640" height="480" controls> | ||
<source src="https://github.com/web-infra-dev/rspack/assets/30187863/106983f7-a59e-4d9e-9001-552f4441d88b" type="video/mp4"> | ||
Your browser does not support the video tag. | ||
</video> |