Skip to content

Commit a353aa7

Browse files
authored
Merge pull request #439 from CosmWasm/debian-builders
Create Debian builder image and use for GNU linux .so files
2 parents f72d5de + c27b736 commit a353aa7

14 files changed

+107
-46
lines changed

.circleci/config.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,13 @@ jobs:
309309
- run:
310310
name: Copy .so build
311311
command: cp /tmp/builds/libwasmvm.x86_64.so ./internal/api
312+
# Debugging step to better understand what is linked here
313+
- run:
314+
name: Check .so files
315+
command: |
316+
ls -lA ./internal/api/libwasmvm.*.so
317+
sha256sum ./internal/api/libwasmvm.*.so
318+
ldd ./internal/api/libwasmvm.x86_64.so
312319
- run:
313320
name: Build Go project
314321
command: make build-go

Makefile

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.PHONY: all build build-rust build-go test
22

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

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

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

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

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

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

116103
update-bindings:

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ go build .
9090
CGO_ENABLED=0 go build .
9191
```
9292

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

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

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

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

builders/Dockerfile.debian

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Use a debian version that is old enough to lead to a low
2+
# glibc requirement of builds.
3+
# Debian 11 "Bullseye" has long-term support until August 31st, 2026
4+
FROM --platform=linux/amd64 debian:11-slim
5+
6+
RUN apt update -y \
7+
&& apt install -y gcc make gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu wget
8+
9+
# GET FROM https://github.com/rust-lang/docker-rust-nightly
10+
ENV RUSTUP_HOME=/usr/local/rustup \
11+
CARGO_HOME=/usr/local/cargo \
12+
PATH=/usr/local/cargo/bin:$PATH
13+
14+
RUN wget --no-verbose "https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-gnu/rustup-init" \
15+
&& chmod +x rustup-init \
16+
&& ./rustup-init -y --no-modify-path --profile minimal --default-toolchain 1.77.0 \
17+
&& rm rustup-init \
18+
&& chmod -R a+w $RUSTUP_HOME $CARGO_HOME \
19+
&& rustup --version \
20+
&& cargo --version \
21+
&& rustc --version \
22+
&& chmod -R 777 /usr/local/cargo \
23+
&& rustup target add aarch64-unknown-linux-gnu
24+
25+
## COPY BUILD SCRIPTS
26+
27+
WORKDIR /code
28+
29+
COPY guest/*.sh /usr/local/bin/
30+
RUN chmod +x /usr/local/bin/*.sh
31+
32+
RUN mkdir /.cargo
33+
RUN chmod +rx /.cargo
34+
COPY guest/cargo-config /.cargo/config
35+
36+
CMD ["bash", "-c", "echo 'Argument missing. Pass one build script (e.g. build_linux.sh) to docker run' && exit 1"]

builders/Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Versioned by a simple counter that is not bound to a specific CosmWasm version
22
# See builders/README.md
3-
BUILDERS_PREFIX := cosmwasm/go-ext-builder:0019
3+
BUILDERS_PREFIX := cosmwasm/libwasmvm-builder:0100
44

5-
.PHONY: docker-image-centos7
6-
docker-image-centos7:
7-
docker build --pull . -t $(BUILDERS_PREFIX)-centos7 -f ./Dockerfile.centos7
5+
.PHONY: docker-image-debian
6+
docker-image-debian:
7+
docker build --pull . -t $(BUILDERS_PREFIX)-debian -f ./Dockerfile.debian
88

99
.PHONY: docker-image-cross
1010
docker-image-cross:
@@ -15,10 +15,10 @@ docker-image-alpine:
1515
docker build --pull . -t $(BUILDERS_PREFIX)-alpine -f ./Dockerfile.alpine
1616

1717
.PHONY: docker-images
18-
docker-images: docker-image-centos7 docker-image-cross docker-image-alpine
18+
docker-images: docker-image-debian docker-image-cross docker-image-alpine
1919

2020
.PHONY: docker-publish
2121
docker-publish: docker-images
2222
docker push $(BUILDERS_PREFIX)-cross
23-
docker push $(BUILDERS_PREFIX)-centos7
23+
docker push $(BUILDERS_PREFIX)-debian
2424
docker push $(BUILDERS_PREFIX)-alpine

builders/README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,21 @@ any machine that can run Docker can do the cross-compilation.
1414

1515
## Docker Hub images
1616

17-
See https://hub.docker.com/r/cosmwasm/go-ext-builder/tags for all available
18-
versions of the builder images.
17+
See those DockerHub repos for all available versions of the builder images.
18+
19+
- From version 0100: https://hub.docker.com/r/cosmwasm/libwasmvm-builder/tags
20+
- Before version 0100: https://hub.docker.com/r/cosmwasm/go-ext-builder/tags
1921

2022
## Changelog
2123

2224
**Unreleased**
2325

26+
**Version 0100:**
27+
28+
- Rename builder image from cosmwasm/go-ext-builder to
29+
cosmwasm/libwasmvm-builder
30+
- Replace CentOS with Debian image for GNU linux builds
31+
2432
**Version 0019:**
2533

2634
- Bump `OSX_VERSION_MIN` to 10.15.

builders/guest/build_gnu_aarch64.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
set -o errexit -o nounset -o pipefail
33

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

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

@@ -14,5 +15,5 @@ export AR_aarch64_unknown_linux_gnu=llvm-ar
1415
export CFLAGS_aarch64_unknown_linux_gnu="--sysroot=/usr/aarch64-linux-gnu"
1516
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc
1617
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUNNER="$qemu_aarch64"
17-
cargo build --release --target aarch64-unknown-linux-gnu
18-
cp target/aarch64-unknown-linux-gnu/release/libwasmvm.so artifacts/libwasmvm.aarch64.so
18+
cargo build --release --target-dir="$TARGET_DIR" --target aarch64-unknown-linux-gnu
19+
cp "$TARGET_DIR/aarch64-unknown-linux-gnu/release/libwasmvm.so" artifacts/libwasmvm.aarch64.so

builders/guest/build_gnu_x86_64.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
set -o errexit -o nounset -o pipefail
33

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

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

89
echo "Starting x86_64-unknown-linux-gnu build"
910
export CC=clang
1011
export CXX=clang++
11-
cargo build --release --target x86_64-unknown-linux-gnu
12-
cp target/x86_64-unknown-linux-gnu/release/libwasmvm.so artifacts/libwasmvm.x86_64.so
12+
cargo build --release --target-dir="$TARGET_DIR" --target x86_64-unknown-linux-gnu
13+
cp "$TARGET_DIR/x86_64-unknown-linux-gnu/release/libwasmvm.so" artifacts/libwasmvm.x86_64.so

builders/guest/build_macos.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
set -o errexit -o nounset -o pipefail
33

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

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

1718
echo "Starting x86_64-apple-darwin build"
1819
export CC=o64-clang
1920
export CXX=o64-clang++
20-
cargo build --release --target x86_64-apple-darwin
21+
cargo build --release --target-dir="$TARGET_DIR" --target x86_64-apple-darwin
2122

2223
# Create a universal library with both archs
2324
lipo -output artifacts/libwasmvm.dylib -create \
24-
target/x86_64-apple-darwin/release/deps/libwasmvm.dylib \
25-
target/aarch64-apple-darwin/release/deps/libwasmvm.dylib
25+
"$TARGET_DIR/x86_64-apple-darwin/release/deps/libwasmvm.dylib" \
26+
"$TARGET_DIR/aarch64-apple-darwin/release/deps/libwasmvm.dylib"

builders/guest/build_macos_static.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
set -o errexit -o nounset -o pipefail
33

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

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

1718
echo "Starting x86_64-apple-darwin build"
1819
export CC=o64-clang
1920
export CXX=o64-clang++
20-
cargo build --release --target x86_64-apple-darwin --example wasmvmstatic
21+
cargo build --release --target-dir="$TARGET_DIR" --target x86_64-apple-darwin --example wasmvmstatic
2122

2223
# Create a universal library with both archs
2324
lipo -output artifacts/libwasmvmstatic_darwin.a -create \
24-
target/x86_64-apple-darwin/release/examples/libwasmvmstatic.a \
25-
target/aarch64-apple-darwin/release/examples/libwasmvmstatic.a
25+
"$TARGET_DIR/x86_64-apple-darwin/release/examples/libwasmvmstatic.a" \
26+
"$TARGET_DIR/aarch64-apple-darwin/release/examples/libwasmvmstatic.a"

0 commit comments

Comments
 (0)