Skip to content

Commit ae977ed

Browse files
lucarin91cmaglieCopilot
authored
add libxml2 and fix build issues (#16)
* Updated deps and compilers * some other updates * add libxml2 * add configure_toolchain script * include archive instead of a folder * fix linters * make configure_toolchain.sh executable * Update Dockerfile Co-authored-by: Copilot <[email protected]> * make formatter happy * update readme --------- Co-authored-by: Cristian Maglie <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent 609f7e9 commit ae977ed

File tree

300 files changed

+28058
-25029
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

300 files changed

+28058
-25029
lines changed

Dockerfile

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
FROM ubuntu:latest as build
1+
FROM ubuntu:22.04 AS build
22

33
ENV TZ=Europe/Rome
44
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && \
55
apt-get update && \
66
apt-get install -y \
77
build-essential \
88
# Intall clang compiler used by macos
9-
clang \
9+
clang-13 \
1010
cmake \
1111
curl \
1212
dh-autoreconf \
@@ -24,19 +24,26 @@ RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone &
2424
tar \
2525
unzip \
2626
llvm \
27-
&& rm -rf /var/lib/apt/lists/*
27+
&& rm -rf /var/lib/apt/lists/* \
28+
&& ln -s /usr/bin/clang-13 /usr/bin/clang \
29+
&& ln -s /usr/bin/clang++-13 /usr/bin/clang++ \
30+
# pretend to have 1.17 instead of 1.16
31+
&& ln -s /usr/bin/aclocal /usr/bin/aclocal-1.17 \
32+
&& ln -s /usr/bin/automake /usr/bin/automake-1.17
33+
2834
# Install toolchains in /opt
29-
RUN curl downloads.arduino.cc/tools/internal/toolchains.tar.gz | tar -xz "opt"
35+
RUN curl -L downloads.arduino.cc/tools/internal/toolchains.tar.gz | tar -xz "opt"
3036
# install proper arm toolchains (already present in the toolchains.tar.gz archive)
3137
# 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 && \
3238
# 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
3339

34-
RUN cd /opt/osxcross && \
35-
git pull && \
40+
WORKDIR /opt/osxcross
41+
RUN git pull && \
3642
# use a specific version of osxcross (it does not have tags), this commit has the automatic install of compiler_rt libraries
3743
git checkout b875d7c1360c8ff2077463d7a5a12e1cff1cc683 && \
3844
UNATTENDED=1 SDK_VERSION=10.15 ./build.sh && \
3945
ENABLE_COMPILER_RT_INSTALL=1 SDK_VERSION=10.15 ./build_compiler_rt.sh
46+
4047
# Set toolchains paths
4148
# arm-linux-gnueabihf-gcc -> linux_arm
4249
# aarch64-linux-gnu-gcc -> linux_arm64
@@ -45,8 +52,6 @@ RUN cd /opt/osxcross && \
4552
# o64-clang -> darwin_amd64
4653
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
4754

48-
WORKDIR /workdir
49-
5055
# Handle libusb and libudev compilation and merging
5156
COPY deps/ /opt/lib/
5257
# compiler name is arm-linux-gnueabihf-gcc '-gcc' is added by ./configure
@@ -55,20 +60,20 @@ RUN CROSS_COMPILE=x86_64-ubuntu16.04-linux-gnu /opt/lib/build_libs.sh && \
5560
CROSS_COMPILE=aarch64-linux-gnu /opt/lib/build_libs.sh && \
5661
CROSS_COMPILE=i686-ubuntu16.04-linux-gnu /opt/lib/build_libs.sh && \
5762
CROSS_COMPILE=i686-w64-mingw32 /opt/lib/build_libs.sh && \
58-
# CROSS_COMPILER is used to override the compiler
63+
# CROSS_COMPILER is used to override the compiler
5964
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
6065

61-
FROM ubuntu:latest
66+
FROM ubuntu:22.04
6267
# Copy all the installed toolchains and compiled libs
6368
COPY --from=build /opt /opt
64-
COPY --from=build /usr/lib/llvm-10/lib/clang/10.0.0 /usr/lib/llvm-10/lib/clang/10.0.0
69+
COPY --from=build /usr/lib/llvm-13/lib/clang/13.0.1 /usr/lib/llvm-13/lib/clang/13.0.1
6570
ENV TZ=Europe/Rome
6671
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && \
6772
apt-get update && \
6873
apt-get install -y \
69-
build-essential \
74+
build-essential \
7075
# Intall clang compiler used by macos
71-
clang \
76+
clang-13 \
7277
cmake \
7378
dh-autoreconf \
7479
git \
@@ -79,7 +84,10 @@ RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone &
7984
tar \
8085
bison \
8186
flex \
82-
&& rm -rf /var/lib/apt/lists/*
87+
&& rm -rf /var/lib/apt/lists/* \
88+
&& ln -s /usr/bin/clang-13 /usr/bin/clang \
89+
&& ln -s /usr/bin/clang++-13 /usr/bin/clang++
90+
8391
# Set toolchains paths
8492
# arm-linux-gnueabihf-gcc -> linux_arm
8593
# aarch64-linux-gnu-gcc -> linux_arm64
@@ -88,6 +96,8 @@ RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone &
8896
# o64-clang -> darwin_amd64
8997
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
9098

91-
WORKDIR /workdir
99+
COPY scripts/configure_toolchain.sh /
92100

93-
ENTRYPOINT ["/bin/bash"]
101+
WORKDIR /workdir
102+
ENTRYPOINT ["/configure_toolchain.sh"]
103+
CMD ["bash"]

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
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.
1010

1111
## Starting Image
12-
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.
13-
14-
The starting image is only marginally important, since internally we use manually installed toolchains.
12+
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.
1513

1614
## The Toolchains
1715
The toolchains are download from http://downloads.arduino.cc/tools/internal/toolchains.tar.gz .
@@ -40,4 +38,11 @@ To reduce the overall dimension of the docker image we used the [multi-stage bu
4038
Usefull commands you can use:
4139
- `docker build -t ghcr.io/arduino/crossbuild:<version> .` to build the container
4240
- `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)
43-
- `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).
41+
- `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.
42+
The image supports the following toolchain:
43+
44+
- x86_64-ubuntu16.04-linux-gnu
45+
- arm-linux-gnueabihf
46+
- aarch64-linux-gnu
47+
- i686-ubuntu16.04-linux-gnu
48+
- x86_64-apple-darwin13

Taskfile.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ tasks:
5151
-type d -name '.licenses' -prune -o \
5252
-type d -name '__pycache__' -prune -o \
5353
-type d -name 'node_modules' -prune -o \
54+
-type d -path "./deps/*" -prune -o \
5455
-regex ".*[.]md" -print
5556
); do
5657
markdown-link-check \
@@ -78,7 +79,7 @@ tasks:
7879
- task: npm:install-deps
7980
cmds:
8081
- npx markdownlint-cli "**/*.md"
81-
82+
8283
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/npm-task/Taskfile.yml
8384
npm:install-deps:
8485
desc: Install dependencies managed by npm
@@ -111,9 +112,7 @@ tasks:
111112
-type d -name 'node_modules' -prune -or \
112113
-type d -path './deps/*' -prune -or \
113114
\( \
114-
-regextype posix-extended \
115-
-regex '.*[.](bash|sh)' -and \
116-
-type f \
115+
-name '*.bash' -or -name '*.sh' -and -type f \
117116
\) \
118117
-print
119118
)

