From 2d765d7660b1b161e290353eb4d26538f9815b2b Mon Sep 17 00:00:00 2001 From: Expotential108 Date: Tue, 6 Sep 2022 11:07:06 +0200 Subject: [PATCH] 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 2dd78ab..f58ecb0 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 49e8bd1..96473c8 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 0939091..cbae052 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 0000000..4943b7b --- /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 a8ba323..a983986 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 0000000..8e45cf0 --- /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"