Skip to content

Commit bfbbd89

Browse files
committed
fix: add aarch64 cross compilation support
1 parent e5ffc67 commit bfbbd89

File tree

5 files changed

+57
-22
lines changed

5 files changed

+57
-22
lines changed

.github/workflows/test.yaml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: 🪲 Test
22

3-
on: [push, pull_request]
3+
on: [push]
44

55
jobs:
66
run-tests:
@@ -11,3 +11,21 @@ jobs:
1111
- uses: actions/checkout@v3
1212
- run: |
1313
make in-docker TARGET='test'
14+
15+
build-x86_64:
16+
name: Run x86_64 build
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- uses: actions/checkout@v3
21+
- run: |
22+
make in-docker TARGET='dist' BUILD_TYPE='debug'
23+
24+
build-aarch64:
25+
name: Run aarch64 build
26+
runs-on: ubuntu-latest
27+
28+
steps:
29+
- uses: actions/checkout@v3
30+
- run: |
31+
make in-docker TARGET='dist' BUILD_TYPE='debug' ARCH='aarch64'

.releaserc.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ plugins:
3333
# Execute commands to build the project
3434
- - "@semantic-release/exec"
3535
- shell: true
36-
prepareCmd: "make in-docker TARGET='dist'"
36+
prepareCmd: |
37+
make in-docker TARGET='dist'
38+
make in-docker TARGET='dist' ARCH="aarch64"
3739
3840
# Commit the following changes to git after other plugins have run
3941
- - "@semantic-release/git"
@@ -46,5 +48,5 @@ plugins:
4648
- assets:
4749
- path: dist/powerstation-*.rpm
4850
- path: dist/powerstation-*.rpm.sha256.txt
49-
- path: dist/powerstation.tar.gz
50-
- path: dist/powerstation.tar.gz.sha256.txt
51+
- path: dist/powerstation-*.tar.gz
52+
- path: dist/powerstation-*.tar.gz.sha256.txt

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ description = "Daemon for controlling TDP and performance over DBus"
77

88
[package.metadata.generate-rpm]
99
assets = [
10-
{ source = "./target/release/powerstation", dest = "/usr/bin/powerstation", mode = "755" },
10+
{ source = "target/release/powerstation", dest = "/usr/bin/powerstation", mode = "755" },
1111
{ source = "./rootfs/usr/share/dbus-1/system.d/org.shadowblip.PowerStation.conf", dest = "/usr/share/dbus-1/system.d/org.shadowblip.PowerStation.conf", mode = "644" },
1212
{ source = "./rootfs/usr/lib/systemd/system/powerstation.service", dest = "/usr/lib/systemd/system/powerstation.service", mode = "644" },
1313
]

Dockerfile

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
1-
FROM rust:1.83
1+
FROM rust:1.86
22

3+
RUN dpkg --add-architecture arm64
34
RUN apt-get update && apt-get install -y \
45
cmake \
56
build-essential \
67
libpci-dev \
78
libclang-15-dev
9+
10+
RUN apt-get install -y \
11+
g++-aarch64-linux-gnu \
12+
libc6-dev-arm64-cross \
13+
libpci-dev:arm64
14+
15+
RUN rustup target add aarch64-unknown-linux-gnu
16+
17+
ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc
18+
ENV CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc
19+
ENV CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++

Makefile

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
NAME := $(shell grep 'name =' Cargo.toml | head -n 1 | cut -d'"' -f2)
22
VERSION := $(shell grep '^version =' Cargo.toml | cut -d'"' -f2)
3-
ARCH := $(shell uname -m)
3+
ARCH ?= $(shell uname -m)
4+
TARGET_ARCH ?= $(ARCH)-unknown-linux-gnu
45
ALL_RS := $(shell find src -name '*.rs')
56
PREFIX ?= /usr
67
CACHE_DIR := .cache
@@ -28,7 +29,7 @@ help: ## Display this help.
2829

2930
.PHONY: install
3031
install: build ## Install PowerStation to the given prefix (default: PREFIX=/usr)
31-
install -D -m 755 target/release/powerstation \
32+
install -D -m 755 target/$(TARGET_ARCH)/release/powerstation \
3233
$(PREFIX)/bin/powerstation
3334
install -D -m 644 rootfs/usr/share/dbus-1/system.d/org.shadowblip.PowerStation.conf \
3435
$(PREFIX)/share/dbus-1/system.d/org.shadowblip.PowerStation.conf
@@ -47,21 +48,21 @@ uninstall: ## Uninstall PowerStation
4748
##@ Development
4849

