Skip to content

Commit

Permalink
Merge pull request #456 from andrewdavidmackenzie/fix_cross_compiling…
Browse files Browse the repository at this point in the history
…_linux

Fix cross compiling linux
  • Loading branch information
andrewdavidmackenzie authored Sep 18, 2024
2 parents 6e8c06f + 43aac43 commit 789d79a
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .cargo/cargo.toml → .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
linker = "aarch64-linux-gnu-gcc"

[target.armv7-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc"
linker = "arm-linux-gnueabihf-gcc"
47 changes: 27 additions & 20 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: Run cargo fmt check
run: cargo fmt --all -- --check

cross-compile-and-test-arm:
arm7-build:
runs-on: ubuntu-latest
steps:
- name: Clean up files
Expand All @@ -41,36 +41,43 @@ jobs:
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
- name: Add target
run: rustup target add armv7-unknown-linux-gnueabihf

- name: Install Linker
run: |
sudo apt update
sudo apt install -y gcc-aarch64-linux-gnu
sudo apt install -y gcc-arm-linux-gnueabihf
- name: Setup cargo-binstall (Non-Windows)
if: runner.os != 'Windows'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash
- name: Checkout
uses: actions/checkout@v4

- name: Setup cargo-binstall (Windows)
if: runner.os == 'Windows'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Clippy and Build for armv7
run: make armv7

aarch64-build:
runs-on: ubuntu-latest
steps:
- name: Clean up files
run: |
Set-ExecutionPolicy Unrestricted -Scope Process; iex (iwr "https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.ps1").Content
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
- name: Install cross
run: cargo binstall cross -y --force
- name: Add target
run: rustup target add aarch64-unknown-linux-gnu

- name: Install Linkers
run: |
sudo apt update
sudo apt install -y gcc-aarch64-linux-gnu
- name: Checkout
uses: actions/checkout@v4

- name: Build and test for armv7 using cross
run: make cross-armv7

- name: Build and test for aarch64 using cross
run: RUSTFLAGS= make cross-aarch64
- name: Clippy and Build for aarch64
run: make aarch64

clippy-build-and-test:
runs-on: ${{ matrix.os }}
Expand Down
4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,4 @@ skip_optional_dependencies = true

[workspace.metadata.dist.dependencies.apt]
gcc-aarch64-linux-gnu = { version = '*', targets = ["aarch64-unknown-linux-gnu"] }
gcc-arm-linux-gnueabihf = { version = '*', targets = ["armv7-unknown-linux-gnueabihf"] }
# Try this variation to see if it works
arm-linux-gnueabihf-gcc = { version = '*', targets = ["armv7-unknown-linux-gnueabihf"] }
gcc-arm-linux-gnueabihf = { version = '*', targets = ["armv7-unknown-linux-gnueabihf"] }
90 changes: 50 additions & 40 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ $(eval PI = $(shell cat /proc/cpuinfo 2>&1 | grep "Raspberry Pi"))
.PHONY: all
all: clippy build test

.PHONY: clean
clean:
@cargo clean

.PHONY: clippy
clippy:
cargo clippy --tests --no-deps
cargo clippy --tests --no-deps

# Enable the "iced" feature so we only build the "piggui" binary on the current host (macos, linux or raspberry pi)
# To build both binaries on a Pi directly, we will need to modify this
Expand Down Expand Up @@ -56,63 +60,69 @@ build-release:
test:
cargo test

.PHONY: cross-clippy
cross-clippy:
CROSS_CONTAINER_OPTS="--platform linux/amd64" cross clippy --tests --no-deps --target=armv7-unknown-linux-gnueabihf
#### armv7 targets
.PHONY: armv7
armv7: clippy-armv7 build-armv7

.PHONY: clippy-armv7
clippy-armv7:
cargo clippy --tests --no-deps --target=armv7-unknown-linux-gnueabihf

.PHONY: build-armv7
build-armv7:
cargo build --target=armv7-unknown-linux-gnueabihf

.PHONY: cross-armv7
cross-armv7: cross-build-armv7 cross-test-armv7
.PHONY: release-build-armv7
release-build-armv7:
cargo build --release --target=armv7-unknown-linux-gnueabihf

.PHONY: cross-aarch64
cross-aarch64: cross-build-aarch64 cross-test-aarch64
# NOTE: The tests will be built for armv7 architecture, so tests can only be run on that architecture
.PHONY: test-armv7
test-armv7:
cargo test --target=armv7-unknown-linux-gnueabihf

.PHONY: cross
cross: cross-clippy cross-armv7 cross-aarch64
.PHONY: copy-armv7
copy-armv7: build-armv7
scp target/armv7-unknown-linux-gnueabihf/debug/piggui $(PI_USER)@$(PI_TARGET):~/
scp target/armv7-unknown-linux-gnueabihf/debug/piglet $(PI_USER)@$(PI_TARGET):~/

.PHONY: copy-release-armv7
copy-release-armv7: build-armv7
scp target/armv7-unknown-linux-gnueabihf/release/piggui $(PI_USER)@$(PI_TARGET):~/
scp target/armv7-unknown-linux-gnueabihf/release/piglet $(PI_USER)@$(PI_TARGET):~/

.PHONY: cross-build
cross-build-aarch64:
CROSS_CONTAINER_OPTS="--platform linux/amd64" cross build --target=aarch64-unknown-linux-gnu

.PHONY: cross-build-armv7
cross-build-armv7:
CROSS_CONTAINER_OPTS="--platform linux/amd64" cross build --target=armv7-unknown-linux-gnueabihf
#### aarch64 targets
.PHONY: aarch64
aarch64: clippy-aarch64 build-aarch64

.PHONY: cross-release-build-aarch64
cross-release-build-aarch64:
CROSS_CONTAINER_OPTS="--platform linux/amd64" cross build --release --target=aarch64-unknown-linux-gnu
.PHONY: clippy-aarch64
clippy-aarch64:
cargo clippy --tests --no-deps --target=aarch64-unknown-linux-gnu

.PHONY: cross-release-build-armv7
cross-release-build-armv7:
CROSS_CONTAINER_OPTS="--platform linux/amd64" cross build --release --target=armv7-unknown-linux-gnueabihf
.PHONY: build-aarch64
build-aarch64:
cargo build --target=aarch64-unknown-linux-gnu

.PHONY: cross-test-armv7
cross-test-armv7:
CROSS_CONTAINER_OPTS="--platform linux/amd64" cross test --target=armv7-unknown-linux-gnueabihf
.PHONY: release-build-aarch64
release-build-aarch64:
cargo build --release --target=aarch64-unknown-linux-gnu

.PHONY: cross-test-aarch64
cross-test-aarch64:
CROSS_CONTAINER_OPTS="--platform linux/amd64" cross test --target=aarch64-unknown-linux-gnu
# NOTE: The tests will be built for aarch64 architecture, so tests can only be run on that architecture
.PHONY: test-aarch64
test-aarch64:
cargo test --target=aarch64-unknown-linux-gnu

.PHONY: copy-aarch64
copy-aarch64: cross-build-aarch64
copy-aarch64: build-aarch64
scp target/aarch64-unknown-linux-gnu/debug/piggui $(PI_USER)@$(PI_TARGET):~/
scp target/aarch64-unknown-linux-gnu/debug/piglet $(PI_USER)@$(PI_TARGET):~/

.PHONY: copy-release-aarch64
copy-release-aarch64: cross-release-build-aarch64
copy-release-aarch64: release-build-aarch64
scp target/aarch64-unknown-linux-gnu/release/piggui $(PI_USER)@$(PI_TARGET):~/
scp target/aarch64-unknown-linux-gnu/release/piglet $(PI_USER)@$(PI_TARGET):~/

.PHONY: copy-armv7
copy-armv7: cross-build-armv7
scp target/armv7-unknown-linux-gnueabihf/debug/piggui $(PI_USER)@$(PI_TARGET):~/
scp target/armv7-unknown-linux-gnueabihf/debug/piglet $(PI_USER)@$(PI_TARGET):~/

.PHONY: copy-release-armv7
copy-release-armv7: cross-build-armv7
scp target/armv7-unknown-linux-gnueabihf/release/piggui $(PI_USER)@$(PI_TARGET):~/
scp target/armv7-unknown-linux-gnueabihf/release/piglet $(PI_USER)@$(PI_TARGET):~/

.PHONY: ssh
ssh:
ssh $(PI_USER)@$(PI_TARGET)
Expand Down

0 comments on commit 789d79a

Please sign in to comment.