Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Debian builder image and use for GNU linux .so files #439

Merged
merged 10 commits into from
Jul 31, 2024
7 changes: 7 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,13 @@ jobs:
- run:
name: Copy .so build
command: cp /tmp/builds/libwasmvm.x86_64.so ./internal/api
# Debugging step to better understand what is linked here
- run:
name: Check .so files
command: |
ls -lA ./internal/api/libwasmvm.*.so
sha256sum ./internal/api/libwasmvm.*.so
ldd ./internal/api/libwasmvm.x86_64.so
- run:
name: Build Go project
command: make build-go
Expand Down
21 changes: 4 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.PHONY: all build build-rust build-go test

# Builds the Rust library libwasmvm
BUILDERS_PREFIX := cosmwasm/go-ext-builder:0019
BUILDERS_PREFIX := cosmwasm/libwasmvm-builder:0100
# Contains a full Go dev environment including CGO support in order to run Go tests on the built shared library
# This image is currently not published.
ALPINE_TESTER := cosmwasm/alpine-tester:local
Expand Down Expand Up @@ -68,9 +68,6 @@ bench:

# Creates a release build in a containerized build environment of the static library for Alpine Linux (.a)
release-build-alpine:
# Builders should not write their target folder into the host file system (https://github.com/CosmWasm/wasmvm/issues/437)
rm -rf libwasmvm/target/aarch64-unknown-linux-musl/release
rm -rf libwasmvm/target/x86_64-unknown-linux-musl/release
# build the muslc *.a file
docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd)/libwasmvm:/code $(BUILDERS_PREFIX)-alpine
cp libwasmvm/artifacts/libwasmvm_muslc.x86_64.a internal/api
Expand All @@ -79,38 +76,28 @@ release-build-alpine:

# Creates a release build in a containerized build environment of the shared library for glibc Linux (.so)
release-build-linux:
# Builders should not write their target folder into the host file system (https://github.com/CosmWasm/wasmvm/issues/437)
rm -rf libwasmvm/target/x86_64-unknown-linux-gnu/release
rm -rf libwasmvm/target/aarch64-unknown-linux-gnu/release
docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd)/libwasmvm:/code $(BUILDERS_PREFIX)-centos7 build_linux.sh
docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd)/libwasmvm:/code $(BUILDERS_PREFIX)-debian build_gnu_x86_64.sh
docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd)/libwasmvm:/code $(BUILDERS_PREFIX)-debian build_gnu_aarch64.sh
cp libwasmvm/artifacts/libwasmvm.x86_64.so internal/api
cp libwasmvm/artifacts/libwasmvm.aarch64.so internal/api
make update-bindings

# Creates a release build in a containerized build environment of the shared library for macOS (.dylib)
release-build-macos:
# Builders should not write their target folder into the host file system (https://github.com/CosmWasm/wasmvm/issues/437)
rm -rf libwasmvm/target/x86_64-apple-darwin/release
rm -rf libwasmvm/target/aarch64-apple-darwin/release
docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd)/libwasmvm:/code $(BUILDERS_PREFIX)-cross build_macos.sh
cp libwasmvm/artifacts/libwasmvm.dylib internal/api
make update-bindings

# Creates a release build in a containerized build environment of the static library for macOS (.a)
release-build-macos-static:
# Builders should not write their target folder into the host file system (https://github.com/CosmWasm/wasmvm/issues/437)
rm -rf libwasmvm/target/x86_64-apple-darwin/release
rm -rf libwasmvm/target/aarch64-apple-darwin/release
docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd)/libwasmvm:/code $(BUILDERS_PREFIX)-cross build_macos_static.sh
cp libwasmvm/artifacts/libwasmvmstatic_darwin.a internal/api/libwasmvmstatic_darwin.a
make update-bindings

# Creates a release build in a containerized build environment of the shared library for Windows (.dll)
release-build-windows:
# Builders should not write their target folder into the host file system (https://github.com/CosmWasm/wasmvm/issues/437)
rm -rf libwasmvm/target/x86_64-pc-windows-gnu/release
docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd)/libwasmvm:/code $(BUILDERS_PREFIX)-cross build_windows.sh
cp libwasmvm/target/x86_64-pc-windows-gnu/release/wasmvm.dll internal/api
cp libwasmvm/artifacts/wasmvm.dll internal/api
make update-bindings

