Skip to content

Commit

Permalink
Add support for windows builds
Browse files Browse the repository at this point in the history
  • Loading branch information
webmaster128 committed Sep 6, 2022
1 parent c0430b8 commit 779605c
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 3 deletions.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
8 changes: 5 additions & 3 deletions builders/Dockerfile.cross
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions builders/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:**

Expand Down
6 changes: 6 additions & 0 deletions builders/guest/build_windows.sh
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions builders/guest/cargo-config
Original file line number Diff line number Diff line change
Expand Up @@ -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"
6 changes: 6 additions & 0 deletions internal/api/link_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//go:build windows && !sys_wasmvm

package api

// #cgo LDFLAGS: -Wl,-rpath,${SRCDIR} -L${SRCDIR} -lwasmvm
import "C"

0 comments on commit 779605c

Please sign in to comment.