Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ release-alpine:
# Creates a release build in a containerized build environment of the shared library for glibc Linux (.so)
release-linux:
rm -rf libgo_owasm/target/release
rm -rf libgo_owasm/target/x86_64-unknown-linux-gnu/release
rm -rf libgo_owasm/target/aarch64-unknown-linux-gnu/release
docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd):/code/go-owasm owasm/go-ext-builder:$(DOCKER_TAG)-linux

# Creates a release build in a containerized build environment of the shared library for macOS (.dylib)
Expand Down
6 changes: 6 additions & 0 deletions api/link_glibclinux_aarch64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//go:build linux && !muslc && arm64

package api

// #cgo LDFLAGS: -Wl,-rpath,${SRCDIR} -L${SRCDIR} -lgo_owasm.aarch64 -lgmp
import "C"
6 changes: 6 additions & 0 deletions api/link_glibclinux_x86_64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//go:build linux && !muslc && amd64

package api

// #cgo LDFLAGS: -Wl,-rpath,${SRCDIR} -L${SRCDIR} -lgo_owasm.x86_64 -lgmp
import "C"
41 changes: 35 additions & 6 deletions build/Dockerfile.linux
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
FROM centos:centos7

RUN yum -y update
RUN yum -y install clang gcc gcc-c++ make wget gmp-devel
RUN yum -y update \
&& yum -y install clang gcc gmake wget gmp-devel zlib-devel \
# Obtain dependencies for cross compiling
# The only prebuilt glibc was done by third party Computational
&& yum -y install epel-release \
# See https://centos.pkgs.org/7/epel-aarch64/gcc-aarch64-linux-gnu-4.8.5-16.el7.1.aarch64.rpm.html
# and https://centos.pkgs.org/7/epel-aarch64/gcc-c++-aarch64-linux-gnu-4.8.5-16.el7.1.aarch64.rpm.html:
# "Support for cross-building user space programs is not currently provided as that would massively multiply
# the number of packages."
&& yum -y install gcc-aarch64-linux-gnu gcc-c++-aarch64-linux-gnu \
# See https://stackoverflow.com/a/64920961
&& wget http://springdale.princeton.edu/data/springdale/7/x86_64/os/Computational/glibc-aarch64-linux-gnu-2.24-2.sdl7.2.noarch.rpm \
&& sha256sum glibc-aarch64-linux-gnu-2.24-2.sdl7.2.noarch.rpm | grep 8caf8654ba0c15e1792bf0aaa1ac0cd4ad94ac905e97d6ea0f0e56e9ca1f5e78 \
&& wget http://springdale.princeton.edu/data/springdale/7/x86_64/os/Computational/glibc-aarch64-linux-gnu-devel-2.24-2.sdl7.2.noarch.rpm \
&& sha256sum glibc-aarch64-linux-gnu-devel-2.24-2.sdl7.2.noarch.rpm | grep bf050dc2389630f50e90f4cdaf6e4e1d986e89dcd2c8432f72738abe38b3bce2 \
&& yum install -y glibc-aarch64-linux-gnu-2.24-2.sdl7.2.noarch.rpm \
&& yum install -y glibc-aarch64-linux-gnu-devel-2.24-2.sdl7.2.noarch.rpm \
&& rm glibc-aarch64-*.rpm

# reference from https://github.com/rust-lang/docker-rust-nightly
ENV RUSTUP_HOME=/usr/local/rustup \
Expand All @@ -11,12 +27,13 @@ ENV RUSTUP_HOME=/usr/local/rustup \
RUN url="https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-gnu/rustup-init"; \
wget "$url"; \
chmod +x rustup-init; \
./rustup-init -y --no-modify-path --default-toolchain 1.60.0; \
./rustup-init -y --no-modify-path --default-toolchain 1.69.0; \
rm rustup-init; \
chmod -R a+w $RUSTUP_HOME $CARGO_HOME; \
rustup --version; \
cargo --version; \
rustc --version;
rustc --version; \
rustup target add aarch64-unknown-linux-gnu

# pre-fetch many deps
WORKDIR /scratch
Expand All @@ -31,12 +48,24 @@ WORKDIR /code
RUN rm -rf /scratch

# copy build scripts
COPY go-owasm/build/build_linux.sh /opt
RUN chmod +x /opt/build*
COPY go-owasm/build/*.sh /opt/
RUN chmod +x /opt/*.sh

# add config cargo
RUN mkdir /.cargo
RUN chmod +rx /.cargo
COPY go-owasm/build/cargo-config /.cargo/config

# Download and install gmp-devel for AArch64
RUN wget http://mirror.centos.org/altarch/7/os/aarch64/Packages/gmp-devel-6.0.0-15.el7.aarch64.rpm \
&& rpm2cpio gmp-devel-6.0.0-15.el7.aarch64.rpm | cpio -idmv \
&& rm gmp-devel-6.0.0-15.el7.aarch64.rpm

# Copy the missing library libgcc_s.so that gcc does not provide
RUN wget http://mirror.centos.org/altarch/7/os/aarch64/Packages/libgcc-4.8.5-44.el7.aarch64.rpm \
&& sha256sum libgcc-4.8.5-44.el7.aarch64.rpm | grep 4f44c5be70ed9d8d74c2a616cde92a842b15eefaccd766959e5fbd7fbe965d2d \
&& rpm2cpio libgcc-4.8.5-44.el7.aarch64.rpm | cpio -idmv \
&& cp /code/lib64/libgcc_s-4.8.5-20150702.so.1 /usr/lib/gcc/aarch64-linux-gnu/4.8.5/libgcc_s.so \
&& rm libgcc-*.el7.aarch64.rpm

CMD ["/opt/build_linux.sh"]
19 changes: 19 additions & 0 deletions build/build_gnu_aarch64.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
set -o errexit -o nounset -o pipefail

export CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse

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

echo "Starting aarch64-unknown-linux-gnu build"
export CC=clang
export CXX=clang++
export qemu_aarch64="qemu-aarch64 -L /usr/aarch64-linux-gnu"
export CC_aarch64_unknown_linux_gnu=clang
export AR_aarch64_unknown_linux_gnu=llvm-ar
export CFLAGS_aarch64_unknown_linux_gnu="--sysroot=/usr/aarch64-linux-gnu"
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUNNER="$qemu_aarch64"
cargo build --release --target aarch64-unknown-linux-gnu
cp target/aarch64-unknown-linux-gnu/release/libgo_owasm.so ./../api/libgo_owasm.aarch64.so
13 changes: 13 additions & 0 deletions build/build_gnu_x86_64.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
set -o errexit -o nounset -o pipefail

export CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse

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

echo "Starting x86_64-unknown-linux-gnu build"
export CC=clang
export CXX=clang++
cargo build --release --target x86_64-unknown-linux-gnu
cp target/x86_64-unknown-linux-gnu/release/libgo_owasm.so ./../api/libgo_owasm.x86_64.so
10 changes: 8 additions & 2 deletions build/build_linux.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/bin/bash
set -o errexit -o nounset -o pipefail

cd go-owasm/libgo_owasm
cargo build --release
cp target/release/deps/libgo_owasm.so ./../api
/opt/build_gnu_x86_64.sh
/opt/build_gnu_aarch64.sh


# cd go-owasm/libgo_owasm
# cargo build --release
# cp target/release/deps/libgo_owasm.so ./../api