Reputation: 43
I am writing Rust and WebAssembly program. I wanted to debug Rust and WebAssembly program with VSCode and CodeLLDB, but I got an error. I can debug simple Rust program, but fail to debug Rust and WebAssembly program. Steps to reproduce the error are shown below.
Clone the Rust and WebAssembly project template with this command:
cargo generate --git https://github.com/rustwasm/wasm-pack-template
Then, type the project name. I used "foo". Add a test in foo/src/lib.rs
mod utils;
use wasm_bindgen::prelude::*;
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
// allocator.
#[cfg(feature = "wee_alloc")]
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
#[wasm_bindgen]
extern {
fn alert(s: &str);
}
#[wasm_bindgen]
pub fn greet() {
alert("Hello, foo!");
}
// add this test.
#[test]
fn foo_test() {
assert_eq!(1, 1);
}
Place a breakpoint at foo_test(). Then, create a launch.json file.
.vscode/launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in library 'foo'",
"cargo": {
"args": [
"test",
"--no-run",
"--lib",
"--package=foo"
],
"filter": {
"name": "foo",
"kind": "lib"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug integration test 'web'",
"cargo": {
"args": [
"test",
"--no-run",
"--test=web",
"--package=foo"
],
"filter": {
"name": "web",
"kind": "test"
}
},
"args": [],
"cwd": "${workspaceFolder}"
}
]
}
After I started "Debug unit tests in library 'foo'", I got an error message, "Cargo has produced no matching compilation artifacts". What can I do to fix this error?
My setup: macOS Big Sur 11.2.3, Visual Studio Code(VSCode) 1.55.1, CodeLLDB 1.6.1, cargo 1.51.0.
Upvotes: 4
Views: 2290
Reputation: 2035
This might be not the most helpful answer, but the answer is you currently can't - there is an open issue on wasm-bindgen repo tracking future support for debugging but it's not yet supported: https://github.com/rustwasm/wasm-bindgen/issues/2389
Note that even when it will be, you'll need to use browser DevTools not CodeLLDB for WebAssembly debugging, since you need a JavaScript-capable environment.
Upvotes: 1