Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 26 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
FROM ubuntu:latest as build
FROM ubuntu:22.04 AS build

ENV TZ=Europe/Rome
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && \
apt-get update && \
apt-get install -y \
build-essential \
# Intall clang compiler used by macos
clang \
clang-13 \
cmake \
curl \
dh-autoreconf \
Expand All @@ -24,19 +24,26 @@ RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone &
tar \
unzip \
llvm \
&& rm -rf /var/lib/apt/lists/*
&& rm -rf /var/lib/apt/lists/* \
&& ln -s /usr/bin/clang-13 /usr/bin/clang \
&& ln -s /usr/bin/clang++-13 /usr/bin/clang++ \
# pretend to have 1.17 instead of 1.16
&& ln -s /usr/bin/aclocal /usr/bin/aclocal-1.17 \
&& ln -s /usr/bin/automake /usr/bin/automake-1.17

# Install toolchains in /opt
RUN curl downloads.arduino.cc/tools/internal/toolchains.tar.gz | tar -xz "opt"
RUN curl -L downloads.arduino.cc/tools/internal/toolchains.tar.gz | tar -xz "opt"
# install proper arm toolchains (already present in the toolchains.tar.gz archive)
# curl -L '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' | tar -xJC /opt && \
# curl -L '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' | tar -xJC /opt

RUN cd /opt/osxcross && \
git pull && \
WORKDIR /opt/osxcross
RUN git pull && \
# use a specific version of osxcross (it does not have tags), this commit has the automatic install of compiler_rt libraries
git checkout b875d7c1360c8ff2077463d7a5a12e1cff1cc683 && \
UNATTENDED=1 SDK_VERSION=10.15 ./build.sh && \
ENABLE_COMPILER_RT_INSTALL=1 SDK_VERSION=10.15 ./build_compiler_rt.sh

# Set toolchains paths
# arm-linux-gnueabihf-gcc -> linux_arm
# aarch64-linux-gnu-gcc -> linux_arm64
Expand All @@ -45,8 +52,6 @@ RUN cd /opt/osxcross && \
# o64-clang -> darwin_amd64
ENV PATH=/opt/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin/:/opt/gcc-arm-8.3-2019.03-x86_64-aarch64-linux-gnu/bin/:/opt/x86_64-ubuntu16.04-linux-gnu-gcc/bin/:/opt/i686-ubuntu16.04-linux-gnu/bin/:/opt/osxcross/target/bin/:$PATH

WORKDIR /workdir

# Handle libusb and libudev compilation and merging
COPY deps/ /opt/lib/
# compiler name is arm-linux-gnueabihf-gcc '-gcc' is added by ./configure
Expand All @@ -55,20 +60,20 @@ RUN CROSS_COMPILE=x86_64-ubuntu16.04-linux-gnu /opt/lib/build_libs.sh && \
CROSS_COMPILE=aarch64-linux-gnu /opt/lib/build_libs.sh && \
CROSS_COMPILE=i686-ubuntu16.04-linux-gnu /opt/lib/build_libs.sh && \
CROSS_COMPILE=i686-w64-mingw32 /opt/lib/build_libs.sh && \
# CROSS_COMPILER is used to override the compiler
# CROSS_COMPILER is used to override the compiler
CROSS_COMPILER=o64-clang CROSS_COMPILE=x86_64-apple-darwin13 AR=/opt/osxcross/target/bin/x86_64-apple-darwin13-ar RANLIB=/opt/osxcross/target/bin/x86_64-apple-darwin13-ranlib /opt/lib/build_libs.sh

FROM ubuntu:latest
FROM ubuntu:22.04
# Copy all the installed toolchains and compiled libs
COPY --from=build /opt /opt
COPY --from=build /usr/lib/llvm-10/lib/clang/10.0.0 /usr/lib/llvm-10/lib/clang/10.0.0
COPY --from=build /usr/lib/llvm-13/lib/clang/13.0.1 /usr/lib/llvm-13/lib/clang/13.0.1
ENV TZ=Europe/Rome
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && \
apt-get update && \
apt-get install -y \
build-essential \
build-essential \
# Intall clang compiler used by macos
clang \
clang-13 \
cmake \
dh-autoreconf \
git \
Expand All @@ -79,7 +84,10 @@ RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone &
tar \
bison \
flex \
&& rm -rf /var/lib/apt/lists/*
&& rm -rf /var/lib/apt/lists/* \
&& ln -s /usr/bin/clang-13 /usr/bin/clang \
&& ln -s /usr/bin/clang++-13 /usr/bin/clang++

# Set toolchains paths
# arm-linux-gnueabihf-gcc -> linux_arm
# aarch64-linux-gnu-gcc -> linux_arm64
Expand All @@ -88,6 +96,8 @@ RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone &
# o64-clang -> darwin_amd64
ENV PATH=/opt/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin/:/opt/gcc-arm-8.3-2019.03-x86_64-aarch64-linux-gnu/bin/:/opt/x86_64-ubuntu16.04-linux-gnu-gcc/bin/:/opt/i686-ubuntu16.04-linux-gnu/bin/:/opt/osxcross/target/bin/:$PATH

WORKDIR /workdir
COPY scripts/configure_toolchain.sh /

ENTRYPOINT ["/bin/bash"]
WORKDIR /workdir
ENTRYPOINT ["/configure_toolchain.sh"]
CMD ["bash"]
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
This docker container has been created to allow us to easily crosscompile our c++ tools. The idea comes from [multiarch/crossbuild](https://github.com/multiarch/crossbuild), but that container unfortunately is outdated and the apt sources are no longer available.

## Starting Image
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 22.04 jammy.

The starting image is only marginally important, since internally we use manually installed toolchains.
The starting image is [ubuntu:22.04](https://hub.docker.com/_/ubuntu). 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 .
Expand Down Expand Up @@ -40,4 +38,11 @@ To reduce the overall dimension of the docker image we used the [multi-stage bu
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](https://docs.github.com/en/packages/guides/container-guides-for-github-packages)
- `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).
- `docker run -it --rm -e CROSS_COMPILE=<tool-chain> -v $PWD:/workdir ghcr.io/arduino/crossbuild:latest` to get a shell inside the container with the selected toolchain.
The image supports the following toolchain:

- x86_64-ubuntu16.04-linux-gnu
- arm-linux-gnueabihf
- aarch64-linux-gnu
- i686-ubuntu16.04-linux-gnu
- x86_64-apple-darwin13
7 changes: 3 additions & 4 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ tasks:
-type d -name '.licenses' -prune -o \
-type d -name '__pycache__' -prune -o \
-type d -name 'node_modules' -prune -o \
-type d -path "./deps/*" -prune -o \
-regex ".*[.]md" -print
); do
markdown-link-check \
Expand Down Expand Up @@ -78,7 +79,7 @@ tasks:
- task: npm:install-deps
cmds:
- npx markdownlint-cli "**/*.md"

# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/npm-task/Taskfile.yml
npm:install-deps:
desc: Install dependencies managed by npm
Expand Down Expand Up @@ -111,9 +112,7 @@ tasks:
-type d -name 'node_modules' -prune -or \
-type d -path './deps/*' -prune -or \
\( \
-regextype posix-extended \
-regex '.*[.](bash|sh)' -and \
-type f \
-name '*.bash' -or -name '*.sh' -and -type f \
\) \
-print
)
Expand Down
20 changes: 13 additions & 7 deletions deps/build_libs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ export PREFIX=/opt/lib/${CROSS_COMPILE}

if [ "$CROSS_COMPILER" == "" ]; then
CROSS_COMPILER=${CROSS_COMPILE}-gcc
CROSS_COMPILER_CXX=${CROSS_COMPILE}-g++
# CROSS_COMPILER_CXX=${CROSS_COMPILE}-g++
# AR=${CROSS_COMPILE}-ar
else
export CC=$CROSS_COMPILER
export CXX=$CROSS_COMPILER++
CROSS_COMPILER=$CC
CROSS_COMPILER_CXX=$CXX
# CROSS_COMPILER_CXX=$CXX
fi
cd /opt/lib/libusb-1.0.26
cd /opt/lib/libusb-1.0.28
LIBUSB_DIR=$(pwd)
export LIBUSB_DIR
./configure --prefix="${PREFIX}" --with-pic --disable-udev --enable-static --disable-shared --host="${CROSS_COMPILE}"
Expand All @@ -30,7 +30,7 @@ if [[ $CROSS_COMPILE == "x86_64-apple-darwin13" ]]; then
export LIBUSB_1_0_CFLAGS=-I${PREFIX}/include/libusb-1.0
export LIBUSB_1_0_LIBS="-L${PREFIX}/lib -lusb-1.0"
fi
cd /opt/lib/libusb-compat-0.1.7
cd /opt/lib/libusb-compat-0.1.8
LIBUSB0_DIR=$(pwd)
export LIBUSB0_DIR
PKG_CONFIG_PATH="$PREFIX/lib/pkgconfig" ./configure --prefix="${PREFIX}" --enable-static --disable-shared --host="${CROSS_COMPILE}"
Expand All @@ -52,9 +52,10 @@ if [[ $CROSS_COMPILE == "x86_64-apple-darwin13" ]]; then
CMAKE_EXTRA_FLAG="$CMAKE_EXTRA_FLAG -DCMAKE_AR=$AR -DCMAKE_RANLIB=$RANLIB"
fi

cmake -DCMAKE_C_COMPILER="$CROSS_COMPILER" -DCMAKE_CXX_COMPILER="$CROSS_COMPILER_CXX" -DCMAKE_INSTALL_PREFIX="$PREFIX" "$CMAKE_EXTRA_FLAG" -DLIBUSB_INCLUDE_DIR="$PREFIX/include/libusb-1.0" -DLIBFTDI_LIBRARY_DIRS="$PREFIX/lib" -DLIBUSB_LIBRARIES="usb-1.0" ../
make -j"$(nproc)"
make install
# TODO: did not build anymore (missing -L${PREFIX}/lib to libusb-1.0?)
#cmake -DCMAKE_C_COMPILER="$CROSS_COMPILER" -DCMAKE_CXX_COMPILER="$CROSS_COMPILER_CXX" -DCMAKE_INSTALL_PREFIX="$PREFIX" "$CMAKE_EXTRA_FLAG" -DLIBUSB_INCLUDE_DIR="$PREFIX/include/libusb-1.0" -DLIBFTDI_LIBRARY_DIRS="$PREFIX/lib" -DLIBUSB_LIBRARIES="usb-1.0" ../
#make -j"$(nproc)"
#make install

cd /opt/lib/libelf-0.8.13
LIBELF_DIR=$(pwd)
Expand Down Expand Up @@ -110,3 +111,8 @@ make distclean
./configure --prefix="$PREFIX" --enable-static --disable-shared --host="$CROSS_COMPILE"
make -j"$(nproc)"
make install

tar -xzf /opt/lib/libxml2-2.14.3.tar.gz -C /tmp && cd /tmp/libxml2-2.14.3
./autogen.sh --prefix="$PREFIX" --disable-shared --enable-static --without-python --without-iconv --host="$CROSS_COMPILE"
make -j"$(nproc)"
make install
Loading
Loading