Skip to content

rolandjitsu/raspi-cross

Repository files navigation

Raspi Cross

Cross-compile for Raspberry Pi with Docker.

GitHub Workflow Status

Prerequisites

Install the following tools:

Setup Docker

Check current builder instances:

docker buildx ls

If you see an instance that uses the docker driver, switch to it (it's usually the default):

docker buildx use <instance name>

Otherwise, create a builder:

docker buildx create --name my-builder --driver docker --use

NOTE: You cannot create more than one instance using the docker driver.

Then inspect and bootstrap it:

docker buildx inspect --bootstrap

Setup Base Images

Prepare the base cross-compilation image:

docker buildx build -f Dockerfile.cross --tag cross-stretch .

NOTE: By default, the image is going to be available to use on the host as cross-stretch. If docker images doesn't show it, add the --load flag when building.

P.S. To bust the cache, use --no-cache.

Prepare the base image w/ some common libs usually available on the Pi:

docker buildx build -f Dockerfile.cross-pi --tag cross-pi .

Compile

Compile the hello binary:

docker buildx build -f Dockerfile.hello -o type=local,dest=./bin .

Compile the hello-pi binary:

docker buildx build -f Dockerfile.hello-pi -o type=local,dest=./bin .

Bake

To make things easier, you can use the bake command.

To setup the base image:

docker buildx bake cross-stretch

To setup the base image w/ goodies:

docker buildx bake cross-pi

To compile the binaries:

docker buildx bake

P.S. To bust the cache, you can use --no-cache.

Learning Material