running and debugging rust code from the windows operating system
For a hobby project, I will likely need to build a COM interface, for a screen reader integration, and doing so in python would be annoying to say the least. I therefore decided I might take a stab at implementingn it in rust for personal development, and rust seems more interesting than c++. I recently ran into an annoying issue trying to configure vscode debugging and running on windows. Here is how to get up and running and avoid a major pitfall.
prerecs
Once rust-analyzer is installed, either install microsoft build tools, visual studio, or gcc with bash on either wsl or git for bash. I used msvc build tools because the screen reader I'm hacking uses these as prerecs to build the screen reader. Once these are installed, set up a launch configuration.
launch Configuration
Open a rust file, bring up the command pallet and ask for launch configuration. or, press ctrl+f5 and it'll tell you to configure. There are multiple ways to get a launch.json.
From the new launch.json, configure the following.
{ "configurations": [ { "name": "(Windows) Launch", "type": "cppvsdbg", "request": "launch", "program": "${workspaceFolder}/target/debug/${workspaceFolderBasename}.exe", "args": [], "stopAtEntry": false, "cwd": "${fileDirname}", "environment": [], "console": "integratedTerminal" } ] }
This launch is pretty basic. However, the default snippet from windows uses an external terminal, and trying to run that config will cause electron to hickup and try passing some weird sequence of args. See this bug for more details. The unfortunate reality is that you just have to use integrated terminal.
If it worked
Pressing control+f5 should bring up a terminal and run the program. I assume the workspace folder is configured properly, changing program above may be necessary based on specific project requirements. Pressing f5 will bring up a debugger. Breakpoints and stepping all seem to work and stacks seem to work. Howver, there may be stack frames in rust land that don't directly translate to c, I saw several frames that were related to other things. happy hacking!