Skip to content

Use wasmvmstatic example and create builders version 0016 #438

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

Merged
merged 8 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
.PHONY: all build build-rust build-go test

# Builds the Rust library libwasmvm
BUILDERS_PREFIX := cosmwasm/go-ext-builder:0015
BUILDERS_PREFIX := cosmwasm/go-ext-builder:0016
# Contains a full Go dev environment in order to run Go tests on the built library
ALPINE_TESTER := cosmwasm/go-ext-builder:0015-alpine
ALPINE_TESTER := cosmwasm/go-ext-builder:0016-alpine

USER_ID := $(shell id -u)
USER_GROUP = $(shell id -g)
Expand Down Expand Up @@ -66,7 +66,9 @@ test-safety:

# Creates a release build in a containerized build environment of the static library for Alpine Linux (.a)
release-build-alpine:
rm -rf libwasmvm/target/release
# 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.a internal/api
Expand All @@ -75,14 +77,17 @@ release-build-alpine:

# Creates a release build in a containerized build environment of the shared library for glibc Linux (.so)
release-build-linux:
rm -rf libwasmvm/target/release
docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd)/libwasmvm:/code $(BUILDERS_PREFIX)-centos7
# 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
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
Expand All @@ -91,6 +96,7 @@ release-build-macos:

# 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
Expand All @@ -99,7 +105,8 @@ release-build-macos-static:

# Creates a release build in a containerized build environment of the shared library for Windows (.dll)
release-build-windows:
rm -rf libwasmvm/target/release
# 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
make update-bindings
Expand Down
2 changes: 1 addition & 1 deletion builders/Dockerfile.alpine
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ RUN set -eux \

RUN wget "https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-musl/rustup-init" \
&& chmod +x rustup-init \
&& ./rustup-init -y --no-modify-path --profile minimal --default-toolchain 1.68.2 \
&& ./rustup-init -y --no-modify-path --profile minimal --default-toolchain 1.69.0 \
&& rm rustup-init \
&& chmod -R a+w $RUSTUP_HOME $CARGO_HOME

Expand Down
18 changes: 7 additions & 11 deletions builders/Dockerfile.centos7
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,21 @@ ENV RUSTUP_HOME=/usr/local/rustup \

RUN wget "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.68.2 \
&& ./rustup-init -y --no-modify-path --profile minimal --default-toolchain 1.69.0 \
&& rm rustup-init \
&& chmod -R a+w $RUSTUP_HOME $CARGO_HOME \
&& rustup --version \
&& cargo --version \
&& rustc --version

# Add aarch64 as a target of compilation
RUN rustup target add aarch64-unknown-linux-gnu

# allow non-root user to download more deps later
RUN chmod -R 777 /usr/local/cargo
&& rustc --version \
&& chmod -R 777 /usr/local/cargo \
&& rustup target add aarch64-unknown-linux-gnu

## COPY BUILD SCRIPTS

WORKDIR /code

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

RUN mkdir /.cargo
RUN chmod +rx /.cargo
Expand All @@ -57,4 +53,4 @@ RUN wget http://mirror.centos.org/altarch/7/os/aarch64/Packages/libgcc-4.8.5-44.
&& cp /code/lib64/libgcc_s-4.8.5-20150702.so.1 /usr/lib/gcc/aarch64-linux-gnu/4.8.5/libgcc_s.so \
&& rm libgcc-*.el7.aarch64.rpm

CMD ["/opt/build_linux.sh"]
CMD ["bash", "-c", "echo 'Argument missing. Pass one build script (e.g. build_linux.sh) to docker run' && exit 1"]
2 changes: 1 addition & 1 deletion builders/Dockerfile.cross
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM rust:1.68.2-bullseye
FROM rust:1.69.0-bullseye

# Install build dependencies
RUN apt-get update \
Expand Down
2 changes: 1 addition & 1 deletion builders/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Versioned by a simple counter that is not bound to a specific CosmWasm version
# See builders/README.md
BUILDERS_PREFIX := cosmwasm/go-ext-builder:0015
BUILDERS_PREFIX := cosmwasm/go-ext-builder:0016

.PHONY: docker-image-centos7
docker-image-centos7:
Expand Down
5 changes: 5 additions & 0 deletions builders/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ any machine that can run Docker can do the cross-compilation.

## Changelog

**Version 0016:**

- Update Rust to 1.69.0.
- Let `build_muslc.sh` use `--example wasmvmstatic` instead of `--example muslc`

**Version 0015:**

- Update Rust to 1.68.2.
Expand Down
19 changes: 19 additions & 0 deletions builders/guest/build_gnu_aarch64.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
set -o errexit -o nounset -o pipefail

export CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse

# See https://github.com/CosmWasm/wasmvm/issues/222#issuecomment-880616953 for two approaches to
# enable stripping through cargo (if that is desired).

echo "Starting aarch64-unknown-linux-gnu build"
export CC=clang
export CXX=clang++
export qemu_aarch64="qemu-aarch64 -L /usr/aarch64-linux-gnu"
export CC_aarch64_unknown_linux_gnu=clang
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
13 changes: 13 additions & 0 deletions builders/guest/build_gnu_x86_64.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
set -o errexit -o nounset -o pipefail

export CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse

# See https://github.com/CosmWasm/wasmvm/issues/222#issuecomment-880616953 for two approaches to
# enable stripping through cargo (if that is desired).

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
22 changes: 2 additions & 20 deletions builders/guest/build_linux.sh
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,23 +1,5 @@
#!/bin/bash
set -o errexit -o nounset -o pipefail

export CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse

# See https://github.com/CosmWasm/wasmvm/issues/222#issuecomment-880616953 for two approaches to
# enable stripping through cargo (if that is desired).

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

echo "Starting aarch64-unknown-linux-gnu build"
export qemu_aarch64="qemu-aarch64 -L /usr/aarch64-linux-gnu"
export CC_aarch64_unknown_linux_gnu=clang
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
build_gnu_x86_64.sh
build_gnu_aarch64.sh
Empty file modified builders/guest/build_macos.sh
100755 → 100644
Empty file.
Empty file modified builders/guest/build_macos_static.sh
100755 → 100644
Empty file.
8 changes: 4 additions & 4 deletions builders/guest/build_muslc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ export CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse

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 muslc
cargo build --release --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 muslc
cargo build --release --target x86_64-unknown-linux-musl --example wasmvmstatic

cp target/aarch64-unknown-linux-musl/release/examples/libmuslc.a artifacts/libwasmvm_muslc.aarch64.a
cp target/x86_64-unknown-linux-musl/release/examples/libmuslc.a artifacts/libwasmvm_muslc.a
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.a
2 changes: 1 addition & 1 deletion docs/COMPILER_VERSIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ We currently use the following version:

| Type | Rust version | Note |
| ------------------------ | ------------ | --------------------------------- |
| Production Rust compiler | 1.68.2 | Builders version 0015 |
| Production Rust compiler | 1.69.0 | Builders version 0016 |
| Min Rust compiler | 1.60.0 | Supports builder versions >= 0012 |
| Tooling Rust compiler | 1.69.0 | |
5 changes: 0 additions & 5 deletions libwasmvm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ crate-type = ["cdylib", "rlib"]

# the example is to allow us to compile a muslc static lib with the same codebase as we compile the
# normal dynamic libs (best workaround I could find to override crate-type on the command line)
[[example]]
name = "muslc"
path = "src/lib.rs"
crate-type = ["staticlib"]

[[example]]
name = "wasmvmstatic"
path = "src/examples/wasmvmstatic.rs"
Expand Down
4 changes: 4 additions & 0 deletions libwasmvm/src/examples/wasmvmstatic.rs
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
// This is an entry point into the library in order to set
// crate-type = ["staticlib"] via a command line arument.
// See `--example wasmvmstatic`

pub use wasmvm::*;