diff --git a/Makefile b/Makefile index 2dd78ab74..c717bb99d 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) @@ -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: @@ -92,6 +88,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). @@ -102,8 +105,14 @@ release-build: make release-build-alpine make release-build-linux make release-build-macos + 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. 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..ecd4d0730 100644 --- a/builders/Dockerfile.cross +++ b/builders/Dockerfile.cross @@ -1,15 +1,17 @@ -FROM rust:1.60.0-bullseye +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 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. 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: diff --git a/builders/README.md b/builders/README.md index b5253aa25..cbae05273 100644 --- a/builders/README.md +++ b/builders/README.md @@ -14,6 +14,11 @@ can do the cross-compilation. ## Changelog +**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:** - Add cross-compilation setup to build `libwasmvm.x86_64.so` and `libwasmvm.aarch64.so` 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"