Skip to content

Commit

Permalink
ci: demonstrate cross compilation (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheButlah authored Oct 5, 2024
1 parent 10f9a44 commit 26a8817
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 5 deletions.
84 changes: 79 additions & 5 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
name: Release
on:
workflow_dispatch:
inputs:
component:
description: "The component to release"
required: true
type: choice
options:
- identity-server

jobs:
build:
name: Build the code for each platform
runs-on: ubuntu-24.04
# unless we use osxcross, we can only target mac from a mac machine
runs-on: macos-14
env:
LINUX: x86_64-unknown-linux-musl
LINUX_ARM: aarch64-unknown-linux-musl
WINDOWS: x86_64-pc-windows-gnu
MACOS: aarch64-apple-darwin
steps:
- uses: actions/[email protected]
- uses: mlugg/[email protected]
Expand All @@ -22,7 +35,68 @@ jobs:
- name: Cargo zigbuild
run: |
cargo zigbuild \
--target x86_64-unknown-linux-musl \
--target aarch64-unknown-linux-musl \
--target x86_64-pc-windows-gnu \
--all
--target ${LINUX} \
--target ${LINUX_ARM} \
--target ${WINDOWS} \
--target ${MACOS} \
--profile artifact \
-p ${{ inputs.component }}
- name: Arrange artifact directory
run: |
set -Eeuxo pipefail
mkdir artifacts
component="${{ inputs.component }}"
for f in target/*/artifact/"${component}"{,\.exe}; do
target_triple="$(echo "${f}" | cut -d '/' -f2)"
case "${target_triple}" in
"${LINUX}")
mv "${f}" "artifacts/${component}-linux-x86_64" ;;
"${LINUX_ARM}")
mv "${f}" "artifacts/${component}-linux-aarch64" ;;
"${WINDOWS}")
mv "${f}" "artifacts/${component}-windows-x86_64.exe" ;;
"${MACOS}")
mv "${f}" "artifacts/${component}-macos-aarch64" ;;
*)
echo "Unexpected target triple"
exit 1 ;;
esac
done
ls -aRsh artifacts
- name: Compute sha256 checksums
run: |
set -Eeuxo pipefail
pushd artifacts
for f in *; do
shasum -a 256 "${f}" > "${f}.sha256"
done
ls -aRsh
popd
- name: Upload artifacts
uses: actions/[email protected]
with:
name: rust
if-no-files-found: error
retention-days: 30
path: |
artifacts
release:
name: Create Release and Tag
runs-on: ubuntu-24.04
needs: build
steps:
- name: Download Rust Artifacts
uses: actions/[email protected]
with:
# didn't specify artifact name, so all artifacts are downloaded and merged
# into the `artifacts` dir
path: artifacts
merge-multiple: true

- name: List Downloaded Artifacts
run: ls -aRsh artifacts

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/.idea
/.vscode
/target
.intentionally-empty-file.o

*.swp
.DS_Store
Expand Down
19 changes: 19 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,29 @@ General guidance:
- Prefer [newtypes][newtype] for stronger type safety whenever possible. Types document
code better than comments.

## Cross compilation

You will also need to install:
* [cargo-zigbuild][cargo-zigbuild], with version `0.19.2` or later.
* [zig][zig], with version `0.13.0` or later.

The following targets are known to work:
- `x86_64-unknown-linux-gnu`
- `aarch64-unknown-linux-gnu`
- `x86_64-pc-windows-gnu`
- `aarch64-apple-darwin`

If you plan to target MacOS, you will need to be using an apple device on the host. It
is technically possible using [osxcross][osxcross], if you figure out how to do that,
let me know.

[workspace inheritance]: https://doc.rust-lang.org/cargo/reference/workspaces.html#the-package-table
[vscode fmt]: https://stackoverflow.com/a/54665086
[rustrover fmt]: https://www.jetbrains.com/help/rust/rustfmt.html#rustfmt-on-save
[neovim fmt]: https://www.jvt.me/posts/2022/03/01/neovim-format-on-save/
[sansio]: https://sans-io.readthedocs.io/
[carmack style]: https://cbarrete.com/carmack.html
[newtype]: https://rust-lang.github.io/api-guidelines/type-safety.html#c-newtype
[osxcross]: https://github.com/tpoechtrager/osxcross
[cargo-zigbuild]: https://github.com/rust-cross/cargo-zigbuild
[zig]: https://ziglang.org/learn/getting-started/#managers

0 comments on commit 26a8817

Please sign in to comment.