Skip to content

Commit

Permalink
Merge pull request #350 from CosmWasm/builders-13
Browse files Browse the repository at this point in the history
Create builders version 0013
  • Loading branch information
webmaster128 authored Sep 6, 2022
2 parents 5193273 + a5cf1a0 commit 73d66a7
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 12 deletions.
21 changes: 15 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: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)
Expand Down Expand Up @@ -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:
Expand All @@ -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).
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion builders/Dockerfile.alpine
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 6 additions & 4 deletions builders/Dockerfile.cross
Original file line number Diff line number Diff line change
@@ -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.
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:0012
BUILDERS_PREFIX := cosmwasm/go-ext-builder:0013

.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 @@ 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`
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 73d66a7

Please sign in to comment.