Skip to content

Instantly share code, notes, and snippets.

@gitcrtn
Created December 8, 2023 18:03
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/fe8a00c124ef773f2d10927e7e2f891b to your computer and use it in GitHub Desktop.
Save gitcrtn/fe8a00c124ef773f2d10927e7e2f891b to your computer and use it in GitHub Desktop.
A cross compiler of rust-sdl2 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 \
&& 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 gcc-aarch64-linux-gnu libsdl2-dev:arm64 libsdl2-image-dev:arm64 libsdl2-ttf-dev:arm64
COPY build.sh /
ENTRYPOINT ["/build.sh"]
# 1. Build docker image.
docker build -t rust-sdl2-aarch64 .
# 2. Build rust project with sdl2.
cd /path/to/project
docker run --rm -v $PWD:/build rust-sdl2-aarch64
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment