Skip to content

Commit

Permalink
Merge pull request #103 from ereslibre/cross-compile
Browse files Browse the repository at this point in the history
 Build kwctl for different architectures and OS's
  • Loading branch information
ereslibre authored Jan 19, 2022
2 parents 3206b03 + 4a42cd5 commit efc69ad
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 121 deletions.
12 changes: 12 additions & 0 deletions .cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Due to an issue with linking when cross-compiling, specify the
# linker and archiver for cross-compiled targets.
#
# More information: https://github.com/rust-lang/cargo/issues/4133

[target.x86_64-unknown-linux-musl]
linker = "x86_64-linux-musl-ld"
ar = "x86_64-linux-musl-ar"

[target.aarch64-unknown-linux-musl]
linker = "aarch64-linux-musl-ld"
ar = "aarch64-linux-musl-ar"
238 changes: 140 additions & 98 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,127 +1,124 @@
name: kwctl release

on:
push:
tags:
- 'v*'

env:
CARGO_TERM_COLOR: always
BUILD_TARGET: x86_64-unknown-linux-musl
BINARY_NAME: kwctl
BINARY_FULL_NAME: kwctl-linux-amd64
jobs:
test:
name: Test Suite
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true

# Speed-up runs by using GH cache
- uses: actions/cache@v1
with:
path: ~/.cargo/registry/index
key: index-${{ runner.os }}-${{ github.run_number }}
restore-keys: |
index-${{ runner.os }}-
- uses: actions-rs/cargo@v1
with:
command: generate-lockfile
- uses: actions/cache@v1
with:
path: ~/.cargo/registry/cache
key: registry-${{ runner.os }}-${{ steps.rust-version.outputs.version }}-${{ hashFiles('Cargo.lock') }}
- uses: actions-rs/cargo@v1
with:
command: fetch
- uses: actions/cache@v1
with:
path: target
key: target-${{ runner.os }}-${{ steps.rust-version.outputs.version }}-${{ hashFiles('Cargo.lock') }}
ci:
# A branch is required, and cannot be dynamic - https://github.com/actions/runner/issues/1493
uses: kubewarden/kwctl/.github/workflows/tests.yml@main

- uses: actions-rs/cargo@v1
with:
command: test
args: --workspace

build:
name: Build Release
needs: test
build-linux-x86_64:
name: Build linux (x86_64) binary
runs-on: ubuntu-latest
needs:
- ci
steps:
- uses: actions/checkout@v2

# Speed-up runs by using GH cache
- uses: actions/cache@v1
with:
path: ~/.cargo/registry/index
key: index-${{ runner.os }}-${{ github.run_number }}
restore-keys: |
index-${{ runner.os }}-
- uses: actions-rs/cargo@v1
- name: Setup rust toolchain
uses: actions-rs/toolchain@v1
with:
command: generate-lockfile
- uses: actions/cache@v1
toolchain: stable
- name: Setup musl for x86_64
run: |
curl https://musl.cc/x86_64-linux-musl-cross.tgz | tar -xz
echo "$PWD/x86_64-linux-musl-cross/bin" >> $GITHUB_PATH
- run: rustup target add x86_64-unknown-linux-musl
- name: Build kwctl
env:
CC: x86_64-linux-musl-gcc
run: cargo build --target=x86_64-unknown-linux-musl --release
- run: mv target/x86_64-unknown-linux-musl/release/kwctl kwctl-linux-x86_64
- name: Upload binary
uses: actions/upload-artifact@v2
with:
path: ~/.cargo/registry/cache
key: registry-${{ runner.os }}-${{ steps.rust-version.outputs.version }}-${{ hashFiles('Cargo.lock') }}
- uses: actions-rs/cargo@v1
name: kwctl-linux-x86_64
path: kwctl-linux-x86_64

build-linux-aarch64:
name: Build linux (aarch64) binary
runs-on: ubuntu-latest
needs:
- ci
steps:
- uses: actions/checkout@v2
- name: Setup rust toolchain
uses: actions-rs/toolchain@v1
with:
command: fetch
- uses: actions/cache@v1
toolchain: stable
- name: Setup musl for aarch64
run: |
curl https://musl.cc/aarch64-linux-musl-cross.tgz | tar -xz
echo "$PWD/aarch64-linux-musl-cross/bin" >> $GITHUB_PATH
- run: rustup target add aarch64-unknown-linux-musl
- name: Build kwctl
env:
CC: aarch64-linux-musl-gcc
run: cargo build --target=aarch64-unknown-linux-musl --release
- run: mv target/aarch64-unknown-linux-musl/release/kwctl kwctl-linux-aarch64
- name: Upload binary
uses: actions/upload-artifact@v2
with:
path: target
key: target-${{ runner.os }}-${{ steps.rust-version.outputs.version }}-${{ hashFiles('Cargo.lock') }}
name: kwctl-linux-aarch64
path: kwctl-linux-aarch64

- name: Build-musl
uses: gmiam/rust-musl-action@master
build-darwin-x86_64:
name: Build darwin (x86_64) binary
runs-on: macos-latest
needs:
- ci
steps:
- uses: actions/checkout@v2
- name: Setup rust toolchain
uses: actions-rs/toolchain@v1
with:
args: cargo build --target $BUILD_TARGET --release --bin ${{ env.BINARY_NAME }}

- name: upload kwctl as an artifact
toolchain: stable
- run: rustup target add x86_64-apple-darwin
- name: Build kwctl
run: cargo build --target=x86_64-apple-darwin --release
- run: mv target/x86_64-apple-darwin/release/kwctl kwctl-darwin-x86_64
- name: Upload binary
uses: actions/upload-artifact@v2
with:
name: ${{ env.BINARY_NAME }}
path: target/x86_64-unknown-linux-musl/release/${{ env.BINARY_NAME }}
if-no-files-found: error
name: kwctl-darwin-x86_64
path: kwctl-darwin-x86_64

e2e:
name: Run e2e tests against release binary
needs: build
runs-on: ubuntu-latest
build-windows-x86_64:
name: Build windows (x86_64) binary
runs-on: windows-latest
needs:
- ci
steps:
- uses: actions/checkout@v2
- name: Download artifact
uses: actions/download-artifact@v2
- name: Setup rust toolchain
uses: actions-rs/toolchain@v1
with:
name: ${{ env.BINARY_NAME }}

- name: Run e2e tests
run: |
chmod 755 ${{ env.BINARY_NAME }}
PATH=${PWD}:${PATH} make e2e-tests
toolchain: stable
- run: rustup target add x86_64-pc-windows-msvc
- name: Build kwctl
run: cargo build --target=x86_64-pc-windows-msvc --release
- run: mv target/x86_64-pc-windows-msvc/release/kwctl.exe kwctl-windows-x86_64.exe
- name: Upload binary
uses: actions/upload-artifact@v2
with:
name: kwctl-windows-x86_64
path: kwctl-windows-x86_64.exe

release:
name: Release
needs: e2e
name: Create release
runs-on: ubuntu-latest
needs:
- build-linux-x86_64
- build-linux-aarch64
- build-darwin-x86_64
- build-windows-x86_64
steps:
- name: Download artifact
uses: actions/download-artifact@v2
with:
name: ${{ env.BINARY_NAME }}

- name: Compress binary
run: |
zip -9j ${{ env.BINARY_FULL_NAME }}.zip ${{ env.BINARY_NAME }}

- name: Create Release
id: create_release
id: create-release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -131,13 +128,58 @@ jobs:
draft: false
prerelease: false

- name: Upload Release Asset
id: upload-release-asset
- name: Download linux-x86_64 binary
uses: actions/download-artifact@v2
with:
name: kwctl-linux-x86_64
- name: Publish linux-x86_64 binary
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create-release.outputs.upload_url }}
asset_name: kwctl-linux-x86_64
asset_path: kwctl-linux-x86_64
asset_content_type: application/octet-stream

- name: Download linux-aarch64 binary
uses: actions/download-artifact@v2
with:
name: kwctl-linux-aarch64
- name: Publish linux-aarch64 binary
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create-release.outputs.upload_url }}
asset_name: kwctl-linux-aarch64
asset_path: kwctl-linux-aarch64
asset_content_type: application/octet-stream

- name: Download darwin-x86_64 binary
uses: actions/download-artifact@v2
with:
name: kwctl-darwin-x86_64
- name: Publish darwin-x86_64 binary
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create-release.outputs.upload_url }}
asset_name: kwctl-darwin-x86_64
asset_path: kwctl-darwin-x86_64
asset_content_type: application/octet-stream

- name: Download windows-x86_64 binary
uses: actions/download-artifact@v2
with:
name: kwctl-windows-x86_64
- name: Publish windows-x86_64 binary
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ env.BINARY_FULL_NAME }}.zip
asset_name: ${{ env.BINARY_FULL_NAME }}.zip
upload_url: ${{ steps.create-release.outputs.upload_url }}
asset_name: kwctl-windows-x86_64.exe
asset_path: kwctl-windows-x86_64.exe
asset_content_type: application/octet-stream
11 changes: 4 additions & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
on: [push, pull_request]

name: Continuous integration

on:
- push
- pull_request
- workflow_call
jobs:
check:
name: Check
Expand All @@ -16,7 +17,6 @@ jobs:
- uses: actions-rs/cargo@v1
with:
command: check

test:
name: Test Suite
runs-on: ubuntu-latest
Expand All @@ -31,7 +31,6 @@ jobs:
with:
command: test
args: --workspace

fmt:
name: Rustfmt
runs-on: ubuntu-latest
Expand All @@ -47,7 +46,6 @@ jobs:
with:
command: fmt
args: --all -- --check

clippy:
name: Clippy
runs-on: ubuntu-latest
Expand All @@ -63,7 +61,6 @@ jobs:
with:
command: clippy
args: -- -D warnings

e2e:
name: e2e tests
runs-on: ubuntu-latest
Expand Down
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
/target
/.cargo
/target
11 changes: 5 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit efc69ad

Please sign in to comment.