Skip to content

Instantly share code, notes, and snippets.

@kbingham
Last active January 3, 2024 17:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kbingham/b35cc1402d02b0ef41b450941ad8f0c3 to your computer and use it in GitHub Desktop.
Save kbingham/b35cc1402d02b0ef41b450941ad8f0c3 to your computer and use it in GitHub Desktop.

Cross compilation environment for libcamera for the RPi Bullseye OS

This will let you build a cross compilation docker image, and use it to compile libcamera for the RPi. These commands are expected to be run in a checked out libcamera source, and save the Dockerfile file locally. A meson cross file will be automatically generated inside the debian bullseye environment.

If this works well, I'll hope to wrap this up into a better system for testing cross compilation and automating the build of RPi packages.

Build your cross compile docker image:

/usr/bin/docker build -t libcamera/debian/bullseye-cross-arm64 - < Dockerfile.debian.bullseye.cross-arm64

Run a shell in the new docker image in the local libcamera directory

docker run -v "$PWD":"$PWD" -w "$PWD" --rm -it libcamera/debian/bullseye-cross-arm64

Configure meson to perform the cross build

meson build/rpi/bullseye --cross-file /usr/share/meson/arm64-cross

(Cross-compile) Build libcamera at host compile speeds

ninja -C ./build/rpi/bullseye/

Install built components on RPi

TODO: This could be a step to build a debian package (would be nice) or tar/scp built objects to the target...

Another alternative is to run sshfs and mount the RPi rootfs directly. Then a script could call DESTDIR=$RPI_MOUNT_POINT ninja -C ./build/rpi/bullsye install

FROM debian:bullseye
ENV DEBIAN_FRONTEND noninteractive
ENV LANG='C.UTF-8' LC_ALL='C.UTF-8'
# Support multiarch builds to perform cross compilation
# https://wiki.debian.org/Multiarch/HOWTO
RUN dpkg --add-architecture arm64
# Expected system requirements
RUN apt-get update && apt-get install -y \
sudo \
git \
dpkg-dev
# Base libcamera image, with non-toolchain dependencies for building.
# Base libcamera always-host packages (compilation dependencies)
RUN apt-get install -y \
meson ninja-build pkg-config \
python3-yaml python3-ply python3-jinja2 \
openssl \
python3-sphinx doxygen graphviz texlive-latex-extra \
liblttng-ust-dev python3-jinja2 lttng-tools
# Base libcamera cross compiler and target architecture packages
RUN apt-get install -y \
gcc-aarch64-linux-gnu g++-aarch64-linux-gnu \
libgnutls28-dev:arm64 \
libboost-dev:arm64 \
libudev-dev:arm64 \
libgstreamer1.0-dev:arm64 libgstreamer-plugins-base1.0-dev:arm64 \
libevent-dev:arm64 \
qtbase5-dev:arm64 libqt5core5a:arm64 libqt5gui5:arm64 libqt5widgets5:arm64 \
qttools5-dev-tools:arm64 libtiff-dev:arm64 \
libexif-dev:arm64 libjpeg-dev:arm64 libyaml-dev:arm64
# Generate the meson cross file using the debian package helper
RUN /usr/share/meson/debcrossgen --arch arm64 -o /usr/share/meson/arm64-cross
# Create a custom user to operate in the container
RUN adduser --disabled-password --gecos '' libcamera
RUN adduser libcamera sudo
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
WORKDIR /home/libcamera
USER libcamera
@srgfrog
Copy link

srgfrog commented Jun 20, 2022

You need to add dpkg-dev package as well so /usr/share/meson/debcrossgen works.

@kbingham
Copy link
Author

Thanks, my intern Daniel actually discovered this last week - he's been working on some improvements too. So I hope to be able to wrap this all up a bit more later as well.

https://github.com/CactiChameleon9/Libcamera-RPiOS-Build-Enviroment (though this location may move too)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment