Skip to content

Linking wasmvm_muslc

Simon Warta edited this page Mar 26, 2022 · 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

  1. Download them from GitHub releases to your build system
  2. Rename to libwasmvm_muslc.a. This step is important as the linker flag is always -lwasmvm_muslc, no matter which CPU type you build for. I.e. the linker would not find libwasmvm_muslc.aarch64.a or libwasmvm_muslc.x86_64.a directly.
  3. Move libwasmvm_muslc.a to a default library folder of your system (e.g. /lib for Alpine Linux).
  4. 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.
  5. 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