Skip to content

Commit

Permalink
Simplify build process with cross
Browse files Browse the repository at this point in the history
Refactors actions builds to use cross for cross-compilation instead of
manually setting up the infrastructure which is extremely fragile, and
makes adding new archs hard.

Builds for armv7hf and armv6hf are now made as well, although they
aren't part of the docker image - they'll only be released in binaries.
If there's no intrest in these they'll probably get removed at some
point.

This also simplifies the Dockerfile a bit, making it plug-n-play with
any rust platform that has first-party host tools.
  • Loading branch information
Insprill committed May 31, 2024
1 parent b1a6cf9 commit d2e35e8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 35 deletions.
9 changes: 0 additions & 9 deletions .cargo/config.toml

This file was deleted.

40 changes: 21 additions & 19 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on: [ push, pull_request ]

env:
CARGO_TERM_COLOR: always
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER: aarch64-linux-gnu-gcc

jobs:
build:
Expand All @@ -13,44 +12,47 @@ jobs:
fail-fast: false
matrix:
include:
# x86_64
- target: 'x86_64-pc-windows-msvc'
os: windows
- target: 'x86_64-unknown-linux-gnu'
os: ubuntu
- target: 'x86_64-unknown-linux-musl'
os: ubuntu
# aarch64 (armv8)
- target: 'aarch64-unknown-linux-gnu'
os: ubuntu
- target: 'aarch64-unknown-linux-musl'
os: ubuntu
# armv7
- target: 'armv7-unknown-linux-gnueabihf'
os: ubuntu
- target: 'armv7-unknown-linux-musleabihf'
os: ubuntu
# armv6
- target: 'arm-unknown-linux-gnueabihf'
os: ubuntu
- target: 'arm-unknown-linux-musleabihf'
os: ubuntu
steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Install musl Dependencies
if: contains(matrix.target, 'musl')
run: sudo apt-get update && sudo apt-get install musl-tools

- name: Install aarch64 Dependencies
if: contains(matrix.target, 'aarch64')
run: sudo apt-get update && sudo apt-get install gcc-aarch64-linux-gnu

- name: Setup aarch64 musl compiler
if: contains(matrix.target, 'aarch64') && contains(matrix.target, 'musl')
run: |
wget https://musl.cc/aarch64-linux-musl-cross.tgz
tar -xvzf aarch64-linux-musl-cross.tgz
echo "CC=$(pwd)/aarch64-linux-musl-cross/bin/aarch64-linux-musl-gcc" >> "$GITHUB_ENV"
- name: Install Target
run: rustup target add ${{ matrix.target }}
- name: Install Cross
run: cargo install --git https://github.com/cross-rs/cross cross

- name: Setup Cache
uses: Swatinem/rust-cache@v2

- name: Build
# cross doesn't support msvc toolchains out-of-the-box (https://github.com/cross-rs/cross-toolchains)
- name: Build (Windows)
if: matrix.os == 'windows'
run: cargo build --release --target=${{ matrix.target }}

- name: Build (Linux)
if: matrix.os == 'ubuntu'
run: cross build --release --target=${{ matrix.target }}

- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
Expand Down
9 changes: 2 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,14 @@
####################################################################################################
FROM rust:alpine AS builder

RUN apk add --no-cache musl-dev gcc # GCC needed for aarch64 builds
RUN apk add --no-cache musl-dev

WORKDIR /intellectual

COPY . .

# Figure out what arch we're on
RUN BASE_TARGET=-unknown-linux-musl; \
case "$(uname -m)" in \
x86_64) TARGET=x86_64$BASE_TARGET ;; \
aarch64) TARGET=aarch64$BASE_TARGET ;; \
*) echo "Unsupported architecture"; exit 1 ;; \
esac; \
RUN TARGET=$(uname -m)-unknown-linux-musl; \
# Set environment variables so the build has git info
export $(cat .env | xargs); \
# Build the binary
Expand Down

0 comments on commit d2e35e8

Please sign in to comment.