Skip to content

Commit

Permalink
support aarch64-linux for docker on macos (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
rob-odwyer authored Oct 7, 2023
1 parent d7e3160 commit 020f3b3
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 10 deletions.
28 changes: 20 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ jobs:
include:
- build: x86_64-linux
os: ubuntu-latest
docker: true
- build: aarch64-linux
os: ubuntu-latest
target: aarch64-unknown-linux-gnu
docker: true
- build: x86_64-macos
os: macos-latest
- build: aarch64-macos
Expand Down Expand Up @@ -44,23 +49,30 @@ jobs:
- name: Set build target for cross-compiling
if: matrix.target != ''
run: |
echo CARGO_BUILD_TARGET=${{ matrix.target }} >> $GITHUB_ENV
echo JNILIB_RUST_TARGET=${{ matrix.target }} >> $GITHUB_ENV
echo GRADLE_ARGS="${GRADLE_ARGS} -x test">> $GITHUB_ENV
echo CARGO_BUILD_TARGET=${{ matrix.target }} >> build_env.txt
echo JNILIB_RUST_TARGET=${{ matrix.target }} >> build_env.txt
echo GRADLE_ARGS="${GRADLE_ARGS} -x test">> build_env.txt
cat build_env.txt >> $GITHUB_ENV
rustup target add ${{ matrix.target }}
# Run gradle in a docker container to build the JNI lib on Linux for old glibc compatibility
- name: Build with Gradle (Linux)
if: ${{ startsWith(matrix.os, 'ubuntu') }}
if: ${{ matrix.docker }}
run: |
docker build -t build-image ./ci/docker/x86_64-linux
docker run --rm --volume $PWD:/build --workdir /build build-image ./gradlew build copyJniLib -x javadoc
if [ ! -e build_env.txt ]; then
touch build_env.txt
fi
docker build -t build-image ./ci/docker/${{ matrix.build }}
docker run --rm --volume $PWD:/build --workdir /build \
--env-file build_env.txt \
build-image \
./gradlew build copyJniLib -x javadoc ${GRADLE_ARGS}
# Otherwise, run gradle normally to build the JNI lib
- name: Build with Gradle
if: ${{ !startsWith(matrix.os, 'ubuntu') }}
if: ${{ !matrix.docker }}
run: ./gradlew build copyJniLib ${GRADLE_ARGS}
- name: List shared library files
run:
ls build/jni-libs
file build/jni-libs/*
- name: Save JNI lib output
if: startsWith(github.ref, 'refs/tags/')
uses: actions/upload-artifact@v2
Expand Down
2 changes: 2 additions & 0 deletions ci/docker/aarch64-linux/.cargo_config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"
23 changes: 23 additions & 0 deletions ci/docker/aarch64-linux/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM ubuntu:16.04

ARG TOOLCHAIN=nightly-2022-12-11

RUN apt-get update && apt-get install -y curl git gcc openjdk-8-jdk-headless gcc-aarch64-linux-gnu ca-certificates

ENV PATH=$PATH:/rust/bin:/root/.cargo/bin
ENV JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
ENV CARGO_BUILD_TARGET=aarch64-unknown-linux-gnu
ENV JNILIB_RUST_TARGET=aarch64-unknown-linux-gnu

# Confirm that the JAVA_HOME var is set correctly
RUN ls ${JAVA_HOME}/bin/java

# Install rustup
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain=${TOOLCHAIN} --profile=minimal && rustc --version
RUN rustup component add rustfmt

RUN rustup target add ${CARGO_BUILD_TARGET}

# Workaround for https://github.com/rust-lang/cargo/issues/4133
# Linker tool needs to be specified explicitly
COPY .cargo_config /root/.cargo/config
6 changes: 4 additions & 2 deletions ci/docker/x86_64-linux/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ ARG TOOLCHAIN=nightly-2022-12-11
RUN yum install -y git gcc java-11-openjdk

ENV PATH=$PATH:/rust/bin:/root/.cargo/bin
ENV JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.19.0.7-1.el7_9.x86_64
ENV JAVA_HOME=/etc/alternatives/jre_11_openjdk

# Confirm that the JAVA_HOME var is set correctly
RUN ls ${JAVA_HOME}/bin/java

# Install rustup
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain=${TOOLCHAIN} --profile=minimal && rustc --version
RUN rustup component add rustfmt

Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ private enum Arch {
@AllArgsConstructor
private enum Platform {
LINUX(Os.LINUX, Arch.X86_64, "lib", ".so"),
LINUX_AARCH64(Os.LINUX, Arch.AARCH64, "lib", ".so"),
MACOS(Os.MACOS, Arch.X86_64, "lib", ".dylib"),
MACOS_AARCH64(Os.MACOS, Arch.AARCH64, "lib", ".dylib"),
WINDOWS(Os.WINDOWS, Arch.X86_64, "", ".dll");
Expand All @@ -111,6 +112,9 @@ private static Platform detectPlatform() {
String os = System.getProperty("os.name").toLowerCase();
String arch = System.getProperty("os.arch").toLowerCase();
if (os.contains("linux")) {
if (arch.equals("aarch64")) {
return Platform.LINUX_AARCH64;
}
return Platform.LINUX;
}
if (os.contains("mac os") || os.contains("darwin")) {
Expand Down

0 comments on commit 020f3b3

Please sign in to comment.