Skip to content

Commit a26055f

Browse files
committed
Merge branch 'first_release' into main
2 parents 729258b + a65029c commit a26055f

File tree

407 files changed

+503067
-0
lines changed

Some content is hidden

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

407 files changed

+503067
-0
lines changed

Dockerfile

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
FROM ubuntu:latest as build
2+
3+
ENV TZ=Europe/Rome
4+
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && \
5+
apt-get update && \
6+
apt-get install -y \
7+
build-essential \
8+
# Intall clang compiler used by macos
9+
clang \
10+
cmake \
11+
curl \
12+
dh-autoreconf \
13+
git \
14+
gperf \
15+
# various libs required to compile osxcross
16+
libxml2-dev \
17+
libssl-dev \
18+
libz-dev \
19+
# Install Windows cross-tools
20+
mingw-w64 \
21+
p7zip-full \
22+
pkg-config \
23+
tar \
24+
&& rm -rf /var/lib/apt/lists/*
25+
# Install toolchains in /opt
26+
RUN curl downloads.arduino.cc/tools/internal/toolchains.tar.gz | tar -xz "opt"
27+
# install proper arm toolchains (already present in the toolchains.tar.gz archive)
28+
# 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 && \
29+
# 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
30+
31+
RUN cd /opt/osxcross \
32+
git pull \
33+
# use a specific version of osxcross (it does not have tags)
34+
git checkout da2c3d4ff604458a931b08b3af800c5a454136de \
35+
UNATTENDED=1 SDK_VERSION=10.15 ./build.sh
36+
# Set toolchains paths
37+
# arm-linux-gnueabihf-gcc -> linux_arm
38+
# aarch64-linux-gnu-gcc -> linux_arm64
39+
# x86_64-ubuntu16.04-linux-gnu-gcc -> linux_amd64
40+
# i686-ubuntu16.04-linux-gnu-gcc -> linux_386
41+
# o64-clang -> darwin_amd64
42+
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
43+
44+
WORKDIR /workdir
45+
46+
# Handle libusb and libudev compilation and merging
47+
COPY deps/ /opt/lib/
48+
# compiler name is arm-linux-gnueabihf-gcc '-gcc' is added by ./configure
49+
RUN CROSS_COMPILE=x86_64-ubuntu16.04-linux-gnu /opt/lib/build_libs.sh && \
50+
CROSS_COMPILE=arm-linux-gnueabihf /opt/lib/build_libs.sh && \
51+
CROSS_COMPILE=aarch64-linux-gnu /opt/lib/build_libs.sh && \
52+
CROSS_COMPILE=i686-ubuntu16.04-linux-gnu /opt/lib/build_libs.sh && \
53+
CROSS_COMPILE=i686-w64-mingw32 /opt/lib/build_libs.sh && \
54+
# CROSS_COMPILER is used to override the compiler
55+
CROSS_COMPILER=o64-clang CROSS_COMPILE=x86_64-apple-darwin13 /opt/lib/build_libs.sh
56+
57+
FROM ubuntu:latest
58+
# Copy all the installed toolchains and compiled libs
59+
COPY --from=build /opt /opt
60+
ENV TZ=Europe/Rome
61+
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && \
62+
apt-get update && \
63+
apt-get install -y \
64+
build-essential \
65+
# Intall clang compiler used by macos
66+
clang \
67+
cmake \
68+
dh-autoreconf \
69+
git \
70+
gperf \
71+
# Install Windows cross-tools
72+
mingw-w64 \
73+
pkg-config \
74+
tar \
75+
&& rm -rf /var/lib/apt/lists/*
76+
# Set toolchains paths
77+
# arm-linux-gnueabihf-gcc -> linux_arm
78+
# aarch64-linux-gnu-gcc -> linux_arm64
79+
# x86_64-ubuntu16.04-linux-gnu-gcc -> linux_amd64
80+
# i686-ubuntu16.04-linux-gnu-gcc -> linux_386
81+
# o64-clang -> darwin_amd64
82+
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
83+
84+
WORKDIR /workdir
85+
86+
ENTRYPOINT ["/bin/bash"]

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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).

deps/README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Dependencies
2+
The `deps/` folder contains the dependencies used to build and link statically `picotool` and `elf2uf2`: the libraries `libusb` and `libudev`.
3+
The `deps/` folder contains also a bash script used by the docker container to successfully build them with different toolchains and with different targets.
4+
This way they are already compiled and usable by the CI during the building/linking phase!
5+
6+
They come respectively from [here](https://github.com/arduino/OpenOCD-build-script/tree/static/libusb-1.0.20)
7+
and from [here](https://github.com/gentoo/eudev)
8+
9+
## `build_libs.sh`
10+
`build_libs.sh` is used by the [Dockerfile](../Dockerfile#L49-L55):
11+
Basically during the docker build phase the libraries are compiled with every toolchain available in the Docker container. Other libraries can be added, the [`build_libs.sh`](build_libs.sh) script needs to be adapted, but the Dockerfile should be ok.
12+
13+
## libusbudev
14+
libusbudev is the result of merging the two `.a` files with a command line tool called `ar`. This is done to ease the linking phase done by the [CI](.github/workflows/release.yml#L87) passing a single static library. See `LIBUSBUDEV` env variable [here](../../.github/workflows/release.yml#L67) and [here](../../.github/workflows/release.yml#L71).
15+
For macos is not required to merge the two libraries because libudev is not a requirement, so macos uses `libusb.a` only: thus the distinction between the two platforms. Infact libusb for mac is the last one built in the [Dockerfile](../Dockerfile#L55).
16+
17+
`libusbudev.a` is created by the `build_libs.sh` the directory structure created is the following:
18+
19+
```
20+
/opt/lib/
21+
|-- aarch64-linux-gnu
22+
| |-- libudev
23+
| |-- libusb
24+
| `-- libusbudev.a
25+
|-- arm-linux-gnueabihf
26+
| |-- libudev
27+
| |-- libusb
28+
| `-- libusbudev.a
29+
|-- build_libs.sh
30+
|-- eudev-3.2.10
31+
|-- i686-ubuntu16.04-linux-gnu
32+
| |-- libudev
33+
| |-- libusb
34+
| `-- libusbudev.a
35+
|-- i686-w64-mingw32
36+
| |-- libudev
37+
| |-- libusb
38+
| `-- libusbudev.a
39+
|-- libusb-1.0.20
40+
`-- x86_64-ubuntu16.04-linux-gnu
41+
|-- libudev
42+
|-- libusb
43+
`-- libusbudev.a
44+
```
45+
46+
The original `libusb.a` is available in `/opt/lib/libusb-1.0.20/libusb/.libs/libusb-1.0.a`
47+
and `libudev.a` is available in `/opt/lib/eudev-3.2.10/src/libudev/.libs/libudev.a`

deps/build_libs.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
3+
if [ x$CROSS_COMPILER == x ]; then
4+
CROSS_COMPILER=${CROSS_COMPILE}-gcc
5+
else
6+
export CC=$CROSS_COMPILER
7+
fi
8+
# udev lib not required for macos
9+
if [[ ${CROSS_COMPILE} != *apple* ]]; then
10+
cd /opt/lib/eudev-3.2.10
11+
export UDEV_DIR=`pwd`
12+
./autogen.sh
13+
./configure --enable-static --disable-shared --disable-blkid --disable-kmod --disable-manpages --host=${CROSS_COMPILE}
14+
make clean
15+
make -j4
16+
cd ..
17+
export CFLAGS="-I$UDEV_DIR/src/libudev/"
18+
export LDFLAGS="-L$UDEV_DIR/src/libudev/.libs/"
19+
export LIBS="-ludev"
20+
fi
21+
cd /opt/lib/libusb-1.0.20
22+
export LIBUSB_DIR=`pwd`
23+
./configure --enable-static --disable-shared --host=${CROSS_COMPILE}
24+
make clean
25+
make
26+
cd ..
27+
# libusbudev.a merged not required for macos
28+
if [[ ${CROSS_COMPILE} != *apple* ]]; then
29+
mkdir -p ${CROSS_COMPILE}/libusb
30+
mkdir -p ${CROSS_COMPILE}/libudev
31+
cd ${CROSS_COMPILE}/libusb/
32+
ar -x ../../libusb-1.0.20/libusb/.libs/libusb-1.0.a
33+
cd ../libudev/
34+
ar -x ../../eudev-3.2.10/src/libudev/.libs/libudev.a
35+
cd ..
36+
ar -qc libusbudev.a libudev/* libusb/*
37+
fi

deps/eudev-3.2.10/.gitignore

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
src/udev/udevadm
2+
src/udev/udevd
3+
4+
*.[oa]
5+
*.l[oa]
6+
.libs
7+
.deps
8+
Makefile
9+
Makefile.in
10+
11+
aclocal.m4
12+
autom4te.cache
13+
compile
14+
config.*
15+
configure
16+
libtool
17+
stamp-h1
18+
19+
depcomp
20+
install-sh
21+
ltmain.sh
22+
missing
23+
24+
*.pc
25+
26+
m4/libtool.m4
27+
m4/ltoptions.m4
28+
m4/ltsugar.m4
29+
m4/ltversion.m4
30+
m4/lt~obsolete.m4
31+
32+
rule_generator/write_net_rules
33+
34+
rules/64-btrfs.rules
35+
36+
src/ata_id/ata_id
37+
src/cdrom_id/cdrom_id
38+
src/collect/collect
39+
src/mtd_probe/mtd_probe
40+
src/scsi_id/scsi_id
41+
src/v4l_id/v4l_id
42+
43+
src/udev/keyboard-keys-from-name.gperf
44+
src/udev/keyboard-keys-from-name.h
45+
src/udev/keyboard-keys-to-name.h
46+
src/udev/keyboard-keys.txt
47+
48+
test/test-libudev
49+
test/test-udev
50+
test/test
51+
test-driver
52+
53+
test/rules-test.sh.log
54+
test/rules-test.sh.trs
55+
test/test-suite.log
56+
test/udev-test.pl.log
57+
test/udev-test.pl.trs
58+
59+
eudev-*.tar.gz

deps/eudev-3.2.10/.travis.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
language: c
2+
compiler:
3+
- gcc
4+
- clang
5+
before_install:
6+
- sudo apt-get update -qq
7+
- sudo apt-get install autotools-dev automake autoconf libtool gperf xsltproc docbook-xsl
8+
script: ./autogen.sh && ./configure && make V=1 distcheck
9+
notifications:
10+
irc:
11+
channels:
12+
- "irc.freenode.org#gentoo-udev"
13+
on_success: change
14+
on_failure: always

0 commit comments

Comments
 (0)