Skip to content

Commit

Permalink
Setup cross compilation for aarhc64-unknown-freebsd
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-fink committed Feb 21, 2024
1 parent f63c8c0 commit 9be0701
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,9 @@ default = [
# By default include compatibility with the "old" CLI from Wasmtime 13 and
# prior.
"old-cli",

# remove later, just on for convenience
"cheri",
]

# ========================================
Expand Down
6 changes: 6 additions & 0 deletions Cross.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[target.aarch64-unknown-freebsd]
# We need to build std, as aarch64-unknown-freebsd is not a tier 1 rust target
build-std = true
image.name = "ghcr.io/cross-rs/aarch64-unknown-freebsd:local"
image.toolchain = ["linux/arm64/v8=aarch64-unknown-linux-gnu"]

70 changes: 70 additions & 0 deletions docs/cheri-cross-compilation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Cross-Compilation

Since `aarch64-unknown-freebsd` is not a Rust tier-1 target, we use [cross](https://github.com/cross-rs/cross) to cross-compile for it.

We need the latest `cross` binary, as well as a custom docker image.

```shell
git clone https://github.com/cross-rs/cross.git
```

Then, apply the following patch:

```patch
From 49ed9ce2082116ac41f80afef1e7c9390d358cd3 Mon Sep 17 00:00:00 2001
From: Martin Fink <[email protected]>
Date: Wed, 21 Feb 2024 17:46:53 +0100
Subject: [PATCH] add link

---
docker/Dockerfile.aarch64-unknown-freebsd | 2 ++
1 file changed, 2 insertions(+)

diff --git a/docker/Dockerfile.aarch64-unknown-freebsd b/docker/Dockerfile.aarch64-unknown-freebsd
index 8631717..d03726a 100644
--- a/docker/Dockerfile.aarch64-unknown-freebsd
+++ b/docker/Dockerfile.aarch64-unknown-freebsd
@@ -31,6 +31,8 @@ COPY freebsd-fetch-best-mirror.sh /
COPY freebsd-setup-packagesite.sh /
COPY freebsd-install-package.sh /

+RUN ln -s $(which gcc) /usr/local/bin/aarch64-unknown-linux-gnu-gcc
+
ENV CARGO_TARGET_AARCH64_UNKNOWN_FREEBSD_LINKER="$CROSS_TOOLCHAIN_PREFIX"gcc.sh \
AR_aarch64_unknown_freebsd="$CROSS_TOOLCHAIN_PREFIX"ar \
CC_aarch64_unknown_freebsd="$CROSS_TOOLCHAIN_PREFIX"gcc \
--
2.43.0
```

and run the following (assuming you are running on an AArch64 machine).

```shell
cargo build-docker-image \  
--platform=aarch64-unknown-linux-gnu \
aarch64-unknown-freebsd \
--tag local
```

If you're on X86, run:

```shell
cargo build-docker-image \  
aarch64-unknown-freebsd \
--tag local
```

Then, install the latest version of `cross`:

```shell
cargo install --git https://github.com/cross-rs/cross.git cross
```

Now, you can cross-compile for `aarch64-unknown-freebsd`:

```shell
rustup override set nightly
cross build --target aarch64-unknown-freebsd --release
```

The built binary can be found in `target/aarch64-unknown-freebsd/release/`.

0 comments on commit 9be0701

Please sign in to comment.