-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(CI): rework cross compilation (#258)
- Loading branch information
1 parent
b526c60
commit 6c628d0
Showing
7 changed files
with
118 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# apt install gcc-arm-linux-gnueabihf | ||
[target.armv7-unknown-linux-gnueabihf] | ||
linker = "arm-linux-gnueabihf-gcc" | ||
|
||
# apt install gcc-aarch64-linux-gnu | ||
[target.aarch64-unknown-linux-gnu] | ||
linker = "aarch64-linux-gnu-gcc" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,58 +2,37 @@ | |
name: toolchain | ||
description: "Install toolchain" | ||
|
||
inputs: | ||
bin-cache: | ||
description: 'Where to keep cached bins' | ||
required: false | ||
default: /home/runner/.bin-cache | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Setup mise | ||
uses: jdx/mise-action@v2 | ||
with: | ||
# version: TODO: | ||
install: true | ||
cache: true | ||
experimental: true | ||
|
||
- name: Setup rust caching | ||
uses: Swatinem/rust-cache@v2 | ||
with: | ||
shared-key: toolchain | ||
cache-directories: ${{ inputs.bin-cache }} | ||
shared-key: toolchains | ||
|
||
- name: "Set environment variables used by toolchain" | ||
shell: bash | ||
run: | | ||
echo CARGO_TERM_COLOR=always >> $GITHUB_ENV | ||
echo CARGO_INCREMENTAL=0 >> $GITHUB_ENV | ||
echo RUST_BACKTRACE=1 >> $GITHUB_ENV | ||
shell: bash | ||
|
||
- name: "Install rust toolchain" | ||
shell: bash | ||
run: | | ||
# Make sure bin-cache dir exists with something in it | ||
mkdir -p ${{ inputs.bin-cache }} | ||
touch ${{ inputs.bin-cache }}/empty | ||
cp ${{ inputs.bin-cache }}/* /home/runner/.cargo/bin | ||
# Install everything needed | ||
mise run setup:toolchain | ||
# Install dependencies | ||
cargo install [email protected] # TODO: | ||
cargo install [email protected] # TODO: | ||
- name: Install rust toolchain | ||
uses: dtolnay/rust-toolchain@stable | ||
with: | ||
targets: | | ||
x86_64-unknown-linux-gnu, | ||
armv7-unknown-linux-gnueabihf, | ||
aarch64-unknown-linux-gnu | ||
# Cache these binaries | ||
for f in sqlx cargo-tarpaulin; do | ||
cp -f "/home/runner/.cargo/bin/$f" "${{ inputs.bin-cache }}" | ||
done | ||
- name: Install cross compilation dependencies | ||
uses: awalsh128/cache-apt-pkgs-action@latest | ||
with: | ||
version: 1.0 | ||
packages: gcc-arm-linux-gnueabihf gcc-aarch64-linux-gnu | ||
|
||
- name: "Setup DB" | ||
- name: Install cargo dependencies | ||
shell: bash | ||
run: | | ||
mise run setup:db | ||
cargo install [email protected] # TODO: | ||
cargo install [email protected] # TODO: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,6 @@ env: | |
REGISTRY: ghcr.io | ||
IMAGE_NAME: ${{ github.repository }} | ||
VERSION: ${{ github.ref_name }} | ||
DATABASE_URL: sqlite:data/spis.db | ||
|
||
jobs: | ||
ci: | ||
|
@@ -35,22 +34,10 @@ jobs: | |
- name: Install rust toolchain | ||
uses: ./.github/actions/toolchain | ||
|
||
- name: Docker pulls images. | ||
uses: ScribeMD/[email protected] | ||
with: | ||
key: docker-${{ runner.os }} | ||
|
||
- name: Build binary | ||
uses: houseabsolute/actions-rust-cross@v0 | ||
with: | ||
target: ${{ matrix.target }} | ||
args: "--locked --release" | ||
cross-version: v0.2.5 | ||
|
||
- name: Move to release dir | ||
run: | | ||
mkdir release | ||
mv target/${{ matrix.target }}/release/spis release/spis-${{ matrix.target }} | ||
- name: Build spis release | ||
run: make release/spis-${{ matrix.target }} | ||
env: | ||
DATABASE_URL: sqlite:data/spis.db | ||
|
||
- name: Store artifact | ||
uses: actions/upload-artifact@v4 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
X86_64:=x86_64-unknown-linux-gnu | ||
ARMV7:=armv7-unknown-linux-gnueabihf | ||
AARCH64:=aarch64-unknown-linux-gnu | ||
|
||
DATABASE:=$(shell echo ${DATABASE_URL} | awk -F':' '{print $$2}') | ||
MEDIA_DIR:=data/media | ||
THUMBNAIL_DIR:=data/thumbnails | ||
|
||
${DATABASE}: | ||
mkdir -p $(shell dirname ${DATABASE}) | ||
sqlx database create | ||
sqlx migrate run --source migrations | ||
|
||
${MEDIA_DIR}: | ||
mkdir -p ${MEDIA_DIR} | ||
|
||
${THUMBNAIL_DIR}: | ||
mkdir -p ${THUMBNAIL_DIR} | ||
|
||
_release: ${DATABASE} | ||
cargo build --locked --release --target ${TARGET} | ||
mkdir -p release | ||
cp target/${TARGET}/release/spis release/spis-${TARGET} | ||
|
||
release/spis-${X86_64}: | ||
TARGET=${X86_64} $(MAKE) --no-print-directory _release | ||
|
||
release/spis-${ARMV7}: | ||
TARGET=${ARMV7} $(MAKE) --no-print-directory _release | ||
|
||
release/spis-${AARCH64}: | ||
TARGET=${AARCH64} $(MAKE) --no-print-directory _release | ||
|
||
.PHONY: toolchain | ||
toolchain: | ||
rustup show | ||
|
||
.PHONY: dev-clippy | ||
dev-clippy: ${DATABASE} | ||
watchexec --stop-timeout=0 -r -e rs,toml,html,css -- \ | ||
cargo clippy -F dev -- --no-deps -D warnings | ||
|
||
.PHONY: dev-spis | ||
dev-spis: ${DATABASE} ${MEDIA_DIR} ${THUMBNAIL_DIR} | ||
watchexec --stop-timeout=0 -r -e rs,toml,html,css -- \ | ||
cargo run --color always -F dev | ||
|
||
.PHONY: lint-fmt | ||
lint-fmt: | ||
cargo fmt -- --check | ||
|
||
.PHONY: lint-clippy | ||
lint-clippy: ${DATABASE} | ||
cargo clippy -F dev -- --no-deps -D warnings | ||
|
||
.PHONY: lint | ||
lint: lint-fmt lint-clippy | ||
|
||
.PHONY: test | ||
test: ${DATABASE} ${MEDIA_DIR} ${THUMBNAIL_DIR} | ||
cargo tarpaulin --ignore-tests --color always --timeout 120 --skip-clean --out Xml | ||
|
||
.PHONY: docker-build | ||
docker-build: release/spis-${X86_64} | ||
docker build -t spis-local -f docker/Dockerfile . | ||
|
||
.PHONY: docker-run | ||
docker-run: docker-build | ||
docker run -it --rm \ | ||
-p 8080:8080 \ | ||
-v ${PWD}/data/media:/var/lib/spis/media \ | ||
-e SPIS_PROCESSING_RUN_ON_START=true \ | ||
spis-local | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -rf target release data/spis.db data/thumbnails | ||
cargo clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
[toolchain] | ||
channel = "1.80.0" | ||
components = ["rustfmt", "rust-src", "rust-std", "clippy"] | ||
targets = ["x86_64-unknown-linux-gnu"] | ||
targets = [ | ||
"x86_64-unknown-linux-gnu", | ||
"armv7-unknown-linux-gnueabihf", | ||
"aarch64-unknown-linux-gnu", | ||
] | ||
profile = "minimal" |