update-bindings:
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ go build .
CGO_ENABLED=0 go build .
```

In the case that it may be desirable to compile with cgo, but with libwasmvm linking disabled an additional build tag is available.
In the case that it may be desirable to compile with cgo, but with libwasmvm
linking disabled an additional build tag is available.

```sh
# Build with CGO, but with libwasmvm linking disabled
Expand All @@ -106,8 +107,8 @@ The Rust implementation of the VM is compiled to a library called libwasmvm.
This is then linked to the Go code when the final binary is built. For that
reason not all systems supported by Go are supported by this project.

Linux (tested on Ubuntu, Debian, and CentOS7, Alpine) and macOS is supported. We
are working on Windows (#288).
Linux (tested on Ubuntu, Debian, Alpine) and macOS is supported. We are working
on Windows support with very low priority (#288).

[#288]: https://github.com/CosmWasm/wasmvm/pull/288

Expand Down
36 changes: 36 additions & 0 deletions builders/Dockerfile.debian
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Use a debian version that is old enough to lead to a low
# glibc requirement of builds.
# Debian 11 "Bullseye" has long-term support until August 31st, 2026
FROM --platform=linux/amd64 debian:11-slim

RUN apt update -y \
&& apt install -y gcc make gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu wget

# GET FROM https://github.com/rust-lang/docker-rust-nightly
ENV RUSTUP_HOME=/usr/local/rustup \
CARGO_HOME=/usr/local/cargo \
PATH=/usr/local/cargo/bin:$PATH

RUN wget --no-verbose "https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-gnu/rustup-init" \
&& chmod +x rustup-init \
&& ./rustup-init -y --no-modify-path --profile minimal --default-toolchain 1.77.0 \
&& rm rustup-init \
&& chmod -R a+w $RUSTUP_HOME $CARGO_HOME \
&& rustup --version \
&& cargo --version \
&& rustc --version \
&& chmod -R 777 /usr/local/cargo \
&& rustup target add aarch64-unknown-linux-gnu

## COPY BUILD SCRIPTS

WORKDIR /code

COPY guest/*.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/*.sh

RUN mkdir /.cargo
RUN chmod +rx /.cargo
COPY guest/cargo-config /.cargo/config

CMD ["bash", "-c", "echo 'Argument missing. Pass one build script (e.g. build_linux.sh) to docker run' && exit 1"]
12 changes: 6 additions & 6 deletions builders/Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Versioned by a simple counter that is not bound to a specific CosmWasm version
# See builders/README.md
BUILDERS_PREFIX := cosmwasm/go-ext-builder:0019
BUILDERS_PREFIX := cosmwasm/libwasmvm-builder:0100
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better name


.PHONY: docker-image-centos7
docker-image-centos7:
docker build --pull . -t $(BUILDERS_PREFIX)-centos7 -f ./Dockerfile.centos7
.PHONY: docker-image-debian
docker-image-debian:
docker build --pull . -t $(BUILDERS_PREFIX)-debian -f ./Dockerfile.debian

.PHONY: docker-image-cross
docker-image-cross:
Expand All @@ -15,10 +15,10 @@ docker-image-alpine:
docker build --pull . -t $(BUILDERS_PREFIX)-alpine -f ./Dockerfile.alpine

.PHONY: docker-images
docker-images: docker-image-centos7 docker-image-cross docker-image-alpine
docker-images: docker-image-debian docker-image-cross docker-image-alpine

.PHONY: docker-publish
docker-publish: docker-images
docker push $(BUILDERS_PREFIX)-cross
docker push $(BUILDERS_PREFIX)-centos7
docker push $(BUILDERS_PREFIX)-debian
docker push $(BUILDERS_PREFIX)-alpine
12 changes: 10 additions & 2 deletions builders/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,21 @@ any machine that can run Docker can do the cross-compilation.

## Docker Hub images

See https://hub.docker.com/r/cosmwasm/go-ext-builder/tags for all available
versions of the builder images.
See those DockerHub repos for all available versions of the builder images.

- From version 0100: https://hub.docker.com/r/cosmwasm/libwasmvm-builder/tags
- Before version 0100: https://hub.docker.com/r/cosmwasm/go-ext-builder/tags

## Changelog

**Unreleased**

**Version 0100:**

- Rename builder image from cosmwasm/go-ext-builder to
cosmwasm/libwasmvm-builder
- Replace CentOS with Debian image for GNU linux builds

**Version 0019:**

- Bump `OSX_VERSION_MIN` to 10.15.
Expand Down
5 changes: 3 additions & 2 deletions builders/guest/build_gnu_aarch64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
set -o errexit -o nounset -o pipefail

export CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse
export TARGET_DIR="/target" # write to /target in the guest's file system to avoid writing to the host

# No stripping implemented (see https://github.com/CosmWasm/wasmvm/issues/222#issuecomment-2260007943).

Expand All @@ -14,5 +15,5 @@ export AR_aarch64_unknown_linux_gnu=llvm-ar
export CFLAGS_aarch64_unknown_linux_gnu="--sysroot=/usr/aarch64-linux-gnu"
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUNNER="$qemu_aarch64"
cargo build --release --target aarch64-unknown-linux-gnu
cp target/aarch64-unknown-linux-gnu/release/libwasmvm.so artifacts/libwasmvm.aarch64.so
cargo build --release --target-dir="$TARGET_DIR" --target aarch64-unknown-linux-gnu
cp "$TARGET_DIR/aarch64-unknown-linux-gnu/release/libwasmvm.so" artifacts/libwasmvm.aarch64.so
5 changes: 3 additions & 2 deletions builders/guest/build_gnu_x86_64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
set -o errexit -o nounset -o pipefail

export CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse
export TARGET_DIR="/target" # write to /target in the guest's file system to avoid writing to the host

# No stripping implemented (see https://github.com/CosmWasm/wasmvm/issues/222#issuecomment-2260007943).

echo "Starting x86_64-unknown-linux-gnu build"
export CC=clang
export CXX=clang++
cargo build --release --target x86_64-unknown-linux-gnu
cp target/x86_64-unknown-linux-gnu/release/libwasmvm.so artifacts/libwasmvm.x86_64.so
cargo build --release --target-dir="$TARGET_DIR" --target x86_64-unknown-linux-gnu
cp "$TARGET_DIR/x86_64-unknown-linux-gnu/release/libwasmvm.so" artifacts/libwasmvm.x86_64.so
9 changes: 5 additions & 4 deletions builders/guest/build_macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
set -o errexit -o nounset -o pipefail

export CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse
export TARGET_DIR="/target" # write to /target in the guest's file system to avoid writing to the host

# ref: https://wapl.es/rust/2019/02/17/rust-cross-compile-linux-to-macos.html
export PATH="/opt/osxcross/target/bin:$PATH"
Expand All @@ -12,14 +13,14 @@ export LIBZ_SYS_STATIC=1
echo "Starting aarch64-apple-darwin build"
export CC=aarch64-apple-darwin20.4-clang
export CXX=aarch64-apple-darwin20.4-clang++
cargo build --release --target aarch64-apple-darwin
cargo build --release --target-dir="$TARGET_DIR" --target aarch64-apple-darwin

echo "Starting x86_64-apple-darwin build"
export CC=o64-clang
export CXX=o64-clang++
cargo build --release --target x86_64-apple-darwin
cargo build --release --target-dir="$TARGET_DIR" --target x86_64-apple-darwin

# Create a universal library with both archs
lipo -output artifacts/libwasmvm.dylib -create \
target/x86_64-apple-darwin/release/deps/libwasmvm.dylib \
target/aarch64-apple-darwin/release/deps/libwasmvm.dylib
"$TARGET_DIR/x86_64-apple-darwin/release/deps/libwasmvm.dylib" \
"$TARGET_DIR/aarch64-apple-darwin/release/deps/libwasmvm.dylib"
9 changes: 5 additions & 4 deletions builders/guest/build_macos_static.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
set -o errexit -o nounset -o pipefail

export CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse
export TARGET_DIR="/target" # write to /target in the guest's file system to avoid writing to the host

# ref: https://wapl.es/rust/2019/02/17/rust-cross-compile-linux-to-macos.html
export PATH="/opt/osxcross/target/bin:$PATH"
Expand All @@ -12,14 +13,14 @@ export LIBZ_SYS_STATIC=1
echo "Starting aarch64-apple-darwin build"
export CC=aarch64-apple-darwin20.4-clang
export CXX=aarch64-apple-darwin20.4-clang++
cargo build --release --target aarch64-apple-darwin --example wasmvmstatic
cargo build --release --target-dir="$TARGET_DIR" --target aarch64-apple-darwin --example wasmvmstatic

echo "Starting x86_64-apple-darwin build"
export CC=o64-clang
export CXX=o64-clang++
cargo build --release --target x86_64-apple-darwin --example wasmvmstatic
cargo build --release --target-dir="$TARGET_DIR" --target x86_64-apple-darwin --example wasmvmstatic

# Create a universal library with both archs
lipo -output artifacts/libwasmvmstatic_darwin.a -create \
target/x86_64-apple-darwin/release/examples/libwasmvmstatic.a \
target/aarch64-apple-darwin/release/examples/libwasmvmstatic.a
"$TARGET_DIR/x86_64-apple-darwin/release/examples/libwasmvmstatic.a" \
"$TARGET_DIR/aarch64-apple-darwin/release/examples/libwasmvmstatic.a"
9 changes: 5 additions & 4 deletions builders/guest/build_muslc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
set -e # Note we are not using bash here but the Alpine default shell

export CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse
export TARGET_DIR="/target" # write to /target in the guest's file system to avoid writing to the host

# No stripping implemented (see https://github.com/CosmWasm/wasmvm/issues/222#issuecomment-2260007943).

echo "Starting aarch64-unknown-linux-musl build"
export CC=/opt/aarch64-linux-musl-cross/bin/aarch64-linux-musl-gcc
cargo build --release --target aarch64-unknown-linux-musl --example wasmvmstatic
cargo build --release --target-dir="$TARGET_DIR" --target aarch64-unknown-linux-musl --example wasmvmstatic
unset CC

echo "Starting x86_64-unknown-linux-musl build"
cargo build --release --target x86_64-unknown-linux-musl --example wasmvmstatic
cargo build --release --target-dir="$TARGET_DIR" --target x86_64-unknown-linux-musl --example wasmvmstatic

cp target/aarch64-unknown-linux-musl/release/examples/libwasmvmstatic.a artifacts/libwasmvm_muslc.aarch64.a
cp target/x86_64-unknown-linux-musl/release/examples/libwasmvmstatic.a artifacts/libwasmvm_muslc.x86_64.a
cp "$TARGET_DIR/aarch64-unknown-linux-musl/release/examples/libwasmvmstatic.a" artifacts/libwasmvm_muslc.aarch64.a
cp "$TARGET_DIR/x86_64-unknown-linux-musl/release/examples/libwasmvmstatic.a" artifacts/libwasmvm_muslc.x86_64.a
5 changes: 4 additions & 1 deletion builders/guest/build_windows.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
set -o errexit -o nounset -o pipefail

export CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse
export TARGET_DIR="/target" # write to /target in the guest's file system to avoid writing to the host

# ref: https://www.reddit.com/r/rust/comments/5k8uab/crosscompiling_from_ubuntu_to_windows_with_rustup/

cargo build --release --target x86_64-pc-windows-gnu
cargo build --release --target-dir="$TARGET_DIR" --target x86_64-pc-windows-gnu

cp "$TARGET_DIR/x86_64-pc-windows-gnu/release/wasmvm.dll" artifacts/wasmvm.dll
14 changes: 14 additions & 0 deletions devtools/get_glibc_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
set -o errexit -o nounset -o pipefail
command -v shellcheck >/dev/null && shellcheck "$0"

if [[ $# -eq 0 ]]; then
files=(internal/api/libwasmvm.*.so)
else
files=("$@")
fi

for file in "${files[@]}"; do
echo "Required glibc versions in $file:"
objdump -T "$file" | grep GLIBC | sed 's/.*GLIBC_\([.0-9]*\).*/\1/g' | sort -V -u
done
2 changes: 1 addition & 1 deletion docs/COMPILER_VERSIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ ensure we can switch between compiler versions in some range.
## Production Rust compiler

This is the version set in the builders: `builders/Dockerfile.alpine`,
`builders/Dockerfile.centos7` and `Dockerfile.cross`.
`builders/Dockerfile.debian` and `Dockerfile.cross`.

## Min Rust compiler

Expand Down
Loading