Skip to content

Lind toolchain

The toolchain to build and run lind programs consists of the following components:

  • Clang with WebAssembly System Interface (WASI) support to build glibc and lind programs
  • A custom glibc used as sysroot to build lind programs
  • A custom wasm-opt binary to enable multi-processing in lind programs
  • A custom WebAssembly runtime (wasmtime) with RawPOSIX to run lind programs
  • Cargo to build wasmtime

This document gives an overview of how the toolchain is built. The build process is automated with Docker, Bazel and custom shell scripts. Please refer to the relevant files linked below for details about the build commands and used options.

Building the toolchain step by step

  1. Install system dependencies (see apt in Dockerfile)

  2. Download Clang and install builtins (see wget and cp in Dockerfile)

    Clang supports the WASI cross-compilation target out of the box, provided the necessary compiler runtime builtins and a matching sysroot. See wasi-sdk docs for details.

    A pre-built Clang can be downloaded from the llvm-project releases page. Matching builtins are available in the lind-wasm repo under src/glibc/wasi.

  3. Build glibc and generate sysroot (see make_glibc in BUILD file)

    1. Configure and compile glibc for the WASI target with Clang. (see wasm-config.sh)

    2. Compile extra files:

      • nptl/pthread_create.c
      • lind_syscall/lind_syscall.c
      • csu/wasm32/wasi_thread_start.s
      • csu/wasm32/set_stack_pointer.s
    3. Generate sysroot

      Combine the built object files into a single archive file and copy along with headers and a pre-built C runtime into a sysroot directory structure as required by Clang. (see gen_sysroot.sh)

  4. Build custom wasmtime (see make_wasmtime in BUILD)

    Build with cargo build from within src/wasmtime. Custom dependencies fdtables, RawPOSIX and sysdefs are included in the build automatically via Cargo workspace dependencies. (see Cargo.toml)

A customized wasm-opt binary is included in the lind-wasm repo under tools/binaryen/bin and can be used as is.

Automation with Docker

Run the following Docker command from within the lind-wasm repo to create a Docker image with the full toolchain.

docker build -t lind-wasm -f .devcontainer/Dockerfile --platform=linux/amd64 .

Next steps

Take a look at how to compile and run programs to see the toolchain in action.