Skip to content

Instantly share code, notes, and snippets.

@gitcrtn
Created December 8, 2023 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gitcrtn/1dd001ba0b4a3c2572cd06f384288d33 to your computer and use it in GitHub Desktop.
Save gitcrtn/1dd001ba0b4a3c2572cd06f384288d33 to your computer and use it in GitHub Desktop.
A cross compiler of bevy project for aarch64
#!/usr/bin/env bash
source $HOME/.cargo/env
cd /build
mkdir -p .cargo
cat <<EOF > .cargo/config
[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"
EOF
cargo build --target=aarch64-unknown-linux-gnu
FROM debian:bookworm
ENV USER root
RUN rm /bin/sh \
&& ln -s /bin/bash /bin/sh
RUN mkdir /build \
&& cd \
&& apt update \
&& apt install -y curl build-essential pkg-config \
&& curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \
&& source $HOME/.cargo/env \
&& rustup target add aarch64-unknown-linux-gnu \
&& dpkg --add-architecture arm64 \
&& apt update \
&& apt install -y g++-aarch64-linux-gnu libx11-dev:arm64 libasound2-dev:arm64 libudev-dev:arm64 libwayland-dev:arm64 libxkbcommon-dev:arm64
COPY build.sh /
ENV CARGO_BUILD_TARGET=aarch64-unknown-linux-gnu
ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=/usr/bin/aarch64-linux-gnu-gcc
ENV PKG_CONFIG_ALLOW_CROSS=1
ENV PKG_CONFIG_PATH_aarch64_unknown_linux_gnu=/usr/lib/aarch64-linux-gnu/pkgconfig/
ENTRYPOINT ["/build.sh"]
# 1. Build docker image.
docker build -t rust-bevy-aarch64 .
# 2. Build rust project with bevy.
cd /path/to/project
docker run --rm -v $PWD:/build rust-bevy-aarch64
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment