Developing PEP Weblib: Quickstart
This page more concretely lays out the steps to get started developing the PEP Weblib. For more info, see the PEP Weblib: development document.
Prepare your machine
Install prerequisites
Install Nginx and the websockify Python package (e.g. via pipx). For Windows, use winget install nginxinc.nginx (or freenginx.nginx).
Obtain the Emscripten SDK
Emscripten version
Currently, Emscripten ≥4.0.23 blocks too long while waiting for WebSocket traffic, see this issue. Until this is resolved, use version 4.0.22 instead.
Node.js
When Node.js is already installed on the system (node is in PATH), EMSDK will not add its version to PATH, and we assume npm also available with your existing installation.
Option 1: Manual install
Just follow the steps in the Emscripten docs. Make sure to source the environment file in your build shell, and check if the EMSDK envvar is indeed set.
Option 2: Via Conan
Clone conan-io/conan-toolchains and set it up as a local recipe index repository as described in the Conan README.
Create a Conan host profile that you will be using to compile WebAssembly. E.g. place a file wasm32 in ~/.conan2/profiles/ and give it the following contents. Replace the include path by the actual path to the conan_profile_wasm32 file in your core/docker_build subdirectory. Substitute 4.0.22 by the specific version you want to use.
{% set compiler_version = '4.0.22' %}
include(C:\PepSrc\pep\core-3\docker-build\builder\conan\conan_profile_wasm32)
[settings]
# This line should be below `compiler=...`
compiler.version={{compiler_version}}
[tool_requires]
emsdk/{{compiler_version}}
Adapting Conan profiles from docker-build
When adapting Conan profiles in docker-build, you can either copy them (plus included files) to ~/.conan2/profiles/, or create a new profile there and include the one from docker-build via include(/path/to/docker-build/conan_profile).
Configure and build
Install requirements via Conan
As host profile, you can use or include ./docker-build/builder/conan/conan_profile_wasm32, which automatically detects the EMSDK in your environment.
Emscripten version detection
Please make sure you have Conan 2.27 or later for detect_emcc_compiler to work correctly.
Windows quirks
- When installing EMSDK via Conan, you may get "Command line too long", e.g. when it calls
emarwhile building OpenSSL. In this case, patch this line in their emsdk recipe (in your local recipe index repository):And then add104c104 < self.buildenv_info.define_path("AR", self._define_tool_var("emar")) --- > self.buildenv_info.define_path("AR", f'"{os.path.join(self.package_folder, "bin", "upstream", "bin", "llvm-ar")}"')--build="esmdk/*"to theconan installcommand (below).
From your git repository's root directory:
conan install \
--profile=wasm32 \
-s"&:build_type=Debug" \
--build=missing \
-o"&:subbuild_name=wasm32"
- If you get an
ERROR: It's not possible to compose str values and list ones.you may be invoking theconan installcommand from a shell in which you've previously activated the conan build environment, e.g. by runningbuild\wasm32\Debug\generators\conanbuild.baton Windows, while you installed EMSDK via Conan. Fix this by using a fresh shell instead. - If you did not install EMSDK via Conan, you can use
--profile=./docker-build/builder/conan/conan_profile_wasm32as you didn't need to create a customwasm32profile --profile==--profile:host: the target platform- Also add
--profile:build=./docker-build/builder/conan/conan_profileif you have no default build profile installed (see pep/core> README) -s"&:build_type=Debug": Same as normal, this builds pep as Debug, but dependencies as Release according to the profilesubbuild_nameis a pep option: build in subfolder./build/wasm32/Debug/
Configure PEP
To be able to build the PEP services for the WASM client to communicate with, first install dependencies and configure PEP as you would normally do to develop PEP on your platform, see README.md.
Then (from the repo root directory) configure the WASM build as shown below. The value for PKI_DIR should point to the PKI directory of the regular build that you just configured. This will allow you to test with local servers, without which you will likely see boost::system::system_error: certificate verify failed (SSL routines) when connecting.
cmake --preset=wasm32-debug -DPKI_DIR=./build/pki/
Build & run sample page
Windows quirks
- To use scripts like
start_dev.sh, you'll need to open e.g. Git Bash, but- The
build\wasm32\Debug\generators\conanbuild.batscript generated will not be compatible with Git Bash. Instead, source (run) it in the appropriate Windows shell and then start Git Bash from that same shell by invoking"C:\Program Files\Git\bin\bash".
- The
- When using PowerShell, sourcing
conanbuild.batwill not work. Instead, set e.g.-c tools.env.virtualenv:powershell=...according to the docs and sourceconanbuild.ps1. - Nginx may not go to the background or want to shut down with ctrl+C, kill it via the task manager instead.
- websockify may log
WARNING: no 'resource' module, daemonizing is disabled. This can be ignored.
If you installed EMSDK via Conan, you need to put Node.js in PATH by sourcing the generators/conanbuild script from your wasm32 build folder.
The following script first builds the PEP services for your platform, then builds the weblib and starts the PEP services and a web server. If you are not using a Debug configuration (for the weblib or the PEP services), you need to pass extra arguments to the script (try --help).
./weblib/pep-sample-client/start_dev.sh
Now you can finally open http://localhost:2280/weblib/pep-sample-client/ in your browser. Try to log in as Research Assessor and list columns, for example.
IDE
To develop the weblib, you may want to try one of these IDEs:
- JetBrains CLion (has both C++ and web support via default plugins)
- In the CMake panel, activate presets for both the native and the wasm32 build
- Select the active preset and target in the top right
- Microsoft VSCode with C/C++ Extension Pack and optionally WebAssembly DWARF Debugging extensions (see PEP Weblib: development for debugging instructions)
Both also have support for developing remotely with SSH.