|
| 1 | +# Docker crossbuild |
| 2 | + |
| 3 | +This docker container has been created to allow us to easily crosscompile the c++ tools starting from this repo. The idea comes from [multiarch/crossbuild](https://github.com/multiarch/crossbuild), but this container unfortunately is outdated, the apt sources are no longer available. |
| 4 | + |
| 5 | +## Starting Image |
| 6 | +The starting image is [ubuntu:latest](https://hub.docker.com/_/ubuntu) (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 20.04 focal. |
| 7 | + |
| 8 | +The starting image is only marginally important, since internally we use manually installed toolchains. |
| 9 | + |
| 10 | +## The Toolchains |
| 11 | +The toolchains are download from http://downloads.arduino.cc/tools/internal/toolchains.tar.gz . |
| 12 | +Inside that archive there are: |
| 13 | +- **gcc-arm-8.3-2019.03-x86_64-aarch64-linux-gnu** toolchain to crosscompile for *linux_arm64* (downloaded from [here](https://developer.arm.com/-/media/Files/downloads/gnu-a/8.3-2019.03/binrel/gcc-arm-8.3-2019.03-x86_64-aarch64-linux-gnu.tar.xz)) |
| 14 | +- **gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf** toolchain used to crosscompile for *linux_arm* (downloaded from [here](https://developer.arm.com/-/media/Files/downloads/gnu-a/8.3-2019.03/binrel/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf.tar.xz)) |
| 15 | +- **i686-ubuntu16.04-linux-gnu** toolchain to crosscompile for *linux_386* (32bit) |
| 16 | +- **x86_64-ubuntu16.04-linux-gnu-gcc** toolchain to crosscompile for *linux_amd64* |
| 17 | +- [**osxcross**](https://github.com/tpoechtrager/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) |
| 18 | + |
| 19 | +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](https://github.com/crosstool-ng/crosstool-ng). |
| 20 | + |
| 21 | + |
| 22 | +Apparently, osxcross does not have tags or version so we checkout a specific commit in order to have a pinned environment. |
| 23 | + |
| 24 | +The last toolchain required to crosscompile for windows is `mingw-w64` and it's installed through `apt` along with other useful packages. |
| 25 | + |
| 26 | +Once the toolchains are installed in `/opt` we add the binaries to the `PATH` env variable, to easily call them in the CI. |
| 27 | + |
| 28 | +## Copying and Building Libraries |
| 29 | +As explained in the other [`README.md`](deps/README.md) there are some libraries that needs to be compiled. This is achieved by copying `deps/` directory inside `/opt/lib/` in the container and then by using [`build_libs.sh`](deps/build_libs.sh) script [here](Dockerfile#L47-L55) |
| 30 | + |
| 31 | +## Multi-stage build |
| 32 | +To reduce the overall dimesion of the docker image we used the [multi-stage build](https://learnk8s.io/blog/smaller-docker-images). |
| 33 | + |
| 34 | +## How to build and use the container |
| 35 | +Usefull commands you can use: |
| 36 | +- `docker build -t ghcr.io/arduino/crossbuild:<version> docker/` to build the container |
| 37 | +- `docker push ghcr.io/arduino/crossbuild:<version>` to push the image to [github remote registry](https://docs.github.com/en/packages/guides/container-guides-for-github-packages) |
| 38 | +- `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 (like the CI does). |
0 commit comments