deps/build_libs.sh

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ export PREFIX=/opt/lib/${CROSS_COMPILE}
77

88
if [ "$CROSS_COMPILER" == "" ]; then
99
CROSS_COMPILER=${CROSS_COMPILE}-gcc
10-
CROSS_COMPILER_CXX=${CROSS_COMPILE}-g++
10+
# CROSS_COMPILER_CXX=${CROSS_COMPILE}-g++
1111
# AR=${CROSS_COMPILE}-ar
1212
else
1313
export CC=$CROSS_COMPILER
1414
export CXX=$CROSS_COMPILER++
1515
CROSS_COMPILER=$CC
16-
CROSS_COMPILER_CXX=$CXX
16+
# CROSS_COMPILER_CXX=$CXX
1717
fi
18-
cd /opt/lib/libusb-1.0.26
18+
cd /opt/lib/libusb-1.0.28
1919
LIBUSB_DIR=$(pwd)
2020
export LIBUSB_DIR
2121
./configure --prefix="${PREFIX}" --with-pic --disable-udev --enable-static --disable-shared --host="${CROSS_COMPILE}"
@@ -30,7 +30,7 @@ if [[ $CROSS_COMPILE == "x86_64-apple-darwin13" ]]; then
3030
export LIBUSB_1_0_CFLAGS=-I${PREFIX}/include/libusb-1.0
3131
export LIBUSB_1_0_LIBS="-L${PREFIX}/lib -lusb-1.0"
3232
fi
33-
cd /opt/lib/libusb-compat-0.1.7
33+
cd /opt/lib/libusb-compat-0.1.8
3434
LIBUSB0_DIR=$(pwd)
3535
export LIBUSB0_DIR
3636
PKG_CONFIG_PATH="$PREFIX/lib/pkgconfig" ./configure --prefix="${PREFIX}" --enable-static --disable-shared --host="${CROSS_COMPILE}"
@@ -52,9 +52,10 @@ if [[ $CROSS_COMPILE == "x86_64-apple-darwin13" ]]; then
5252
CMAKE_EXTRA_FLAG="$CMAKE_EXTRA_FLAG -DCMAKE_AR=$AR -DCMAKE_RANLIB=$RANLIB"
5353
fi
5454

55-
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" ../
56-
make -j"$(nproc)"
57-
make install
55+
# TODO: did not build anymore (missing -L${PREFIX}/lib to libusb-1.0?)
56+
#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" ../
57+
#make -j"$(nproc)"
58+
#make install
5859

5960
cd /opt/lib/libelf-0.8.13
6061
LIBELF_DIR=$(pwd)
@@ -110,3 +111,8 @@ make distclean
110111
./configure --prefix="$PREFIX" --enable-static --disable-shared --host="$CROSS_COMPILE"
111112
make -j"$(nproc)"
112113
make install
114+
115+
tar -xzf /opt/lib/libxml2-2.14.3.tar.gz -C /tmp && cd /tmp/libxml2-2.14.3
116+
./autogen.sh --prefix="$PREFIX" --disable-shared --enable-static --without-python --without-iconv --host="$CROSS_COMPILE"
117+
make -j"$(nproc)"
118+
make install

0 commit comments

Comments
 (0)