Skip to content

Commit

Permalink
add aarch64 cross-compilation bits to CI and release (#436)
Browse files Browse the repository at this point in the history
  • Loading branch information
froydnj authored Jun 20, 2023
1 parent 56c4a3e commit fc2fe3b
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 21 deletions.
21 changes: 16 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,15 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, ubuntu-20.04, macos-latest]
include:
- os: ubuntu-latest
target: native
- os: ubuntu-20.04
target: native
- os: macos-latest
target: native
- os: ubuntu-20.04
target: aarch64-unknown-linux-gnu
steps:
- uses: actions/checkout@v2
with:
Expand All @@ -63,24 +71,27 @@ jobs:
toolchain: 1.63.0
override: true
profile: minimal
target: aarch64-unknown-linux-gnu
- uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-cargo-2-${{ hashFiles('**/Cargo.lock') }}
key: ${{ runner.os }}-${{ matrix.target }}-cargo-2-${{ hashFiles('**/Cargo.lock') }}
- uses: actions/cache@v2
with:
path: |
librubyfmt/ruby_checkout
key: ${{ runner.os }}-ruby-v1-${{ hashFiles('.git/modules/librubyfmt/ruby_checkout/HEAD') }}
key: ${{ runner.os }}-${{ matrix.target }}-ruby-v1-${{ hashFiles('.git/modules/librubyfmt/ruby_checkout/HEAD') }}
- if: runner.os == 'macOS'
run: |
brew install automake bison
echo "/usr/local/opt/bison/bin:$PATH" >> $GITHUB_PATH
- run: ./script/test.sh
env:
TARGET: ${{ matrix.target }}
- uses: actions/upload-artifact@v3
with:
name: rubyfmt-artifact-${{ matrix.os }}
path: target/release/rubyfmt-main
name: rubyfmt-artifact-${{ matrix.os }}-${{ matrix.target }}
path: target/${{ matrix.target == 'native' && 'release' || format('{0}/release', matrix.target) }}/rubyfmt-main

13 changes: 10 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
include:
- os: ubuntu-latest
target: native
- os: macos-latest
target: native
- os: ubuntu-20.04
target: aarch64-unknown-linux-gnu
steps:
- uses: actions/checkout@v2
with:
Expand All @@ -36,19 +42,20 @@ jobs:
toolchain: 1.63.0
override: true
profile: minimal
target: aarch64-unknown-linux-gnu
- uses: actions/cache@v2
with:
path: |
librubyfmt/ruby_checkout
key: ${{ runner.os }}-ruby-v1-${{ hashFiles('.git/modules/librubyfmt/ruby_checkout/HEAD') }}
key: ${{ runner.os }}-${{matrix.target}}-ruby-v1-${{ hashFiles('.git/modules/librubyfmt/ruby_checkout/HEAD') }}
- if: runner.os == 'macOS'
run: |
brew install automake bison
echo "/usr/local/opt/bison/bin:$PATH" >> $GITHUB_PATH
- run: ./script/make_release
- uses: actions/upload-artifact@v3
with:
name: rubyfmt-release-artifact-${{ matrix.os }}
name: rubyfmt-release-artifact-${{ matrix.os }}-${{ matrix.target }}
path: rubyfmt-*.tar.gz
source-release:
runs-on: macos-latest
Expand Down
66 changes: 54 additions & 12 deletions script/make_release
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,72 @@ mkdir -p "${RELEASE_DIR}"
mkdir -p "${RELEASE_DIR}/lib/"
mkdir -p "${RELEASE_DIR}/include/"

cargo build
cargo build --release
target="${TARGET:-native}"

cp target/release/rubyfmt-main "${RELEASE_DIR}/rubyfmt"
case "$target" in
native)
cargo build
cargo build --release

release_tarball_os="$(uname -s)"
release_tarball_arch="$(uname -a)"
cargo_target_dir_prefix=""
;;
aarch64-unknown-linux-gnu)
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu libc6-dev-arm64-cross

CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc \
CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc \
TARGET_CC=aarch64-linux-gnu-gcc \
TARGET_AR=aarch64-linux-gnu-ar \
cargo build --target aarch64-unknown-linux-gnu

CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc \
CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc \
TARGET_CC=aarch64-linux-gnu-gcc \
TARGET_AR=aarch64-linux-gnu-ar \
cargo build --release --target aarch64-unknown-linux-gnu

cargo_target_dir_prefix="aarch64-unknown-linux-gnu"
# This is kind of a hack, since we're assuming we're on a Linux host.
release_tarball_os="Linux"
release_tarball_arch="aarch64"
;;
*)
echo "Unknown cross-compilation target $target"
exit 1
;;
esac

cargo_dir="target/${cargo_target_dir_prefix}"
cp "${cargo_dir}release/rubyfmt-main" "${RELEASE_DIR}/rubyfmt"
pwd
cp target/debug/rubyfmt-main "${RELEASE_DIR}/rubyfmt-debug"
cp "${cargo_dir}debug/rubyfmt-main" "${RELEASE_DIR}/rubyfmt-debug"
pwd
# shellcheck disable=2012
RELEASE_LIB=$(find target/release/ | grep -i 'librubyfmt-.*\.a$')
RELEASE_LIB=$(find ${cargo_dir}release/ | grep -i 'librubyfmt-.*\.a$')
cp "$RELEASE_LIB" "${RELEASE_DIR}/lib/librubyfmt.a"
pwd
# shellcheck disable=2012
DEBUG_LIB=$(find target/debug/ | grep -i 'librubyfmt-.*\.a$')
DEBUG_LIB=$(find ${cargo_dir}debug/ | grep -i 'librubyfmt-.*\.a$')
cp "$DEBUG_LIB" "${RELEASE_DIR}/lib/librubyfmt-debug.a"
pwd
cp librubyfmt/include/rubyfmt.h "${RELEASE_DIR}/include/rubyfmt.h"
pwd
cp RELEASE_README.md "${RELEASE_DIR}/RELEASE_README"

# check the binary
RES=$(echo 'a(1)' | "${RELEASE_DIR}/rubyfmt")
if [ "$RES" != "a(1)" ]; then
echo "formatting failed"
exit 1
fi
case "$target" in
native)
RES=$(echo 'a(1)' | "${RELEASE_DIR}/rubyfmt")
if [ "$RES" != "a(1)" ]; then
echo "formatting failed"
exit 1
fi
;;
*)
;;
esac

tar -cvz -f "rubyfmt-${TAG}-$(uname -s).tar.gz" "${RELEASE_DIR}"
tar -cvz -f "rubyfmt-${TAG}-${release_tarball_os}-${release_tarball_arch}.tar.gz" "${RELEASE_DIR}"
26 changes: 25 additions & 1 deletion script/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,31 @@ set -euxo pipefail
rm -rf tmp/
source ./script/functions.sh

cargo build --release
target="${TARGET:-native}"

case "$target" in
native)
cargo build --release
;;
aarch64-unknown-linux-gnu)
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu libc6-dev-arm64-cross

CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc \
CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc \
TARGET_CC=aarch64-linux-gnu-gcc \
TARGET_AR=aarch64-linux-gnu-ar \
cargo build --release --target aarch64-unknown-linux-gnu

# Don't try to test things: even with QEMU support, it would take a long time.
exit 0
;;
*)
echo "Unknown cross-compilation target $target"
exit 1
;;
esac


export RUBYFMT_USE_RELEASE=1
uname -a
Expand Down

0 comments on commit fc2fe3b

Please sign in to comment.