Skip to content

Developing Weblib with VS Code on Windows

Prerequisites

  1. 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 AppData directory.
  2. Install C/C++ Extension Pack and WebAssembly DWARF Debugging extensions

Building

  1. Install requirements via Conan and Configure PEP as detailed in the quickstart.md document.
  2. Run build\wasm32\Debug\generators\conanbuild.bat to 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.
  3. Open the project directory in VSCode. Wait until the OUTPUT for [cmake] completes with Build files have been written [...].
  4. Click the CMake icon in the LHS panel, then right-click the target you want to build and choose Set Build Target from the context menu.
  5. Click the Build button 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.

  1. 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.)
  2. Find the "sample launch.json configuration" in developing.md and paste its contents into the launch.json file as an entry in the configurations array.
  3. Check the Uncaught Exceptions checkbox in the RUN AND DEBUG panel's BREAKPOINTS section. 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 a std::this_thread::sleep_for(std::chrono::seconds(1)); call. Keep in mind that some (a.o. static initialization) code runs before entering the main function.
  4. Click the Start debugging button from the main toolbar (at the top of the IDE). (Do not use the Launch the debugger[...] button on the CMake toolbar, since it'll produce a popup saying No compiler found in cache file.)
  5. 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 (in Object.mayCreate) and can be ignored.