Skip to content

Commit

Permalink
Add aarch64 osxcross support (#21)
Browse files Browse the repository at this point in the history
* add aarach64 for osx

* update version to provide gmp for aarch64

* Built shared libs

Co-authored-by: Builder <[email protected]>
  • Loading branch information
RogerKSI and Builder authored Jan 20, 2023
1 parent 75775e7 commit b5eb80c
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 10 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ release-linux:
release-osx:
rm -rf libgo_owasm/target/release
rm -rf libgo_owasm/target/x86_64-apple-darwin/release
rm -rf libgo_owasm/target/aarch64-apple-darwin/release
docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd):/code/go-owasm owasm/go-ext-builder:$(DOCKER_TAG)-osx

releases:
Expand Down
Binary file modified api/libgo_owasm.dylib
Binary file not shown.
3 changes: 1 addition & 2 deletions build/Dockerfile.linux
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ FROM centos:centos7
RUN yum -y update
RUN yum -y install clang gcc gcc-c++ make wget gmp-devel

# GET FROM https://github.com/rust-lang/docker-rust-nightly
# reference from https://github.com/rust-lang/docker-rust-nightly
ENV RUSTUP_HOME=/usr/local/rustup \
CARGO_HOME=/usr/local/cargo \
PATH=/usr/local/cargo/bin:$PATH


RUN url="https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-gnu/rustup-init"; \
wget "$url"; \
chmod +x rustup-init; \
Expand Down
5 changes: 3 additions & 2 deletions build/Dockerfile.osx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ RUN apt install -y build-essential wget cmake
WORKDIR /opt

# pin to proper nightly and add macOS Rust target
RUN rustup target add x86_64-apple-darwin
RUN rustup target add x86_64-apple-darwin aarch64-apple-darwin

# build osxcross
RUN git clone https://github.com/tpoechtrager/osxcross \
Expand All @@ -21,13 +21,14 @@ RUN git clone https://github.com/tpoechtrager/osxcross \
&& mv MacOSX11.3.sdk.tar.xz tarballs/ \
&& UNATTENDED=yes OSX_VERSION_MIN=10.10 ./build.sh \
# install gmp
&& echo "1" | MACOSX_DEPLOYMENT_TARGET=10.10 ./tools/osxcross-macports install gmp \
&& echo "1" | MACOSX_DEPLOYMENT_TARGET=11.3 ./tools/osxcross-macports install gmp \
# cleanups before Docker layer is finalized
&& rm -r tarballs/
RUN chmod +rx /opt/osxcross
RUN chmod +rx /opt/osxcross/target
RUN chmod -R +rx /opt/osxcross/target/bin
RUN /opt/osxcross/target/bin/x86_64-apple-darwin20.4-clang --version
RUN /opt/osxcross/target/bin/aarch64-apple-darwin20.4-clang --version

# pre-fetch many deps
WORKDIR /scratch
Expand Down
22 changes: 17 additions & 5 deletions build/build_osx.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
#!/bin/bash

# ref: https://wapl.es/rust/2019/02/17/rust-cross-compile-linux-to-macos.html
# ref from
## https://wapl.es/rust/2019/02/17/rust-cross-compile-linux-to-macos.html
## https://github.com/CosmWasm/wasmvm/blob/v1.1.1/builders/Dockerfile.cross
export OSXCROSS_MP_INC=1
export LIBZ_SYS_STATIC=1
export CC=o64-clang
export CXX=o64-clang++

cd go-owasm/libgo_owasm
rustup target add x86_64-apple-darwin

echo "Starting aarch64-apple-darwin build"
export CC=aarch64-apple-darwin20.4-clang
export CXX=aarch64-apple-darwin20.4-clang++
cargo build --release --target aarch64-apple-darwin

echo "Starting x86_64-apple-darwin build"
export CC=o64-clang
export CXX=o64-clang++
cargo build --release --target x86_64-apple-darwin
cp target/x86_64-apple-darwin/release/deps/libgo_owasm.dylib ./../api

# Create a universal library with both archs
lipo -output ./../api/libgo_owasm.dylib -create \
target/x86_64-apple-darwin/release/deps/libgo_owasm.dylib \
target/aarch64-apple-darwin/release/deps/libgo_owasm.dylib
4 changes: 4 additions & 0 deletions build/cargo-config
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[target.x86_64-apple-darwin]
linker = "x86_64-apple-darwin20.4-clang"
ar = "x86_64-apple-darwin20.4-ar"

[target.aarch64-apple-darwin]
linker = "aarch64-apple-darwin20.4-clang"
ar = "aarch64-apple-darwin20.4-ar"
2 changes: 1 addition & 1 deletion libgo_owasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2021"
[lib]
crate-type = ["cdylib"]

# GET FROM https://github.com/CosmWasm/wasmvm/blob/main/libwasmvm/Cargo.toml
# reference from https://github.com/CosmWasm/wasmvm/blob/main/libwasmvm/Cargo.toml
[[example]]
name = "muslc"
path = "src/lib.rs"
Expand Down

0 comments on commit b5eb80c

Please sign in to comment.