- At least 5-10 GiB of free disk space.
- First follow the general instructions for setting up https://github.com/ddnet/ddnet for building on Linux.
- Install and activate the latest 4.x version of the Emscripten SDK (emsdk). To that end, run the following commands within the folder where the emsdk should be installed:
Refer to the Emscripten documentation for details about using and updating the Emscripten SDK. Note: Installing Emscripten from the package manager (e.g. with
git clone https://github.com/emscripten-core/emsdk.git cd emsdk ./emsdk install 4.0.22 ./emsdk activate 4.0.22sudo apt install emscripten) may not work, as building some libraries requires a different version of Emscripten than is available via package manager. - Use a stable version of Rust. Using the nightly version results in linking errors.
Note that using Rust versions 1.90.0 - 1.93.0 specifically does not work.
For reproducible builds, use exactly the same version of Rust that is used in the CI:
rustup default 1.89.0
- Add the WASM targets to rustup to build Rust with Emscripten after setting the Rust version:
rustup target add wasm32-unknown-emscripten
- Build the
ddnet-libsvia Emscripten. See below for instructions on how to compile them locally. Alternatively, use the precompiled libraries from https://github.com/ddnet/ddnet-libs/. The libraries can also be built by manually running the GitHub workflowbuild-libraries-emscripten. - Important note for reproducible builds: To make the build reproducible, you must use exactly the same versions of the emsdk and Rust. Furthermore, exactly CMake version 3.22.1 must be used for configuring.
- To use the emsdk within a terminal in the later steps, run
source .../emsdk/emsdk_env.shonce in the terminal (with the correct path to the emsdk) to setup the environment variables.
- Building the DDNet client via Emscripten is currently not directly possible on Windows, due to CMake issue 25049.
On Windows, the CMake Ninja and Makefile generators mangle
$signs in the link options, which are required for theDEFAULT_LIBRARY_FUNCS_TO_INCLUDEflag. This causes the linking step to either fail due to incorrectly escaped arguments or the client will not launch because SDL cannot find the relevant functions that should have been made accessible by setting theDEFAULT_LIBRARY_FUNCS_TO_INCLUDEflag. - If you are motivated, it is possible to manually fix up and run the linking command with correct arguments, which allows building and running the client successfully on Windows.
- Note for building on Windows: All commands in this README must be executed in a
bashterminal (e.g., from MSYS2) and not incmd.exeor PowerShell. - On Linux, install the following dependencies:
sudo apt install autoconf automake libtool m4
- On Windows using MSYS2, install the following dependencies:
pacman -S autoconf-wrapper automake-wrapper libtool unzip
- There is a script to automatically download and build all libraries.
This requires an active internet connection and can take around 10-20 minutes:
Warning: Do not choose a directory inside the
scripts/compile_libs/gen_libs.sh build-webasm-libs webasm
srcfolder! - If you see error messages in the first few minutes, examine the output and ensure that you installed the emsdk and other prerequisites correctly.
- After the script finished executing, it should have created a
ddnet-libsdirectory in your selected output folder, which contains all libraries in the correct directory format and can be merged with theddnet-libsfolder in the source directory:find ddnet-libs -type d -name webasm -exec rm -r {} + -prune cp -r build-webasm-libs/ddnet-libs/. ddnet-libs/ - To force the libraries to be rebuild, delete the individual build folders inside the library folders:
rm -rf build-webasm-libs/compile_libs/*/build_webasm_*
- To force the libraries to be downloaded again when changing the library versions, delete the entire library build folder:
rm -rf build-webasm-libs
- Create a new directory to build the client in.
- Then run
emcmake cmake .. -G "Unix Makefiles" -DVIDEORECORDER=OFF -DVULKAN=OFF -DSERVER=OFF -DTOOLS=OFF -DPREFER_BUNDLED_LIBS=ONin your build directory to configure followed bycmake --build . -j8to build. - For testing it is highly recommended to build in debug mode by also passing the argument
-DCMAKE_BUILD_TYPE=Debugwhen invokingemcmake cmake, as this speeds up the build process and adds debug information as well as additional checks. - Note that using the Ninja build system with Emscripten is not currently possible due to CMake issue 16395.
- To test the compiled code locally, run
emrun --browser firefox index.htmlin the build directory. - To host the compiled Emscripten client, copy the
DDNet.data,DDNet.js,DDNet.wasmandindex.htmlfiles from the build directory to the web server. The fileindex.htmlin the build folder is copied fromother/emscripten/index.html. - You can also run
other/emscripten/server.pyto host a minimal server for testing using Python without needing to install Emscripten. - When using a proper web server, enable cross-origin policies to allow the client to download its components.
For example for apache2 on Debian-based distributions:
Edit the apache2 config to allow
sudo a2enmod header
.htaccessfiles:Setsudo nano /etc/apache2/apache2.conf
AllowOverridetoAllfor your directory in the editor. Then create a.htaccessfile on the web server (where theindex.htmlis) and add these lines it:Now restart apache2:Header add Cross-Origin-Embedder-Policy "require-corp" Header add Cross-Origin-Opener-Policy "same-origin"sudo service apache2 restart
- Make sure that the
CCandCXXvariables are not set in your shell environment, because this will interfere with the compiler selection of the emsdk.