Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
45 changes: 28 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
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 \
git \
gperf \
# various libs required to compile osxcross
# various libs requied to compile osxcross
libxml2-dev \
libssl-dev \
libz-dev \
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,9 @@ 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 ./configure_toolchain.sh /
RUN chmod +x /configure_toolchain.sh

ENTRYPOINT ["/bin/bash"]
WORKDIR /workdir
ENTRYPOINT ["/configure_toolchain.sh"]
CMD ["bash"]
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
47 changes: 47 additions & 0 deletions configure_toolchain.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash -e

Check failure on line 1 in configure_toolchain.sh

View workflow job for this annotation

GitHub Actions / executable

non-executable script file: ./configure_toolchain.sh

Check failure on line 1 in configure_toolchain.sh

View workflow job for this annotation

GitHub Actions / executable

non-executable script file: ./configure_toolchain.sh

# Check if the CROSS_COMPILE variable is set
if [ -z "$CROSS_COMPILE" ]; then
echo "Error: CROSS_COMPILE is not set. Please specify the toolchain prefix (e.g., arm-linux-gnueabihf-)."
exit 1
fi

# Detect if the toolchain is osxcross
if [[ "$CROSS_COMPILE" == *"apple-darwin"* ]]; then
# Set osxcross-specific tools
export CC="o64-clang"
export CXX="o64-clang++"
else
export CC="${CROSS_COMPILE}-gcc"
export CXX="${CROSS_COMPILE}-g++"
fi

# Set default compilation flags
export AR="${CROSS_COMPILE}-ar"
export RANLIB="${CROSS_COMPILE}-ranlib"
export LD="${CROSS_COMPILE}-ld"
export STRIP="${CROSS_COMPILE}-strip"
export CFLAGS="-O2"
export CXXFLAGS="$CFLAGS"

# Add toolchain's lib directory to library paths
TOOLCHAIN_LIB_DIR="/opt/lib/${CROSS_COMPILE%/}/lib"
TOOLCHAIN_INCLUDE_DIR="/opt/lib/${CROSS_COMPILE%/}/include"
export LIBRARY_PATH="$TOOLCHAIN_LIB_DIR:$LIBRARY_PATH"
export PKG_CONFIG_PATH="$TOOLCHAIN_LIB_DIR/pkgconfig:$PKG_CONFIG_PATH"
export CPATH="$TOOLCHAIN_INCLUDE_DIR:$CPATH"
export C_INCLUDE_PATH="$TOOLCHAIN_INCLUDE_DIR:$C_INCLUDE_PATH"
export CPLUS_INCLUDE_PATH="$TOOLCHAIN_INCLUDE_DIR:$CPLUS_INCLUDE_PATH"

echo "Configured toolchain: $CROSS_COMPILE"
echo " CC=$CC, CXX=$CXX, AR=$AR, RANLIB=$RANLIB, LD=$LD, STRIP=$STRIP"
echo " CFLAGS=$CFLAGS, CXXFLAGS=$CXXFLAGS, LDFLAGS=$LDFLAGS"
echo " LIBRARY_PATH=$LIBRARY_PATH"
echo " LD_LIBRARY_PATH=$LD_LIBRARY_PATH"
echo " PKG_CONFIG_PATH=$PKG_CONFIG_PATH"
echo " CPATH=$CPATH"
echo " C_INCLUDE_PATH=$C_INCLUDE_PATH"
echo " CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH"

# Execute the provided command
exec "$@"
21 changes: 14 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,9 @@ 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