From 856b1a0ff4b631375a53105f058184482f6bcf51 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Wed, 15 Jan 2020 19:47:13 +0100 Subject: [PATCH 1/2] Add windows cross compiling --- Dockerfile.cross | 14 ++++++++------ Makefile | 2 +- build/{build.sh => build_cross.sh} | 2 +- build/build_windows.sh | 6 ++++++ build/cargo-config | 6 +++++- 5 files changed, 21 insertions(+), 9 deletions(-) rename build/{build.sh => build_cross.sh} (82%) create mode 100755 build/build_windows.sh diff --git a/Dockerfile.cross b/Dockerfile.cross index 262ed7471..990fea722 100644 --- a/Dockerfile.cross +++ b/Dockerfile.cross @@ -7,19 +7,24 @@ RUN apt-get update RUN apt install -y clang gcc g++ zlib1g-dev libmpc-dev libmpfr-dev libgmp-dev RUN apt install -y build-essential cmake +## add support for windows cross-compile +RUN apt install -y mingw-w64 + # add some llvm configs for later - how to cross-compile this in wasmer-llvm-backend??? RUN echo deb http://deb.debian.org/debian buster-backports main >> /etc/apt/sources.list RUN apt-get update RUN apt install -y libllvm8 llvm-8 llvm-8-dev llvm-8-runtime ENV LLVM_SYS_80_PREFIX=/usr/lib/llvm-8 -## ADD MACOS SUPPORT - WORKDIR /opt # Pin to proper nightly and add macOS Rust target RUN rustup default nightly-2020-06-08 + +# Add macOS and Windows Rust target RUN rustup target add x86_64-apple-darwin +RUN rustup target add x86_64-pc-windows-msvc +RUN rustup target add x86_64-pc-windows-gnu # Build osxcross RUN git clone https://github.com/tpoechtrager/osxcross @@ -31,8 +36,6 @@ RUN chmod +rx /opt/osxcross RUN chmod +rx /opt/osxcross/target RUN chmod -R +rx /opt/osxcross/target/bin -## TODO: add support for windows cross-compile - # PRE-FETCH MANY DEPS WORKDIR /scratch COPY Cargo.toml /scratch/ @@ -43,7 +46,6 @@ RUN cargo fetch RUN chmod -R 777 /usr/local/cargo ## COPY BUILD SCRIPTS - WORKDIR /code RUN rm -rf /scratch @@ -54,4 +56,4 @@ RUN mkdir /.cargo RUN chmod +rx /.cargo COPY build/cargo-config /.cargo/config -CMD ["/opt/build_osx.sh"] +CMD ["/opt/build_cross.sh"] diff --git a/Makefile b/Makefile index 3a9a2c93e..b7168b704 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ .PHONY: all build build-rust build-go test docker-image docker-image-centos7 docker-image-cross -DOCKER_TAG := 0.8.2 +DOCKER_TAG := 0.9.0-dev USER_ID := $(shell id -u) USER_GROUP = $(shell id -g) diff --git a/build/build.sh b/build/build_cross.sh similarity index 82% rename from build/build.sh rename to build/build_cross.sh index de07b48d3..f56c4d102 100755 --- a/build/build.sh +++ b/build/build_cross.sh @@ -4,5 +4,5 @@ set -e DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" -"$DIR/build_linux.sh" +"$DIR/build_windows.sh" "$DIR/build_osx.sh" \ No newline at end of file diff --git a/build/build_windows.sh b/build/build_windows.sh new file mode 100755 index 000000000..9f5421a74 --- /dev/null +++ b/build/build_windows.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +# 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 --verbose +cp target/x86_64-pc-windows-gnu/release/deps/libgo_cosmwasm.dll api diff --git a/build/cargo-config b/build/cargo-config index 4727075fd..58e431ea3 100644 --- a/build/cargo-config +++ b/build/cargo-config @@ -1,3 +1,7 @@ [target.x86_64-apple-darwin] linker = "x86_64-apple-darwin14-clang" -ar = "x86_64-apple-darwin14-ar" \ No newline at end of file +ar = "x86_64-apple-darwin14-ar" + +[target.x86_64-pc-windows-gnu] +linker = "x86_64-w64-mingw32-gcc" +ar = "x86_64-w64-mingw32-gcc-ar" \ No newline at end of file From 23c4a0dc8c7352cacc783549b5b3a6f36be5a3ee Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Mon, 29 Jun 2020 22:49:37 +0200 Subject: [PATCH 2/2] REVERT ME: only cross compile windows as github is flaky for osx build --- Dockerfile.cross | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Dockerfile.cross b/Dockerfile.cross index 990fea722..4d69b713a 100644 --- a/Dockerfile.cross +++ b/Dockerfile.cross @@ -30,11 +30,14 @@ RUN rustup target add x86_64-pc-windows-gnu RUN git clone https://github.com/tpoechtrager/osxcross RUN cd osxcross && \ wget -nc https://s3.dockerproject.org/darwin/v2/MacOSX10.10.sdk.tar.xz && \ - mv MacOSX10.10.sdk.tar.xz tarballs/ && \ - UNATTENDED=yes OSX_VERSION_MIN=10.7 ./build.sh -RUN chmod +rx /opt/osxcross -RUN chmod +rx /opt/osxcross/target -RUN chmod -R +rx /opt/osxcross/target/bin + mv MacOSX10.10.sdk.tar.xz tarballs/ + +# TODO: enable when github is not so flaky +# RUN cd osxcross && UNATTENDED=yes OSX_VERSION_MIN=10.7 ./build.sh + +# RUN chmod +rx /opt/osxcross +# RUN chmod +rx /opt/osxcross/target +# RUN chmod -R +rx /opt/osxcross/target/bin # PRE-FETCH MANY DEPS WORKDIR /scratch @@ -56,4 +59,6 @@ RUN mkdir /.cargo RUN chmod +rx /.cargo COPY build/cargo-config /.cargo/config -CMD ["/opt/build_cross.sh"] +# TODO: re-enable when github is not so flaky +# CMD ["/opt/build_cross.sh"] +CMD ["/opt/build_windows.sh"]