Skip to content

Commit b431b63

Browse files
authored
Merge pull request #294 from CosmWasm/multiarch-builders
Create universal library with for ARM and Intel
2 parents 1624bde + f42579b commit b431b63

15 files changed

+211
-79
lines changed

.editorconfig

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ insert_final_newline = true
1111
indent_style = space
1212
indent_size = 4
1313

14+
[*.py]
15+
indent_style = space
16+
indent_size = 4
17+
1418
[{Makefile,*.go}]
1519
indent_style = tab
1620
indent_size = 4

.gitignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
target/
1+
# Please also see libwasmvm/.gitignore for the Rust-specific ignored files.
2+
23
**/*.rs.bk
34
*.iml
45
.idea
@@ -7,7 +8,6 @@ target/
78
lib*.a
89

910
# artifacts from compile tests
10-
artifacts/
1111
/demo
1212
tmp
1313
a.out

Makefile

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
.PHONY: all build build-rust build-go test
22

33
# Builds the Rust library libwasmvm
4-
BUILDERS_PREFIX := cosmwasm/go-ext-builder:0008
4+
BUILDERS_PREFIX := cosmwasm/go-ext-builder:0009
55
# Contains a full Go dev environment in order to run Go tests on the built library
6-
ALPINE_TESTER := cosmwasm/go-ext-builder:0008-alpine
6+
ALPINE_TESTER := cosmwasm/go-ext-builder:0009-alpine
77

88
USER_ID := $(shell id -u)
99
USER_GROUP = $(shell id -g)
@@ -73,10 +73,10 @@ release-build-linux:
7373

7474
# Creates a release build in a containerized build environment of the shared library for macOS (.dylib)
7575
release-build-macos:
76-
rm -rf libwasmvm/target/release
77-
docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd)/libwasmvm:/code $(BUILDERS_PREFIX)-cross
78-
cp libwasmvm/target/x86_64-apple-darwin/release/deps/libwasmvm.dylib api
79-
cp libwasmvm/bindings.h api
76+
rm -rf libwasmvm/target/x86_64-apple-darwin/release
77+
rm -rf libwasmvm/target/aarch64-apple-darwin/release
78+
docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd)/libwasmvm:/code $(BUILDERS_PREFIX)-cross build_macos.sh
79+
cp libwasmvm/artifacts/libwasmvm.dylib api
8080
make update-bindings
8181

8282
update-bindings:

README.md

+39-33
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,45 @@ link with, and Go developers should just be able to import this directly.
1414

1515
## Supported Platforms
1616

17-
Requires Rust 1.51+, Requires Go 1.17+
18-
19-
Since this package includes a rust prebuilt dll, you cannot just import the go code,
20-
but need to be on a system that works with an existing dll. Currently this is Linux
21-
(tested on Ubuntu, Debian, and CentOS7) and MacOS. We have a build system for Windows,
22-
but it is [not supported][wasmer_support] by the Wasmer Singlepass backend which we rely upon.
23-
24-
[wasmer_support]: https://docs.wasmer.io/ecosystem/wasmer/wasmer-features
25-
26-
### Overview
27-
28-
| | [x86] | [x86_64] | [ARM32] | [ARM64] |
29-
| ------------- | ------------------- | ------------------- | -------------------- | -------------------- |
30-
| Linux (glibc) | ❌‍ || ❌‍ <sub>[#53]</sub> | ❌‍ <sub>[#53]</sub> |
31-
| Linux (muslc) | ❌‍ || ❌‍ <sub>[#53]</sub> | ❌‍ <sub>[#53]</sub> |
32-
| macOS | ❌‍ || ❌‍ <sub>[#53]</sub> | ❌‍ <sub>[#53]</sub> |
33-
| Windows | ❌ <sub>[#28]</sub> | ❌ <sub>[#28]</sub> | ❌ <sub>[#28]</sub> | ❌ <sub>[#28]</sub> |
34-
35-
[x86]: https://en.wikipedia.org/wiki/X86
36-
[x86_64]: https://en.wikipedia.org/wiki/X86-64
37-
[arm32]: https://en.wikipedia.org/wiki/AArch32
38-
[arm64]: https://en.wikipedia.org/wiki/AArch64
39-
[#28]: https://github.com/CosmWasm/wasmvm/issues/28
40-
[#53]: https://github.com/CosmWasm/wasmvm/issues/53
41-
42-
✅ Supported and activly maintained.
43-
44-
❌ Blocked by external dependency.
45-
46-
🤷‍ Not supported because nobody cares so far. Feel free to look into it.
47-
48-
This is all blocked on [wasmer support for singlepass backend](https://docs.wasmer.io/ecosystem/wasmer/wasmer-features#compiler-support-by-chipset).
49-
We can only move on these wasmvm issues when the upstream has support.
17+
Requires Rust 1.55+ and Go 1.17+.
18+
19+
The Rust implementation of the VM is compiled to a library called libwasmvm. This is
20+
then linked to the Go code when the final binary is built. For that reason not all
21+
systems supported by Go are supported by this project.
22+
23+
Linux (tested on Ubuntu, Debian, and CentOS7, Alpine) and macOS is supported.
24+
We are working on Windows (#288).
25+
26+
[#288]: https://github.com/CosmWasm/wasmvm/pull/288
27+
28+
### Builds of libwasmvm
29+
30+
Our system currently supports the following builds. In general we can only support targets
31+
that are [supported by Wasmer's singlepass backend](https://docs.wasmer.io/ecosystem/wasmer/wasmer-features#compiler-support-by-chipset),
32+
which for example excludes all 32 bit systems.
33+
34+
<!-- AUTO GENERATED BY libwasmvm_builds.py START -->
35+
36+
| OS family | Arch | Linking | Supported | Wasmer 2.2+ | Note |
37+
| --------------- | ------- | ------- | -------------------- | ---------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
38+
| Linux (glibc) | x86_64 | shared | ✅​libwasmvm.so | ✅​libwasmvm.so | |
39+
| Linux (glibc) | x86_64 | static | 🚫​ | 🚫​ | Would link libwasmvm statically but glibc dynamically as static glibc linking is not recommended. Potentially interesting for Osmosis. |
40+
| Linux (glibc) | aarch64 | shared | 🚫​ | ✅​libwasmvm.aarch64.so | |
41+
| Linux (glibc) | aarch64 | static | 🚫​ | 🚫​ | |
42+
| Linux (musl) | x86_64 | shared | 🚫​ | 🚫​ | Possible but not needed |
43+
| Linux (musl) | x86_64 | static | ✅​libwasmvm_muslc.a | ✅​libwasmvm_muslc.a | |
44+
| Linux (musl) | aarch64 | shared | 🚫​ | 🚫​ | Possible but not needed |
45+
| Linux (musl) | aarch64 | static | 🚫​ | ✅​libwasmvm_muslc.aarch64.a | |
46+
| macOS | x86_64 | shared | ✅​libwasmvm.dylib | ✅​libwasmvm.dylib | Fat/universal library with multiple archs (#294) |
47+
| macOS | x86_64 | static | 🚫​ | 🚫​ | |
48+
| macOS | aarch64 | shared | 🚫​ | ✅​libwasmvm.dylib | Fat/universal library with multiple archs (#294) |
49+
| macOS | aarch64 | static | 🚫​ | 🚫​ | |
50+
| Windows (mingw) | x86_64 | shared | 🏗​wasmvm.dll | 🏗​wasmvm.dll | See #288 |
51+
| Windows (mingw) | x86_64 | static | 🚫​ | 🚫​ | |
52+
| Windows (mingw) | aarch64 | shared | 🚫​ | 🚫​ | |
53+
| Windows (mingw) | aarch64 | static | 🚫​ | 🚫​ | |
54+
55+
<!-- AUTO GENERATED BY libwasmvm_builds.py END -->
5056

5157
## Docs
5258

builders/Dockerfile.alpine

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# 1. Build the static Rust library
33
# 2. Execute Go tests that use and test this library
44
# For 2. we define the Go image here. For 1. we install Rust below.
5-
FROM golang:1.17.5-alpine
5+
FROM golang:1.17.7-alpine
66

77
ENV RUSTUP_HOME=/usr/local/rustup \
88
CARGO_HOME=/usr/local/cargo \

builders/Dockerfile.centos7

+10-12
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
FROM centos:centos7
22

3-
RUN yum -y update
4-
RUN yum -y install clang gcc gcc-c++ make wget
3+
RUN yum -y update \
4+
&& yum -y install clang gcc gcc-c++ make wget
55

66
# GET FROM https://github.com/rust-lang/docker-rust-nightly
77
ENV RUSTUP_HOME=/usr/local/rustup \
88
CARGO_HOME=/usr/local/cargo \
99
PATH=/usr/local/cargo/bin:$PATH
1010

11-
12-
RUN url="https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-gnu/rustup-init"; \
13-
wget "$url"; \
14-
chmod +x rustup-init; \
15-
./rustup-init -y --no-modify-path --default-toolchain 1.55.0; \
16-
rm rustup-init; \
17-
chmod -R a+w $RUSTUP_HOME $CARGO_HOME; \
18-
rustup --version; \
19-
cargo --version; \
20-
rustc --version;
11+
RUN wget "https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-gnu/rustup-init" \
12+
&& chmod +x rustup-init \
13+
&& ./rustup-init -y --no-modify-path --default-toolchain 1.55.0 \
14+
&& rm rustup-init \
15+
&& chmod -R a+w $RUSTUP_HOME $CARGO_HOME \
16+
&& rustup --version \
17+
&& cargo --version \
18+
&& rustc --version
2119

2220
# allow non-root user to download more deps later
2321
RUN chmod -R 777 /usr/local/cargo

builders/Dockerfile.cross

+27-20
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,52 @@
1-
FROM rust:1.55.0-buster
1+
FROM rust:1.55.0-bullseye
22

33
# Install build dependencies
4-
RUN apt-get update
5-
RUN apt install -y clang gcc g++ zlib1g-dev libmpc-dev libmpfr-dev libgmp-dev
6-
RUN apt install -y build-essential cmake
7-
8-
# add some llvm configs for later - how to cross-compile this in wasmer-llvm-backend???
9-
RUN echo deb http://deb.debian.org/debian buster-backports main >> /etc/apt/sources.list
10-
RUN apt-get update
11-
RUN apt install -y libllvm8 llvm-8 llvm-8-dev llvm-8-runtime
12-
ENV LLVM_SYS_80_PREFIX=/usr/lib/llvm-8
4+
RUN apt-get update \
5+
&& apt install -y clang gcc g++ zlib1g-dev libmpc-dev libmpfr-dev libgmp-dev build-essential cmake
136

147
## ADD MACOS SUPPORT
158

169
WORKDIR /opt
1710

18-
# Add macOS Rust target
19-
RUN rustup target add x86_64-apple-darwin
11+
# Add macOS Rust targets
12+
RUN rustup target add x86_64-apple-darwin aarch64-apple-darwin
2013

2114
# Build osxcross
22-
RUN git clone https://github.com/tpoechtrager/osxcross
23-
RUN cd osxcross && \
24-
wget -nc https://s3.dockerproject.org/darwin/v2/MacOSX10.10.sdk.tar.xz && \
25-
mv MacOSX10.10.sdk.tar.xz tarballs/ && \
26-
UNATTENDED=yes OSX_VERSION_MIN=10.10 ./build.sh
15+
# See https://github.com/tpoechtrager/osxcross/blob/master/build.sh#L31-L49 for SDK overview.
16+
#
17+
# SDK availability is tricky. There is 10.10 and 10.11. at
18+
# - https://s3.dockerproject.org/darwin/v2/MacOSX10.10.sdk.tar.xz
19+
# - https://s3.dockerproject.org/darwin/v2/MacOSX10.11.sdk.tar.xz
20+
# and we have https://github.com/phracker/MacOSX-SDKs/releases.
21+
# At some point we might want to use our own package.
22+
RUN git clone https://github.com/tpoechtrager/osxcross \
23+
&& cd osxcross \
24+
# Don't change file name when downloading because osxcross auto-detects the version from the name
25+
&& wget -nc https://github.com/phracker/MacOSX-SDKs/releases/download/11.3/MacOSX11.3.sdk.tar.xz \
26+
&& mv MacOSX11.3.sdk.tar.xz tarballs/ \
27+
&& UNATTENDED=yes OSX_VERSION_MIN=10.10 ./build.sh \
28+
# Cleanups before Docker layer is finalized
29+
&& rm -r tarballs/
2730
RUN chmod +rx /opt/osxcross
2831
RUN chmod +rx /opt/osxcross/target
2932
RUN chmod -R +rx /opt/osxcross/target/bin
3033

34+
# RUN ls -l /opt/osxcross/target/bin
35+
RUN /opt/osxcross/target/bin/x86_64-apple-darwin20.4-clang --version
36+
RUN /opt/osxcross/target/bin/aarch64-apple-darwin20.4-clang --version
37+
3138
# allow non-root user to download more deps later
3239
RUN chmod -R 777 /usr/local/cargo
3340

3441
## COPY BUILD SCRIPTS
3542

3643
WORKDIR /code
3744

38-
COPY guest/*.sh /opt/
39-
RUN chmod +x /opt/*.sh
45+
COPY guest/*.sh /usr/local/bin/
46+
RUN chmod +x /usr/local/bin/*.sh
4047

4148
RUN mkdir /.cargo
4249
RUN chmod +rx /.cargo
4350
COPY guest/cargo-config /.cargo/config
4451

45-
CMD ["/opt/build_macos.sh"]
52+
CMD ["bash", "-c", "echo 'Argument missing. Pass one build script (e.g. build_macos.sh) to docker run' && exit 1"]

builders/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Versioned by a simple counter that is not bound to a specific CosmWasm version
22
# See builders/README.md
3-
BUILDERS_PREFIX := cosmwasm/go-ext-builder:0008
3+
BUILDERS_PREFIX := cosmwasm/go-ext-builder:0009
44

55
.PHONY: docker-image-centos7
66
docker-image-centos7:

builders/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ can do the cross-compilation.
1414

1515
## Changelog
1616

17+
**Version 0009:**
18+
19+
- Let macOS build dylib files with both aarch64 and x86_64 code.
20+
- Update Go (for testing only) to 1.17.7.
21+
1722
**Version 0008:**
1823

1924
- Update Rust to 1.55.0 and Go (for testing only) to 1.17.5.

builders/guest/build_linux.sh

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/bash
2+
set -o errexit -o nounset -o pipefail
23

34
# See https://github.com/CosmWasm/wasmvm/issues/222#issuecomment-880616953 for two approaches to
45
# enable stripping through cargo (if that is desired).

builders/guest/build_macos.sh

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
#!/bin/bash
2+
set -o errexit -o nounset -o pipefail
23

34
# ref: https://wapl.es/rust/2019/02/17/rust-cross-compile-linux-to-macos.html
45
export PATH="/opt/osxcross/target/bin:$PATH"
56
export LIBZ_SYS_STATIC=1
6-
export CC=o64-clang
7-
export CXX=o64-clang++
87

98
# See https://github.com/CosmWasm/wasmvm/issues/222#issuecomment-880616953 for two approaches to
109
# enable stripping through cargo (if that is desired).
1110

11+
echo "Starting aarch64-apple-darwin build"
12+
export CC=aarch64-apple-darwin20.4-clang
13+
export CXX=aarch64-apple-darwin20.4-clang++
14+
cargo build --release --target aarch64-apple-darwin
15+
16+
echo "Starting x86_64-apple-darwin build"
17+
export CC=o64-clang
18+
export CXX=o64-clang++
1219
cargo build --release --target x86_64-apple-darwin
20+
21+
# Create a universal library with both archs
22+
lipo -output artifacts/libwasmvm.dylib -create \
23+
target/x86_64-apple-darwin/release/deps/libwasmvm.dylib \
24+
target/aarch64-apple-darwin/release/deps/libwasmvm.dylib

builders/guest/cargo-config

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
[target.x86_64-apple-darwin]
2-
linker = "x86_64-apple-darwin14-clang"
3-
ar = "x86_64-apple-darwin14-ar"
2+
linker = "x86_64-apple-darwin20.4-clang"
3+
ar = "x86_64-apple-darwin20.4-ar"
4+
5+
[target.aarch64-apple-darwin]
6+
linker = "aarch64-apple-darwin20.4-clang"
7+
ar = "aarch64-apple-darwin20.4-ar"

0 commit comments

Comments
 (0)