4950
.PHONY: debug
50-
debug: target/debug/powerstation ## Build debug build
51-
target/debug/powerstation: $(ALL_RS) Cargo.lock
52-
cargo build
51+
debug: target/$(TARGET_ARCH)/debug/powerstation ## Build debug build
52+
target/$(TARGET_ARCH)/debug/powerstation: $(ALL_RS) Cargo.lock
53+
cargo build --target $(TARGET_ARCH)
5354

5455
.PHONY: build
55-
build: target/release/powerstation ## Build release build
56-
target/release/powerstation: $(ALL_RS) Cargo.lock
57-
cargo build --release
56+
build: target/$(TARGET_ARCH)/release/powerstation ## Build release build
57+
target/$(TARGET_ARCH)/release/powerstation: $(ALL_RS) Cargo.lock
58+
cargo build --release --target $(TARGET_ARCH)
5859

5960
.PHONY: all
6061
all: build debug ## Build release and debug builds
6162

6263
.PHONY: run
6364
run: setup debug ## Build and run
64-
sudo ./target/debug/powerstation
65+
sudo ./target/$(TARGET_ARCH)/debug/powerstation
6566

6667
.PHONY: test
6768
test: debug ## Build and run all tests
@@ -87,25 +88,25 @@ setup: /usr/share/dbus-1/system.d/org.shadowblip.PowerStation.conf ## Install db
8788
##@ Distribution
8889

8990
.PHONY: dist
90-
dist: dist/$(NAME).tar.gz dist/$(NAME)-$(VERSION)-1.$(ARCH).rpm ## Create all redistributable versions of the project
91+
dist: dist/$(NAME)-$(ARCH).tar.gz dist/$(NAME)-$(VERSION)-1.$(ARCH).rpm ## Create all redistributable versions of the project
9192

9293
.PHONY: dist-archive
93-
dist-archive: dist/powerstation.tar.gz ## Build a redistributable archive of the project
94-
dist/powerstation.tar.gz: build
94+
dist-archive: dist/powerstation-$(ARCH).tar.gz ## Build a redistributable archive of the project
95+
dist/powerstation-$(ARCH).tar.gz: build
9596
rm -rf $(CACHE_DIR)/powerstation
9697
mkdir -p $(CACHE_DIR)/powerstation
9798
$(MAKE) install PREFIX=$(CACHE_DIR)/powerstation/usr NO_RELOAD=true
9899
mkdir -p dist
99100
tar cvfz $@ -C $(CACHE_DIR) powerstation
100-
cd dist && sha256sum powerstation.tar.gz > powerstation.tar.gz.sha256.txt
101+
cd dist && sha256sum powerstation-$(ARCH).tar.gz > powerstation-$(ARCH).tar.gz.sha256.txt
101102

102103
.PHONY: dist-rpm
103104
dist-rpm: dist/$(NAME)-$(VERSION)-1.$(ARCH).rpm ## Build a redistributable RPM package
104-
dist/$(NAME)-$(VERSION)-1.$(ARCH).rpm: target/release/$(NAME)
105+
dist/$(NAME)-$(VERSION)-1.$(ARCH).rpm: target/$(TARGET_ARCH)/release/$(NAME)
105106
mkdir -p dist
106107
cargo install cargo-generate-rpm
107-
cargo generate-rpm
108-
cp ./target/generate-rpm/$(NAME)-$(VERSION)-1.$(ARCH).rpm dist
108+
cargo generate-rpm --target $(TARGET_ARCH)
109+
cp ./target/$(TARGET_ARCH)/generate-rpm/$(NAME)-$(VERSION)-1.$(ARCH).rpm dist
109110
cd dist && sha256sum $(NAME)-$(VERSION)-1.$(ARCH).rpm > $(NAME)-$(VERSION)-1.$(ARCH).rpm.sha256.txt
110111

111112
INTROSPECT_CARD ?= Card2
@@ -166,6 +167,8 @@ in-docker: docker-builder
166167
-v $(PWD):/src \
167168
--workdir /src \
168169
-e HOME=/home/build \
170+
-e ARCH=$(ARCH) \
171+
-e PKG_CONFIG_SYSROOT_DIR="/usr/$(ARCH)-linux-gnu" \
169172
--user $(shell id -u):$(shell id -g) \
170173
$(IMAGE_NAME):$(IMAGE_TAG) \
171174
make $(TARGET)

0 commit comments

Comments
 (0)