Skip to content

Linking wasmvm_muslc

Christoph Otter edited this page Feb 27, 2024 · 2 revisions

Starting with wasmvm v1.0.0-beta9, the two static library builds libwasmvm_muslc.aarch64.a and libwasmvm_muslc.x86_64.a are deployed. Those static libraries for Linux use a statically linked musl libc. The libraries are made for Alpine Linux but the resulting binaries also run on other distributions like Debian.

How to use the .a files

The following steps use libwasmvm_muslc.x86_64.a for succinctness, but it works the same way for libwasmvm_muslc.aarch64.a.

  1. Download them from GitHub releases to your build system
  2. Move libwasmvm_muslc.x86_64.a to a default library folder of your system (e.g. /lib for Alpine Linux). For versions before 2.0, you had to rename this to libwasmvm_muslc.a before, but this is not necessary anymore.
  3. Add the build flags -linkmode=external -extldflags '-Wl,-z,muldefs -static' and muslc tag to yout go build command, e.g.
    go build -ldflags "-linkmode=external -extldflags '-Wl,-z,muldefs -static'" -tags muslc \
      -o demo ./cmd/demo
    
    Before the upgrade to Rust 1.56.0+, the resulting binary was statically linked by default. Now we have to be explicit.
  4. Use file to check if the resulting binary was statically linked:
    $ file /code/build/wasmd
    ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), statically linked, Go BuildID=QN0ROsCeqcPMyxlFbUzY/hzS-Y64fQc5lRiMuUIF_/sGKzbwyqPD97q7uMHE9w/Yu9a5qtHsFDSRYK0wXTs, not stripped
    

The full integration process can be seen in this wasmd PR.

Further reading

To learn more about linking with Go, we recommend the following ressources:

Clone this wiki locally