Developing Weblib with VS Code on Windows
Prerequisites
- Download and install VSCode from https://code.visualstudio.com/download# . Choose the "System Installer" to prevent every user from having to store an instance in their
AppDatadirectory. - Install C/C++ Extension Pack and WebAssembly DWARF Debugging extensions
Building
Install requirements via ConanandConfigure PEPas detailed in thequickstart.mddocument.- Run
build\wasm32\Debug\generators\conanbuild.batto set environment variables, then start VSCode from that same command line:"C:\Program Files\Microsoft VS Code\Code.exe". Unfortunately it'll spam some (apparently error) logging to this console. - Open the project directory in VSCode. Wait until the
OUTPUTfor[cmake]completes withBuild files have been written [...]. - Click the
CMakeicon in the LHS panel, then right-click the target you want to build and chooseSet Build Targetfrom the context menu. - Click the
Buildbutton on the CMake toolbar (at the bottom of the IDE) to build your target.
Debugging
VSCode provides two ways to debug targets: a native one (accessed through the "Run and Debug" icon in the LHS panel) and one based on CMake (accessed through the CMake toolbar (at the bottom of the IDE). These instructions are based on VSCode's native debugging support.
- Click the "Run and Debug" icon in the LHS panel, then click the "Create a launch.json file" link. Choose "Node.js" debugger from dropdown. (If the dropdown doesn't contain this entry, close all open documents and try again.)
- Find the "sample
launch.jsonconfiguration" indeveloping.mdand paste its contents into thelaunch.jsonfile as an entry in theconfigurationsarray. - Check the
Uncaught Exceptionscheckbox in theRUN AND DEBUGpanel'sBREAKPOINTSsection. You may also want to set a breakpoint somewhere in (PEP) code. - Note that the debugger (apparently) takes a while to attach, causing breakpoints to be skipped if they are set on code that's executed early in the application lifecycle. You may want to delay execution of the code you're interested in, e.g. by adding astd::this_thread::sleep_for(std::chrono::seconds(1));call. Keep in mind that some (a.o. static initialization) code runs before entering themainfunction. - Click the
Start debuggingbutton from the main toolbar (at the top of the IDE). (Do not use theLaunch the debugger[...]button on the CMake toolbar, since it'll produce a popup sayingNo compiler found in cache file.) - If you've also enabled breakpoints for
Caught Exceptions(i.e. you've checked that checkbox), the debugger will break on a bunch of exceptions thrown from bootstrapping code:throw new FS.ErrnoError(44);. These exceptions are eaten by calling code (inObject.mayCreate) and can be ignored.