1919# $ docker run --privileged --rm tonistiigi/binfmt --install arm64
2020
2121FROM ubuntu:22.04
22- ENV DEBIAN_FRONTEND noninteractive
2322
2423# These are automatically provided by docker (no need for --build-arg)
2524ARG TARGETPLATFORM
2625ARG TARGETARCH
2726
28- RUN apt-get update && apt-get upgrade -y && apt-get install -y wget nano rsync curl gnupg2 jq unzip bzip2 xz-utils
27+ RUN export DEBIAN_FRONTEND=noninteractive; \
28+ apt-get update && \
29+ apt-get upgrade -y && \
30+ apt-get install -y nano rsync curl gnupg2 jq unzip bzip2 xz-utils && \
31+ rm -rf /var/lib/apt/lists/*
32+
2933
30- # for clang-*-15, see https://apt.llvm.org/
3134RUN echo "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main" >> /etc/apt/sources.list && \
3235 echo "deb-src http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main" >> /etc/apt/sources.list && \
33- wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
36+ curl -sSL https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
3437
35- # Install gcc8-arm-none-eabi
3638RUN if [ "${TARGETPLATFORM}" = "linux/arm64" ]; then \
3739 GNU_TOOLCHAIN=https://developer.arm.com/-/media/Files/downloads/gnu/13.3.rel1/binrel/arm-gnu-toolchain-13.3.rel1-aarch64-arm-none-eabi.tar.xz \
3840 GNU_TOOLCHAIN_HASH=c8824bffd057afce2259f7618254e840715f33523a3d4e4294f471208f976764 \
@@ -42,13 +44,14 @@ RUN if [ "${TARGETPLATFORM}" = "linux/arm64" ]; then \
4244 GNU_TOOLCHAIN_HASH=fb31fbdfe08406ece43eef5df623c0b2deb8b53e405e2c878300f7a1f303ee52 \
4345 GNU_TOOLCHAIN_FORMAT=bz2; \
4446 fi; \
45- wget -O gcc.tar.${GNU_TOOLCHAIN_FORMAT} ${GNU_TOOLCHAIN} &&\
46- echo "$GNU_TOOLCHAIN_HASH gcc.tar.${GNU_TOOLCHAIN_FORMAT}" | sha256sum -c &&\
47- tar -xvf gcc.tar.${GNU_TOOLCHAIN_FORMAT} -C /usr/local --strip-components=1 &&\
47+ curl -sSL -o gcc.tar.${GNU_TOOLCHAIN_FORMAT} ${GNU_TOOLCHAIN} && \
48+ echo "$GNU_TOOLCHAIN_HASH gcc.tar.${GNU_TOOLCHAIN_FORMAT}" | sha256sum -c && \
49+ tar -xf gcc.tar.${GNU_TOOLCHAIN_FORMAT} -C /usr/local --strip-components=1 && \
4850 rm -f gcc.tar.${GNU_TOOLCHAIN_FORMAT}
4951
5052# Tools for building
51- RUN apt-get update && apt-get install -y \
53+ RUN export DEBIAN_FRONTEND=noninteractive; \
54+ apt-get update && apt-get install -y \
5255 make \
5356 llvm-18 \
5457 gcc-10 \
@@ -64,98 +67,105 @@ RUN apt-get update && apt-get install -y \
6467 libcmocka-dev \
6568 libusb-1.0-0-dev \
6669 libudev-dev \
67- libhidapi-dev
70+ libhidapi-dev \
71+ && rm -rf /var/lib/apt/lists/*
6872
69- RUN apt-get update && apt-get install -y \
73+ RUN export DEBIAN_FRONTEND=noninteractive; \
74+ apt-get update && apt-get install -y \
7075 doxygen \
71- graphviz
76+ graphviz \
77+ && rm -rf /var/lib/apt/lists/*
7278
7379# Set gcc-10 as the default gcc
74- RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 100
75- RUN update-alternatives --install /usr/bin/gcov gcov /usr/bin/gcov-10 100
80+ RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 100 && \
81+ update-alternatives --install /usr/bin/gcov gcov /usr/bin/gcov-10 100 && \
82+ rm /var/log/alternatives.log
7683
7784# Tools for CI
78- RUN apt-get update && apt-get install -y \
85+ RUN export DEBIAN_FRONTEND=noninteractive; \
86+ apt-get update && apt-get install -y \
7987 python3 \
8088 python3-pip \
8189 clang-format-18 \
82- clang-tidy-18
83-
84- RUN python3 -m pip install --upgrade pip
90+ clang-tidy-18 \
91+ && rm -rf /var/lib/apt/lists/*
8592
8693# Python modules
87- COPY py/bitbox02 /tmp/bitbox02
88- RUN python3 -m pip install /tmp/bitbox02
89- RUN rm -r /tmp/bitbox02
90- COPY py/requirements.txt /tmp
91- RUN python3 -m pip install --upgrade --requirement /tmp/requirements.txt
92- RUN rm /tmp/requirements.txt
94+ RUN --mount=source=py,target=/mnt,rw \
95+ python3 -m pip install --no-compile --no-cache-dir /mnt/bitbox02 && \
96+ python3 -m pip install --no-compile --no-cache-dir --upgrade --requirement /mnt/requirements.txt && \
9397
9498# Python modules for CI
95- RUN python3 -m pip install --upgrade \
99+ RUN python3 -m pip install --no-compile --no-cache-dir -- upgrade \
96100 pylint==2.13.9 \
97101 pylint-protobuf==0.20.2 \
98102 black==22.3.0 \
99103 mypy==0.960 \
100104 mypy-protobuf==3.2.0
101105
102106# Python modules for packaging
103- RUN python3 -m pip install --upgrade \
107+ RUN python3 -m pip install --no-compile --no-cache-dir -- upgrade \
104108 setuptools==41.2.0 \
105109 wheel==0.33.6 \
106110 twine==1.15.0
107111
108112# Install protoc from release, because the version available on the repo is too old
113+ ENV PATH /opt/protoc/bin:$PATH
109114RUN if [ "${TARGETPLATFORM}" = "linux/arm64" ]; then \
110115 PROTOC_URL=https://github.com/protocolbuffers/protobuf/releases/download/v21.2/protoc-21.2-linux-aarch_64.zip; \
111116 else \
112117 PROTOC_URL=https://github.com/protocolbuffers/protobuf/releases/download/v21.2/protoc-21.2-linux-x86_64.zip; \
113118 fi; \
114119 mkdir -p /opt/protoc && \
115- curl -L0 ${PROTOC_URL} -o /tmp/protoc-21.2.zip && \
120+ curl -sSL0 ${PROTOC_URL} -o /tmp/protoc-21.2.zip && \
116121 unzip /tmp/protoc-21.2.zip -d /opt/protoc && \
117122 rm /tmp/protoc-21.2.zip
118- ENV PATH /opt/protoc/bin:$PATH
119123
120124# Developer tools
121- RUN apt-get update && apt-get install -y \
122- bash-completion
125+ RUN export DEBIAN_FRONTEND=noninteractive; \
126+ apt-get update && apt-get install -y \
127+ bash-completion \
128+ && rm -rf /var/lib/apt/lists/*
123129# Install gcovr from PIP to get a newer version than in apt repositories
124- RUN python3 -m pip install gcovr
130+ RUN python3 -m pip install --no-compile --no-cache-dir --upgrade \
131+ gcovr==7.2
125132
126133# Install Go, used for the tools in tools/go and for test/gounittest
127- ENV GOPATH /opt/go
128- ENV GOROOT /opt/go_dist/go
129- ENV PATH $GOROOT/bin:$GOPATH/bin:$PATH
134+ ENV PATH=/opt/go_dist/go/bin:/opt/go/bin:$PATH GOPATH=/opt/go GOROOT=/opt/go_dist/go
130135RUN mkdir -p /opt/go_dist && \
131- curl https://dl.google.com/go/go1.19.3.linux-${TARGETARCH}.tar.gz | tar -xz -C /opt/go_dist
136+ curl -sSL https://dl.google.com/go/go1.19.3.linux-${TARGETARCH}.tar.gz | tar -xz -C /opt/go_dist
132137
133138# Install lcov from release (the one from the repos is too old).
134- RUN cd /opt && wget https://github.com/linux-test-project/ lcov/releases/download/v1.14/lcov -1.14.tar.gz && tar -xf lcov-1.14.tar.gz
135- ENV PATH /opt/ lcov-1.14/bin:$PATH
139+ ENV PATH= /opt/ lcov-1.14/bin:$PATH
140+ RUN curl -sSL https://github.com/linux-test-project/ lcov/releases/download/v1.14/lcov -1.14.tar.gz | tar -xz -C /opt
136141
137142# Install rust compiler
138- ENV PATH /opt/cargo/bin:$PATH
139- ENV RUSTUP_HOME=/opt/rustup
140- COPY src/rust/rust-toolchain.toml /tmp/rust-toolchain.toml
141- RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | CARGO_HOME=/opt/cargo sh -s -- --default-toolchain $(grep -oP '(?<=channel = ")[^"]+' /tmp/rust-toolchain.toml) -y
142- RUN rustup target add thumbv7em-none-eabi
143- RUN rustup component add rustfmt
144- RUN rustup component add clippy
145- RUN rustup component add rust-src
146- RUN CARGO_HOME=/opt/cargo cargo install cbindgen --version 0.26.0 --locked
147- RUN CARGO_HOME=/opt/cargo cargo install bindgen-cli --version 0.69.4 --locked
143+ # Since bindgen embeds information about its target directory, use a deterministic path for it.
144+ ARG BINDGEN_VERSION=0.69.4
145+ ARG CBINDGEN_VERSION=0.26.0
146+ ENV PATH=/opt/cargo/bin:$PATH RUSTUP_HOME=/opt/rustup
147+ RUN --mount=source=tools/prost-build-proto,target=/mnt/prost-build-proto,rw \
148+ --mount=source=src/rust/rust-toolchain.toml,target=/mnt/rust-toolchain.toml \
149+ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | \
150+ CARGO_HOME=/opt/cargo sh -s -- --default-toolchain $(grep -oP '(?<=channel = ")[^"]+' /mnt/rust-toolchain.toml) -y && \
151+ rustup target add thumbv7em-none-eabi && \
152+ rustup component add rustfmt && \
153+ rustup component add clippy && \
154+ rustup component add rust-src && \
155+ if [ "${TARGETPLATFORM}" = "linux/arm64" ]; then \
156+ CARGO_HOME=/opt/cargo cargo install cbindgen --version ${CBINDGEN_VERSION} --locked && \
157+ CARGO_HOME=/opt/cargo cargo install bindgen-cli --version ${BINDGEN_VERSION} --locked --target-dir=/tmp/bindgen-target && rm -r /tmp/bindgen-target; \
158+ else \
159+ curl -sSL https://github.com/rust-lang/rust-bindgen/releases/download/v${BINDGEN_VERSION}/bindgen-cli-x86_64-unknown-linux-gnu.tar.xz | tar -xJ --strip-components=1 -C /opt/cargo/bin bindgen-cli-x86_64-unknown-linux-gnu/bindgen && \
160+ curl -sSL https://github.com/mozilla/cbindgen/releases/download/${CBINDGEN_VERSION}/cbindgen -o /opt/cargo/bin/cbindgen && chmod +x /opt/cargo/bin/cbindgen; \
161+ fi && \
162+ CARGO_HOME=/opt/cargo cargo install --path /mnt/prost-build-proto --locked && \
163+ rm -r /opt/cargo/registry/index /opt/cargo/.global-cache
148164
149165# Until cargo vendor supports vendoring dependencies of the rust std libs we
150166# need a copy of this file next to the toml file. It also has to be world
151167# writable so that invocations of `cargo vendor` can update it. Below is the
152168# tracking issue for `cargo vendor` to support rust std libs.
153169# https://github.com/rust-lang/wg-cargo-std-aware/issues/23
154- RUN cp "$(rustc --print=sysroot)/lib/rustlib/src/rust/Cargo.lock" "$(rustc --print=sysroot)/lib/rustlib/src/rust/library/test/"
155- RUN chmod 777 $(rustc --print=sysroot)/lib/rustlib/src/rust/library/test/Cargo.lock
156-
157- COPY tools/prost-build-proto prost-build-proto
158- RUN CARGO_HOME=/opt/cargo cargo install --path prost-build-proto --locked
159-
160- # Clean temporary files to reduce image size
161- RUN rm -rf /var/lib/apt/lists/*
170+ RUN cp "$(rustc --print=sysroot)/lib/rustlib/src/rust/Cargo.lock" "$(rustc --print=sysroot)/lib/rustlib/src/rust/library/test/" && \
171+ chmod 777 $(rustc --print=sysroot)/lib/rustlib/src/rust/library/test/Cargo.lock
0 commit comments