Skip to content

Latest commit

 

History

History
43 lines (31 loc) · 4.3 KB

README.md

File metadata and controls

43 lines (31 loc) · 4.3 KB

Docker crossbuild

Sync Labels status Check Markdown status Check License status Check Taskfiles status Check Shell Scripts status

This docker container has been created to allow us to easily crosscompile our c++ tools. The idea comes from multiarch/crossbuild, but that container unfortunately is outdated and the apt sources are no longer available.

Starting Image

The starting image is ubuntu:latest (The ubuntu:latest tag points to the "latest LTS", since that's the version recommended for general use.) at the time of writing latest points to Ubuntu 22.04 jammy.

The starting image is only marginally important, since internally we use manually installed toolchains.

The Toolchains

The toolchains are download from http://downloads.arduino.cc/tools/internal/toolchains.tar.gz . Inside that archive there are:

  • gcc-arm-8.3-2019.03-x86_64-aarch64-linux-gnu toolchain to crosscompile for linux_arm64 (downloaded from here)
  • gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf toolchain used to crosscompile for linux_arm (downloaded from here)
  • i686-ubuntu16.04-linux-gnu toolchain to crosscompile for linux_386 (32bit)
  • x86_64-ubuntu16.04-linux-gnu-gcc toolchain to crosscompile for linux_amd64
  • osxcross toolchain to crosscompile for darwin_amd64. Inside osxcross/tarballs/ there is already MacOSX10.15.sdk.tar.xz: the SDK required by macos to crosscompile (we tried with SDK version 10.09 but it was too old)

Regarding the two ubuntu toolchains: in the beginning we tried to use the ones shipped with 12.04 but they caused some build errors because they were too old, so we upgraded to 16.04 ones. They are created using crosstool-ng.

Apparently, osxcross does not have tags or version so we checkout a specific commit in order to have a pinned environment.

The last toolchain required to crosscompile for windows is mingw-w64 and it's installed through apt along with other useful packages.

Once the toolchains are installed in /opt we add the binaries to the PATH env variable, to easily use them in the CI.

Copying and Building Libraries

As explained in the other README.md there are some libraries that needs to be compiled, in order to create static binaries. This is achieved by copying deps/ directory inside /opt/lib/ in the container and then by using build_libs.sh script here

Multi-stage build

To reduce the overall dimension of the docker image we used the multi-stage build. But the image still 8GB.

How to build and use the container

Usefull commands you can use:

  • docker build -t ghcr.io/arduino/crossbuild:<version> . to build the container
  • docker push ghcr.io/arduino/crossbuild:<version> to push the image to github remote registry
  • docker run -it --name crossbuild -v $PWD:/workdir ghcr.io/arduino/crossbuild:<version> to get a shell inside the container and use the toolchains available inside (just like the CI does).