-
Notifications
You must be signed in to change notification settings - Fork 103
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.
The following steps use libwasmvm_muslc.x86_64.a
for succinctness, but it works the same way for libwasmvm_muslc.aarch64.a
.
- Download them from GitHub releases to your build system
- 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 tolibwasmvm_muslc.a
before, but this is not necessary anymore. - Add the build flags
-linkmode=external -extldflags '-Wl,-z,muldefs -static'
andmuslc
tag to youtgo build
command, e.g.Before the upgrade to Rust 1.56.0+, the resulting binary was statically linked by default. Now we have to be explicit.go build -ldflags "-linkmode=external -extldflags '-Wl,-z,muldefs -static'" -tags muslc \ -o demo ./cmd/demo
- 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.
To learn more about linking with Go, we recommend the following ressources:
- "2. If you really need CGO, but not netcgo" in https://dubo-dubon-duponey.medium.com/a-beginners-guide-to-cross-compiling-static-cgo-pie-binaries-golang-1-16-792eea92d5aa
- For why we need
-Wl,-z,muldefs
: https://github.com/rust-lang/rust/issues/78919 - Advanced Go binary builds: https://wiki.archlinux.org/title/Go_package_guidelines