Skip to content

Commit

Permalink
Update cross-compilation to aarch64 target (#25)
Browse files Browse the repository at this point in the history
* Switch to `aarch64-unknown-linux-gnu` target for cross-compilation
* Update target and linker in `config.toml` and pod-operation README
* Update checks workflow to use new target
  • Loading branch information
samderanova authored Mar 8, 2024
1 parent ad043cf commit 3533a05
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/run-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
run:
working-directory: ./pod-operation
env:
TARGET: armv7-unknown-linux-gnueabihf
TARGET: aarch64-unknown-linux-gnu
steps:
- name: Check out repository
uses: actions/checkout@v4
Expand All @@ -81,7 +81,7 @@ jobs:
run: rustup target add $TARGET

- name: Install target building dependencies
run: sudo apt-get update && sudo apt-get -qq install crossbuild-essential-armhf
run: sudo apt-get update && sudo apt-get -qq install crossbuild-essential-arm64

- name: Run cargo test
run: cargo test
Expand All @@ -93,7 +93,7 @@ jobs:
run: cargo clippy -- -D warnings

- name: Build Pod Operation Program (debug)
run: cargo build --target $TARGET --config target.$TARGET.linker=\"arm-linux-gnueabihf-gcc\"
run: cargo build --target $TARGET --config target.$TARGET.linker=\"aarch64-linux-gnu-gcc\"

- name: Build Pod Operation Program (release)
run: cargo build --target $TARGET --config target.$TARGET.linker=\"arm-linux-gnueabihf-gcc\" --release
run: cargo build --target $TARGET --config target.$TARGET.linker=\"aarch64-linux-gnu-gcc\" --release
8 changes: 4 additions & 4 deletions pod-operation/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# Uncomment lines as needed

[build]
# target = "armv7-unknown-linux-gnueabihf"
# target = "aarch64-unknown-linux-gnu"

[target.armv7-unknown-linux-gnueabihf]
# linker = "armv7-unknown-linux-gnueabihf-gcc"
# linker = "arm-none-linux-gnueabihf-gcc"
[target.aarch64-unknown-linux-gnu]
# linker = "aarch64-unknown-linux-gnu-gcc"
# linker = "aarch64-none-linux-gnu-gcc"
2 changes: 1 addition & 1 deletion pod-operation/Cross.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[build]
default-target = "armv7-unknown-linux-gnueabihf"
default-target = "aarch64-unknown-linux-gnu"
18 changes: 11 additions & 7 deletions pod-operation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ cargo install cargo-watch
Add the build target for the Raspberry Pi

```shell
rustup target add armv7-unknown-linux-gnueabihf
rustup target add aarch64-unknown-linux-gnu
```

### Cross-Compilation
Expand All @@ -29,15 +29,19 @@ A Homebrew formula for macOS cross-compiler toolchains is available

```shell
brew tap messense/macos-cross-toolchains
brew install armv7-unknown-linux-gnueabihf
brew install aarch64-unknown-linux-gnu
```

#### Windows/Linux

To cross-compile on Windows and Linux, a different compiler toolchain is needed. From the
[Arm GNU Toolchain Downloads](https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads),
download and install the **AArch32 GNU/Linux target with hard float (arm-none-linux-gnueabihf)**
for your operating system.
download and install the **AArch64 GNU/Linux target (aarch64-none-linux-gnu)** for your operating
system.

For Linux operating systems, your distribution may also provide the target via
its package manager (`apt`, `pacman`, etc.). Please refer to the appropriate
package repository to verify and install it this way if you wish.

#### Alternative Building Process With `cross`

Expand Down Expand Up @@ -84,12 +88,12 @@ cargo watch -x run

## Building for Production

Uncomment the arm-linux linker for your operating system in `.cargo/config.toml`.
Uncomment the aarch64 Linux linker for your operating system in `.cargo/config.toml`.

To build for production, use the `--release` option:

```shell
cargo build --target armv7-unknown-linux-gnueabihf --release
cargo build --target aarch64-unknown-linux-gnu --release
```

Alternatively, use `cross` to compile in a container:
Expand All @@ -101,5 +105,5 @@ cross build --release
Note: the default target is already specified in `Cross.toml`.

Either approach will compile the project to
`target/armv7-unknown-linux-gnueabihf/release/pod-operation`
`target/aarch64-unknown-linux-gnu/release/pod-operation`
which can be run on the Raspberry Pi.

0 comments on commit 3533a05

Please sign in to comment.