Testing Versions
- Veilid 1fff6cfd (2023-08-22)
- cargo 1.71.0
- wasm-bindgen 0.2.87
- wasm-strip 1.0.31
- python 3.11.3
- llvm-dwarfdump 15.0.7
Have you read The Dev Guide?
I can’t complain about learning the hard way - it’s a great way to learn - but before you follow my fallible foolish footsteps, consider skipping all this stuff with a simple and snappy setup.sh.
That being said, imo there is value in this, even if it’s academic.
Make sure you’ve Cloned the Repo with git submodules.
Install Dependencies
capnproto
The veilid-core build script checks capnp --version
prior to compilation.
The capnp
executable is written in c++, and is distributed via distro package managers. Install on:
- Debian/Ubuntu:
apt-get install capnproto
- Arch:
sudo pacman -S capnproto
- Mac:
brew install capnp
CapnProto’s Install Docs are Awesome
wasm-bindgen
Generates javascript / typescript bindings to a wasm library’s public functions.
The wasm-bindgen
executable is provided by wasm-bindgen-cli
, which can be installed with cargo:
cargo install wasm-bindgen-cli
wasm-strip
Removes unnecessary sections to optimize wasm blobs for size.
The wasm-strip
executable comes from the excellent WebAssembly Binary Toolkit “WABT” project, which is distributed via distro package managers as wabt
. This comes with a number of other wasm tools. Install on:
- Debian/Ubuntu:
apt-get install wabt
- Arch:
sudo pacman -S wabt
- Mac: Not Tested
Python 3 (Debug Only)
Used to generate the debug sourcemap using llvm-dwarfdump
.
- Debian/Ubuntu:
apt-get install python
- Arch:
sudo pacman -S python
- Mac: Not Tested
LLVM-DwarfDump (Debug Only)
Extracts embedded debug information. Used to generate sourcemaps for debug builds.
Part of the LLVM compiler toolset. Install on:
- Debian/Ubuntu: Not Tested
- Arch:
sudo pacman -S llvm
- Mac: Not Tested
Build with the release profile
Note that this will embed your working directory and username into the compiled wasm.
/home/username/penname/projects/veilid/unreleasedprojectname/$environment/$user's_fork/veilid/
Use exactly “release
“, case-sensitive.
/home/USER/.../veilid/veilid-wasm/wasm_build.sh release
Build for Release manually
Here are the steps I used to replicate what wasm_build.sh
does - I have an article on Dissecting wasm-build.sh that goes into way too much detail:
cd /home/USER/.../veilid/veilid-wasm/
cargo build --target wasm32-unknown-unknown --release
WASMDIR=../target/wasm32-unknown-unknown/release
mkdir $WASMDIR/pkg
wasm-bindgen --out-dir $WASMDIR/pkg --target web $WASMDIR/veilid_wasm.wasm
wasm-strip $WASMDIR/pkg/veilid_wasm_bg.wasm
Build with the debug profile
Run wasm_build.sh
with no parameters (or any - as long as it’s not release
).
/home/USER/.../veilid/veilid-wasm/wasm_build.sh
Build for Debug manually
cd /home/USER/.../veilid/veilid-wasm/
RUSTFLAGS="-O -g" cargo build --target wasm32-unknown-unknown
WASMDIR=../target/wasm32-unknown-unknown/debug
mkdir $WASMDIR/pkg
wasm-bindgen --out-dir $WASMDIR/pkg --target web --keep-debug --debug $WASMDIR/veilid_wasm.wasm
python3 wasm-sourcemap.py $WASMDIR/pkg/veilid_wasm_bg.wasm -o $WASMDIR/pkg/veilid_wasm_bg.wasm.map --dwarfdump /usr/bin/llvm-dwarfdump
Sizes
Building with the release profile (and running wasm-strip) makes a huge difference:
Profile | After Step | Size |
---|---|---|
release | cargo build | 8.5MB |
release | wasm-bindgen | 5.6MB |
release | wasm-strip | 4.4MB |
debug | cargo build | 197MB |
debug | wasm-bindgen | 195MB |