项目作者: rolandjitsu

项目描述 :
Cross-compile for Raspberry Pi with Docker
高级语言: C
项目地址: git://github.com/rolandjitsu/raspi-cross.git
创建时间: 2020-10-01T04:00:15Z
项目社区:https://github.com/rolandjitsu/raspi-cross

开源协议:MIT License

下载


Raspi Cross

Cross-compile for Raspberry Pi with Docker.

GitHub Workflow Status

Prerequisites

Install the following tools:

Setup Docker

Check current builder instances:

  1. docker buildx ls

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

  1. docker buildx use <instance name>

Otherwise, create a builder:

  1. 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:

  1. docker buildx inspect --bootstrap

Setup Base Images

Prepare the base cross-compilation image:

  1. 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:

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

Compile

Compile the hello binary:

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

Compile the hello-pi binary:

  1. 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:

  1. docker buildx bake cross-stretch

To setup the base image w/ goodies:

  1. docker buildx bake cross-pi

To compile the binaries:

  1. docker buildx bake

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

Learning Material