From c0430b8f7a2958c322ce5fefa093dc404a3e5242 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Tue, 6 Sep 2022 10:54:49 +0200 Subject: [PATCH 1/6] Upgrade Rust to 1.63.0 --- builders/Dockerfile.alpine | 2 +- builders/Dockerfile.cross | 2 +- builders/README.md | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/builders/Dockerfile.alpine b/builders/Dockerfile.alpine index 80b33eaa6..89b50b959 100644 --- a/builders/Dockerfile.alpine +++ b/builders/Dockerfile.alpine @@ -16,7 +16,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.60.0 \ + && ./rustup-init -y --no-modify-path --profile minimal --default-toolchain 1.63.0 \ && rm rustup-init \ && chmod -R a+w $RUSTUP_HOME $CARGO_HOME diff --git a/builders/Dockerfile.cross b/builders/Dockerfile.cross index 57abdb805..49e8bd15a 100644 --- a/builders/Dockerfile.cross +++ b/builders/Dockerfile.cross @@ -1,4 +1,4 @@ -FROM rust:1.60.0-bullseye +FROM rust:1.63.0-bullseye # Install build dependencies RUN apt-get update \ diff --git a/builders/README.md b/builders/README.md index b5253aa25..09390919e 100644 --- a/builders/README.md +++ b/builders/README.md @@ -14,6 +14,10 @@ can do the cross-compilation. ## Changelog +**Version 0013:** + +- Update Rust to 1.63.0. + **Version 0012:** - Add cross-compilation setup to build `libwasmvm.x86_64.so` and `libwasmvm.aarch64.so` From 779605ce711b22760c5093c7c6b859335a82a722 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Tue, 6 Sep 2022 11:07:06 +0200 Subject: [PATCH 2/6] Add support for windows builds --- Makefile | 7 +++++++ builders/Dockerfile.cross | 8 +++++--- builders/README.md | 1 + builders/guest/build_windows.sh | 6 ++++++ builders/guest/cargo-config | 4 ++++ internal/api/link_windows.go | 6 ++++++ 6 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 builders/guest/build_windows.sh create mode 100644 internal/api/link_windows.go diff --git a/Makefile b/Makefile index 2dd78ab74..f58ecb057 100644 --- a/Makefile +++ b/Makefile @@ -92,6 +92,13 @@ release-build-macos: cp libwasmvm/artifacts/libwasmvm.dylib internal/api make update-bindings +# Creates a release build in a containerized build environment of the shared library for Windows (.dll) +release-build-windows: + rm -rf libwasmvm/target/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 + update-bindings: # After we build libwasmvm, we have to copy the generated bindings for Go code to use. # We cannot use symlinks as those are not reliably resolved by `go get` (https://github.com/CosmWasm/wasmvm/pull/235). diff --git a/builders/Dockerfile.cross b/builders/Dockerfile.cross index 49e8bd15a..96473c83a 100644 --- a/builders/Dockerfile.cross +++ b/builders/Dockerfile.cross @@ -2,14 +2,16 @@ FROM rust:1.63.0-bullseye # Install build dependencies RUN apt-get update \ - && apt install -y clang gcc g++ zlib1g-dev libmpc-dev libmpfr-dev libgmp-dev build-essential cmake + && apt install -y clang gcc g++ zlib1g-dev libmpc-dev libmpfr-dev libgmp-dev build-essential cmake \ + # Support for Windows cross-compile + mingw-w64 ## ADD MACOS SUPPORT WORKDIR /opt -# Add macOS Rust targets -RUN rustup target add x86_64-apple-darwin aarch64-apple-darwin +# Add macOS and Windows Rust targets +RUN rustup target add x86_64-apple-darwin x86_64-pc-windows-gnu # Build osxcross # See https://github.com/tpoechtrager/osxcross/blob/master/build.sh#L31-L49 for SDK overview. diff --git a/builders/README.md b/builders/README.md index 09390919e..cbae05273 100644 --- a/builders/README.md +++ b/builders/README.md @@ -17,6 +17,7 @@ can do the cross-compilation. **Version 0013:** - Update Rust to 1.63.0. +- Add Windows support to cosmwasm/go-ext-builder:0013-cross. This image builds for macOS and Windows now. **Version 0012:** diff --git a/builders/guest/build_windows.sh b/builders/guest/build_windows.sh new file mode 100644 index 000000000..4943b7b8d --- /dev/null +++ b/builders/guest/build_windows.sh @@ -0,0 +1,6 @@ +#!/bin/bash +set -o errexit -o nounset -o pipefail + +# 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 diff --git a/builders/guest/cargo-config b/builders/guest/cargo-config index a8ba3238c..a983986d5 100644 --- a/builders/guest/cargo-config +++ b/builders/guest/cargo-config @@ -9,3 +9,7 @@ ar = "aarch64-apple-darwin20.4-ar" [target.aarch64-unknown-linux-gnu] linker = "/usr/aarch64-linux-gnu/bin/ld" ar = "/usr/aarch64-linux-gnu/bin/ar" + +[target.x86_64-pc-windows-gnu] +linker = "x86_64-w64-mingw32-gcc" +ar = "x86_64-w64-mingw32-gcc-ar" diff --git a/internal/api/link_windows.go b/internal/api/link_windows.go new file mode 100644 index 000000000..8e45cf011 --- /dev/null +++ b/internal/api/link_windows.go @@ -0,0 +1,6 @@ +//go:build windows && !sys_wasmvm + +package api + +// #cgo LDFLAGS: -Wl,-rpath,${SRCDIR} -L${SRCDIR} -lwasmvm +import "C" From 1d3719f03808e4203f5a1d69e9e2f44f6ec41045 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Tue, 6 Sep 2022 11:07:48 +0200 Subject: [PATCH 3/6] Bump builders version --- Makefile | 4 ++-- builders/Makefile | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index f58ecb057..9861aef56 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,9 @@ .PHONY: all build build-rust build-go test # Builds the Rust library libwasmvm -BUILDERS_PREFIX := cosmwasm/go-ext-builder:0012 +BUILDERS_PREFIX := cosmwasm/go-ext-builder:0013 # Contains a full Go dev environment in order to run Go tests on the built library -ALPINE_TESTER := cosmwasm/go-ext-builder:0012-alpine +ALPINE_TESTER := cosmwasm/go-ext-builder:0013-alpine USER_ID := $(shell id -u) USER_GROUP = $(shell id -g) diff --git a/builders/Makefile b/builders/Makefile index e48947e60..0e3944c7e 100644 --- a/builders/Makefile +++ b/builders/Makefile @@ -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:0012 +BUILDERS_PREFIX := cosmwasm/go-ext-builder:0013 .PHONY: docker-image-centos7 docker-image-centos7: From d4cfbcb3c140023818a90dd197302653ceb6bfeb Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Tue, 6 Sep 2022 14:13:09 +0200 Subject: [PATCH 4/6] Bring back missing aarch64-apple-darwin target --- builders/Dockerfile.cross | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builders/Dockerfile.cross b/builders/Dockerfile.cross index 96473c83a..ecd4d0730 100644 --- a/builders/Dockerfile.cross +++ b/builders/Dockerfile.cross @@ -11,7 +11,7 @@ RUN apt-get update \ WORKDIR /opt # Add macOS and Windows Rust targets -RUN rustup target add x86_64-apple-darwin x86_64-pc-windows-gnu +RUN rustup target add x86_64-apple-darwin aarch64-apple-darwin x86_64-pc-windows-gnu # Build osxcross # See https://github.com/tpoechtrager/osxcross/blob/master/build.sh#L31-L49 for SDK overview. From df33037db46ade0450b42e56660f80c2bf640612 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Tue, 6 Sep 2022 14:13:27 +0200 Subject: [PATCH 5/6] Add release-build-windows --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 9861aef56..dbb9fc48a 100644 --- a/Makefile +++ b/Makefile @@ -109,6 +109,7 @@ release-build: make release-build-alpine make release-build-linux make release-build-macos + make release-build-windows test-alpine: release-build-alpine @# Build a Go demo binary called ./demo that links the static library from the previous step. From a5cf1a0520d4827a248f31646014e0919fdb90c3 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Tue, 6 Sep 2022 14:14:26 +0200 Subject: [PATCH 6/6] Move alpine tests out of build --- Makefile | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index dbb9fc48a..c717bb99d 100644 --- a/Makefile +++ b/Makefile @@ -71,10 +71,6 @@ release-build-alpine: cp libwasmvm/artifacts/libwasmvm_muslc.a internal/api cp libwasmvm/artifacts/libwasmvm_muslc.aarch64.a internal/api make update-bindings - # try running go tests using this lib with muslc - docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd):/mnt/testrun -w /mnt/testrun $(ALPINE_TESTER) go build -tags muslc ./... - # Use package list mode to include all subdirectores. The -count=1 turns off caching. - docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd):/mnt/testrun -w /mnt/testrun $(ALPINE_TESTER) go test -tags muslc -count=1 ./... # Creates a release build in a containerized build environment of the shared library for glibc Linux (.so) release-build-linux: @@ -112,6 +108,11 @@ release-build: make release-build-windows test-alpine: release-build-alpine +# try running go tests using this lib with muslc + docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd):/mnt/testrun -w /mnt/testrun $(ALPINE_TESTER) go build -tags muslc ./... +# Use package list mode to include all subdirectores. The -count=1 turns off caching. + docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd):/mnt/testrun -w /mnt/testrun $(ALPINE_TESTER) go test -tags muslc -count=1 ./... + @# Build a Go demo binary called ./demo that links the static library from the previous step. @# Whether the result is a statically linked or dynamically linked binary is decided by `go build` @# and it's a bit unclear how this is decided. We use `file` to see what we got.