Skip to content

Commit

Permalink
feat: cross compile amd64 Linux binaries with Musl (#1757)
Browse files Browse the repository at this point in the history
  • Loading branch information
leruaa authored Nov 14, 2024
1 parent 588286b commit 12f212e
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 9 deletions.
84 changes: 81 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ jobs:
# `platform` and `arch`: Used in tarball names
# `svm`: target platform to use for the Solc binary: https://github.com/roynalnaruto/svm-rs/blob/84cbe0ac705becabdc13168bae28a45ad2299749/svm-builds/build.rs#L4-L24
- runner: ubuntu-latest
target: x86_64-unknown-linux-gnu
target: x86_64-unknown-linux-musl
svm_target_platform: linux-amd64
platform: linux
arch: amd64
- runner: warp-ubuntu-latest-arm64-4x
target: aarch64-unknown-linux-gnu
target: aarch64-unknown-linux-musl
svm_target_platform: linux-aarch64
platform: linux
arch: arm64
Expand Down Expand Up @@ -148,12 +148,19 @@ jobs:
echo "MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx --show-sdk-platform-version)" >> $GITHUB_ENV
- name: Linux ARM setup
if: matrix.target == 'aarch64-unknown-linux-gnu'
if: matrix.target == 'aarch64-unknown-linux-musl'
run: |
sudo apt-get update -y
sudo apt-get install -y gcc-aarch64-linux-gnu
echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
- name: Musl setup
if: contains(matrix.target, 'musl')
run: |
sudo apt-get update -y
sudo apt-get install -y musl-tools musl-dev
rustup target add ${{ matrix.target }}
- name: Build binaries
env:
SVM_TARGET_PLATFORM: ${{ matrix.svm_target_platform }}
Expand Down Expand Up @@ -225,6 +232,77 @@ jobs:
${{ steps.artifacts.outputs.file_name }}
${{ steps.man.outputs.cargo_prove_man }}
toolchain-test:
name: "Test toolchain installation (${{ matrix.name }})"
needs: release
strategy:
fail-fast: false
matrix:
include:
- name: "Ubuntu 24.04 (x86_64)"
runner: "ubuntu-24.04"
- name: "Ubuntu 22.04 (x86_64)"
runner: "ubuntu-22.04"
- name: "Ubuntu 20.04 (x86_64)"
runner: "ubuntu-20.04"
- name: "macOS Monterey (x86_64)"
runner: "macos-12"
- name: "macOS Ventura (x86_64)"
runner: "macos-13"
- name: "macOS Sonoma (ARM64)"
runner: "macos-14"

runs-on: "${{ matrix.runner }}"
steps:
- name: "Checkout source code"
uses: "actions/checkout@v4"

- name: "Install SP1"
env:
SP1UP_VERSION: ${{ github.ref_name }}
run: |
cd sp1up
chmod +x sp1up
./sp1up --token ${{ secrets.GITHUB_TOKEN }}
- name: "Create SP1 project from template"
run: |
$HOME/.sp1/bin/cargo-prove prove new --bare hello
- name: "Build SP1 project"
run: |
cd ./hello/program
$HOME/.sp1/bin/cargo-prove prove build
toolchain-test-ec2:
name: "Test toolchain installation (${{ matrix.name }})"
needs: release
strategy:
fail-fast: false
matrix:
include:
# AMI from `us-east-1`
- name: "Debian 12 (x86_64)"
ec2-instance: "c5.2xlarge"
ami: "ami-064519b8c76274859"
volume: "/dev/xvda"
- name: "Debian 12 (ARM64)"
ec2-instance: "c6g.2xlarge"
ami: "ami-0789039e34e739d67"
volume: "/dev/xvda"
uses: "./.github/workflows/toolchain-ec2.yml"
with:
image-id: "${{ matrix.ami }}"
instance-type: "${{ matrix.ec2-instance }}"
root-volume: "${{ matrix.volume }}"
secrets:
AWS_REGION: "${{ secrets.AWS_REGION }}"
AWS_ACCESS_KEY_ID: "${{ secrets.AWS_ACCESS_KEY_ID }}"
AWS_SECRET_ACCESS_KEY: "${{ secrets.AWS_SECRET_ACCESS_KEY }}"
AWS_SUBNET_ID: "${{ secrets.AWS_SUBNET_ID }}"
AWS_SG_ID: "${{ secrets.AWS_SG_ID }}"
GH_PAT: ${{ secrets.GH_PAT }}

cleanup:
name: Release cleanup
runs-on: ubuntu-latest
Expand Down
19 changes: 14 additions & 5 deletions .github/workflows/toolchain-ec2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,24 @@ jobs:
- name: "Install build dependencies"
run: |
sudo apt-get update
sudo apt-get install -y build-essential pkg-config libssl-dev
sudo apt-get install -y build-essential pkg-config libssl-dev git
- name: "Install cargo-prove"
- name: "Install SP1"
env:
SP1UP_VERSION: ${{ github.ref_name }}
run: |
cargo install --locked --path ./crates/cli
cd sp1up
chmod +x sp1up
./sp1up --token ${{ secrets.GH_PAT }}
- name: "Install SP1 toolchain"
- name: "Create SP1 project from template"
run: |
cargo prove install-toolchain --token ${{ secrets.GH_PAT }}
$HOME/.sp1/bin/cargo-prove prove new --bare hello
- name: "Build SP1 project"
run: |
cd ./hello/program
$HOME/.sp1/bin/cargo-prove prove build
stop-runner:
name: "Stop self-hosted EC2 runner"
Expand Down
9 changes: 8 additions & 1 deletion crates/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,14 @@ pub fn is_supported_target() -> bool {
}

pub fn get_target() -> String {
target_lexicon::HOST.to_string()
let mut target: target_lexicon::Triple = target_lexicon::HOST;

// We don't want to operate on the musl toolchain, even if the CLI was compiled with musl
if target.environment == target_lexicon::Environment::Musl {
target.environment = target_lexicon::Environment::Gnu;
}

target.to_string()
}

pub async fn get_toolchain_download_url(client: &Client, target: String) -> String {
Expand Down

0 comments on commit 12f212e

Please sign in to comment.