Skip to content

Commit

Permalink
Refactor build workflow to matrix.
Browse files Browse the repository at this point in the history
This splits the building process in multiple jobs, avoiding running out
of diskspace because of installing all the different target toolchains
for the different architectures.
  • Loading branch information
brocaar committed Sep 6, 2023
1 parent 2e7a8bb commit b916ef9
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 48 deletions.
20 changes: 14 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ jobs:
uses: actions/checkout@v2
-
name: Install Nix
uses: cachix/install-nix-action@v20
uses: cachix/install-nix-action@v22
with:
nix_path: nixpkgs=channel:nixos-22.11
nix_path: nixpkgs=channel:nixos-23.05
-
name: Cargo cache
uses: actions/cache@v3
Expand All @@ -41,15 +41,23 @@ jobs:
needs: tests
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
strategy:
matrix:
target:
- aarch64-unknown-linux-musl
- armv5te-unknown-linux-musleabi
- armv7-unknown-linux-musleabihf
- mips-unknown-linux-musl
- mipsel-unknown-linux-musl
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Install Nix
uses: cachix/install-nix-action@v20
uses: cachix/install-nix-action@v22
with:
nix_path: nixpkgs=channel:nixos-22.11
nix_path: nixpkgs=channel:nixos-23.05
-
name: Cargo cache
uses: actions/cache@v3
Expand All @@ -60,10 +68,10 @@ jobs:
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-dist-${{ hashFiles('**/Cargo.lock') }}
key: ${{ runner.os }}-cargo-dist-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}
-
name: Build distributables
run: nix-shell --command "make dist"
run: nix-shell --command "make dist-${{ matrix.target }}"
-
name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
Expand Down
116 changes: 74 additions & 42 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,69 +1,74 @@
.PHONY: dist

# Compile the binaries for all targets.
build:
build: build-aarch64-unknown-linux-musl \
build-armv5te-unknown-linux-musleabi \
build-armv7-unknown-linux-musleabihf \
build-mips-unknown-linux-musl \
build-mipsel-unknown-linux-musl

build-aarch64-unknown-linux-musl:
cross build --target aarch64-unknown-linux-musl --release

build-armv5te-unknown-linux-musleabi:
cross build --target armv5te-unknown-linux-musleabi --release

build-armv7-unknown-linux-musleabihf:
cross build --target armv7-unknown-linux-musleabihf --release

build-mips-unknown-linux-musl:
cross build --target mips-unknown-linux-musl --release --no-default-features --features semtech_udp

build-mipsel-unknown-linux-musl:
cross build --target mipsel-unknown-linux-musl --release --no-default-features --features semtech_udp

# Build distributable binaries.
dist: build package
# Build distributable binaries for all targets.
dist: dist-aarch64-unknown-linux-musl \
dist-armv5te-unknown-linux-musleabi \
dist-armv7-unknown-linux-musleabihf \
dist-mips-unknown-linux-musl \
dist-mipsel-unknown-linux-musl

# Update the version.
version:
test -n "$(VERSION)"
sed -i 's/^version.*/version = "$(VERSION)"/g' ./Cargo.toml
make test
git add .
git commit -v -m "Bump version to $(VERSION)"
git tag -a v$(VERSION) -m "v$(VERSION)"
dist-aarch64-unknown-linux-musl: build-aarch64-unknown-linux-musl package-aarch64-unknown-linux-musl

# Cleanup dist.
clean:
cargo clean
rm -rf dist
dist-armv5te-unknown-linux-musleabi: build-armv5te-unknown-linux-musleabi package-armv5te-unknown-linux-musleabi

# Run tests
test:
cargo clippy --no-deps
cargo test
dist-armv7-unknown-linux-musleabihf: build-armv7-unknown-linux-musleabihf package-armv7-unknown-linux-musleabihf

# Enter the devshell.
devshell:
nix-shell
dist-mips-unknown-linux-musl: build-mips-unknown-linux-musl package-mips-unknown-linux-musl

# Enter the Docker based devshell.
docker-devshell:
docker-compose run --rm chirpstack-mqtt-forwarder
dist-mipsel-unknown-linux-musl: build-mipsel-unknown-linux-musl package-mipsel-unknown-linux-musl

# Package the compiled binaries.
package: package-targz-armv7hf package-targz-arm64 package-deb \
package-dragino \
package-multitech-conduit \
package-multitech-conduit-ap \
package-tektelic-kona \
package-kerlink-klkgw \
package-rak-ramips-24kec

package-targz-armv7hf:
# Package the compiled binaries
package-aarch64-unknown-linux-musl:
$(eval PKG_VERSION := $(shell cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version'))
mkdir -p dist
tar -czvf dist/chirpstack-mqtt-forwarder_$(PKG_VERSION)_armv7hf.tar.gz -C target/armv7-unknown-linux-musleabihf/release chirpstack-mqtt-forwarder

package-targz-arm64:
$(eval PKG_VERSION := $(shell cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version'))
mkdir -p dist
# .tar.gz
tar -czvf dist/chirpstack-mqtt-forwarder_$(PKG_VERSION)_arm64.tar.gz -C target/aarch64-unknown-linux-musl/release chirpstack-mqtt-forwarder

package-deb:
# .deb
cargo deb --target aarch64-unknown-linux-musl --no-build --no-strip
cargo deb --target armv7-unknown-linux-musleabihf --no-build --no-strip
cp target/aarch64-unknown-linux-musl/debian/*.deb ../dist

package-armv7-unknown-linux-musleabihf: package-tektelic-kona package-kerlink-klkgw
$(eval PKG_VERSION := $(shell cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version'))
mkdir -p dist

# .tar.gz
tar -czvf dist/chirpstack-mqtt-forwarder_$(PKG_VERSION)_armv7hf.tar.gz -C target/armv7-unknown-linux-musleabihf/release chirpstack-mqtt-forwarder

# .deb
cargo deb --target armv7-unknown-linux-musleabihf --no-build --no-strip
cp target/armv7-unknown-linux-musleabihf/debian/*.deb ../dist
cp target/aarch64-unknown-linux-musl/debian/*.deb ../dist

package-armv5te-unknown-linux-musleabi: package-multitech-conduit package-multitech-conduit-ap

package-mips-unknown-linux-musl: package-dragino

package-mipsel-unknown-linux-musl: package-rak-ramips-24kec

# Gateway specific packaging.
package-dragino:
cd packaging/vendor/dragino/mips_24kc && ./package.sh
mkdir -p dist/vendor/dragino/mips_24kc
Expand Down Expand Up @@ -93,3 +98,30 @@ package-kerlink-klkgw:
cd packaging/vendor/kerlink/klkgw && ./package.sh
mkdir -p dist/vendor/kerlink/klkgw
cp packaging/vendor/kerlink/klkgw/*.ipk dist/vendor/kerlink/klkgw

# Update the version.
version:
test -n "$(VERSION)"
sed -i 's/^version.*/version = "$(VERSION)"/g' ./Cargo.toml
make test
git add .
git commit -v -m "Bump version to $(VERSION)"
git tag -a v$(VERSION) -m "v$(VERSION)"

# Cleanup dist.
clean:
cargo clean
rm -rf dist

# Run tests
test:
cargo clippy --no-deps
cargo test

# Enter the devshell.
devshell:
nix-shell

# Enter the Docker based devshell.
docker-devshell:
docker-compose run --rm chirpstack-mqtt-forwarder

0 comments on commit b916ef9

Please sign in to comment.