Skip to content

Commit 19bc47d

Browse files
committed
Update example Dockerfiles
1 parent 46c3c59 commit 19bc47d

File tree

5 files changed

+91
-45
lines changed

5 files changed

+91
-45
lines changed

CHANGES.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@
283283
* Don't require `runtime` feature of `clang`.
284284

285285
* 0.81.2
286-
* Fix building when crosscompiling with target-specific RUSTFLAGS.
286+
* Fix building when cross-compiling with target-specific RUSTFLAGS.
287287

288288
* 0.81.1
289289
* Fix building on macOS (fixes https://github.com/twistedfall/opencv-rust/issues/460).
@@ -309,7 +309,7 @@
309309

310310
* 0.78.1
311311
* Automatically implement `Clone` for those classes that are constructor-copiable in C++, e.g. `KeyPoint`.
312-
* Fixes for crosscompiling (kudos to icedrocket).
312+
* Fixes for cross-compiling (kudos to icedrocket).
313313

314314
* 0.78.0
315315
* Don't strip "lib" prefix from linked libraries when building with MSVC (kudos to icedrocket)
@@ -648,7 +648,7 @@
648648
* Internal improvements and cleanups
649649
650650
* 0.38.0
651-
* Fix crosscompilation when targeting Windows platform.
651+
* Fix cross-compilation when targeting Windows platform.
652652
* Fix generation of bigger binaries
653653
654654
* 0.37.0

INSTALL.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ and additionally to support more OpenCV modules:
2424
`zypper install opencv-devel clang-devel gcc-c++`
2525

2626
#### Other Linux:
27+
2728
You have several options of getting the OpenCV library:
2829

2930
* install it from the repository, make sure to install `-dev` packages because they contain headers necessary
@@ -36,8 +37,9 @@ You have several options of getting the OpenCV library:
3637

3738
Additionally, please make sure to install `clang` package or its derivative that contains `libclang.so` and
3839
`clang` binary.
39-
* Gentoo, Fedora: `clang`
40-
* Debian, Ubuntu: `clang` and `libclang-dev`
40+
41+
* Gentoo, Fedora: `clang`
42+
* Debian, Ubuntu: `clang` and `libclang-dev`
4143

4244
### Windows package
4345

@@ -78,7 +80,8 @@ Get OpenCV from homebrew:
7880
brew install llvm
7981
```
8082

81-
If you have already installed OpenCV via Homebrew, there is no need to configure any environment variables specifically for OpenCV on macOS. The OpenCV installation can be automatically detected if it was installed through Homebrew.
83+
If you have already installed OpenCV via Homebrew, there is no need to configure any environment variables specifically for
84+
OpenCV on macOS. The OpenCV installation can be automatically detected if it was installed through Homebrew.
8285

8386
To take advantage of this automatic detection, refrain from setting the following environment variables:
8487

@@ -112,9 +115,9 @@ you can get some information on how to perform the build in CI scripts:
112115
[install-ubuntu.sh](https://github.com/twistedfall/opencv-rust/blob/master/ci/install-ubuntu.sh) and
113116
[script.sh](https://github.com/twistedfall/opencv-rust/blob/master/ci/script.sh), search for `"static"` string.
114117

115-
### Crosscompilation
118+
### Cross-compilation
116119

117-
Cross-compilation is supported to at least some extent. The ability to crosscompile projects using `opencv` from x86-64
120+
Cross-compilation is supported to at least some extent. The ability to cross-compile projects using `opencv` from x86-64
118121
Linux host machine to Raspberry Pi is tested regularly. Cross-compilation is notoriously difficult to set up, so you can
119122
use this example [rpi-xcompile.Dockerfile](https://github.com/twistedfall/opencv-rust/blob/master/tools/docker/rpi-xcompile.Dockerfile).
120123

@@ -128,4 +131,4 @@ Building this image requries `qemu-arm` to be present on the host system and the
128131

129132
After the successful build you will have an image configured for cross-compilation to Raspberry Pi. It will contain the
130133
sample build script `/usr/local/bin/cargo-xbuild` that you can check for the correct environment setup and the specific
131-
command line arguments to use when crosscompiling the project inside the container created from that image.
134+
command line arguments to use when cross-compiling the project inside the container created from that image.

tools/docker/rpi-xcompile.Dockerfile

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,37 @@
55
#
66
# After the successful build you will have an image configured for cross-compilation to Raspberry Pi. It will contain the
77
# sample build script `/usr/local/bin/cargo-xbuild` that you can check for the correct environment setup and the specific
8-
# command line arguments to use when crosscompiling the project inside the container created from that image.
8+
# command line arguments to use when cross-compiling the project inside the container created from that image.
99

1010

1111
# Download and extract rpi root filesystem
12-
FROM alpine:3.18
12+
FROM alpine:3.22
1313

14-
RUN set -xeu && \
15-
apk add xz
16-
17-
ADD https://downloads.raspberrypi.org/raspios_lite_armhf/root.tar.xz /
14+
ADD https://downloads.raspberrypi.org/raspios_lite_armhf/images/raspios_lite_armhf-2025-10-02/2025-10-01-raspios-trixie-armhf-lite.img.xz /raspios-lite-armhf.img.xz
1815

16+
# chmod calls are necessary because 7zip doesn't preserve file permissions during extraction
1917
RUN set -xeu && \
20-
mkdir "/rpi-root" && \
21-
tar xpaf /root.tar.xz -C /rpi-root
22-
23-
24-
# Prepare the root of the rpi filesystem, it's going to be used later for crosscompilation
18+
apk add xz 7zip && \
19+
unxz /raspios-lite-armhf.img.xz && \
20+
7z x -so /raspios-lite-armhf.img 1.img > rootfs.img && \
21+
7z x -snld -o/rpi-root rootfs.img && \
22+
chmod -R 755 /rpi-root/bin /rpi-root/boot /rpi-root/dev /rpi-root/etc /rpi-root/home /rpi-root/lib /rpi-root/media \
23+
/rpi-root/mnt /rpi-root/opt /rpi-root/run /rpi-root/sbin /rpi-root/srv /rpi-root/usr /rpi-root/var && \
24+
chmod -R 1777 /rpi-root/tmp && \
25+
chmod -R 555 /rpi-root/sys /rpi-root/proc && \
26+
chmod -R 700 /rpi-root/root
27+
28+
# Prepare the root of the rpi filesystem, it's going to be used later for cross-compilation
2529
# This step requries qemu-arm to be present on the host system and the corresponding binfmt-misc set up
2630
FROM scratch
2731

2832
COPY --from=0 /rpi-root /
2933

34+
# initramfs-tools breaking dist-upgrade in Docker:
35+
# mkinitramfs: failed to determine device for /
36+
RUN set -xeu && \
37+
DEBIAN_FRONTEND=noninteractive apt-get purge -y initramfs-tools
38+
3039
RUN set -xeu && \
3140
apt-get update && \
3241
DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade -y && \
@@ -44,11 +53,11 @@ RUN set -xeu && \
4453

4554
# Specify dependencies that you need to have on rpi
4655
RUN set -xeu && \
47-
DEBIAN_FRONTEND=noninteractive apt-get install -y libudev-dev libsqlite3-dev libopencv-dev libstrophe-dev libcamera-dev pkg-config
56+
DEBIAN_FRONTEND=noninteractive apt-get install -y libopencv-dev
4857

4958

50-
# Create the image that will be used for crosscompilation
51-
FROM ubuntu:22.04
59+
# Create the image that will be used for cross-compilation
60+
FROM ubuntu:24.04
5261

5362
COPY --from=1 / /rpi-root
5463

@@ -59,28 +68,31 @@ RUN set -xeu && \
5968
apt-get -y autoclean
6069

6170
RUN set -xeu && \
62-
DEBIAN_FRONTEND=noninteractive apt-get install -y clang libclang-dev lld curl git build-essential pkg-config cmake
71+
DEBIAN_FRONTEND=noninteractive apt-get install -y clang libclang-dev lld curl git build-essential cmake
6372

6473
RUN set -xeu && \
6574
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile=minimal && \
6675
rm -rf /root/.rustup/tmp/* # warning: could not delete temp directory: /root/.rustup/tmp/szyc3h06vricp83o_dir
6776

68-
RUN set -xeu && \
69-
echo "[net]\ngit-fetch-with-cli = true\n[target.arm-unknown-linux-gnueabihf]\nlinker = \"clang-rpi\"" > /root/.cargo/config
70-
7177
ENV PATH="${PATH}:/root/.cargo/bin"
7278

7379
RUN set -xeu && \
7480
rustup target add arm-unknown-linux-gnueabihf
7581

82+
RUN set -xeu && \
83+
echo "[target.arm-unknown-linux-gnueabihf]\nlinker = \"clang-rpi\"" > /root/.cargo/config.toml
84+
7685
RUN echo '#!/bin/bash\n\
7786
RPI_ROOT="/rpi-root"\n\
78-
clang --target=arm-unknown-linux-gnueabihf -fuse-ld=lld --sysroot="$RPI_ROOT" --gcc-toolchain="$RPI_ROOT" "$@"' > /usr/local/bin/clang-rpi && chmod +x /usr/local/bin/clang-rpi
87+
clang --target=arm-unknown-linux-gnueabihf -fuse-ld=lld --sysroot="$RPI_ROOT" --gcc-install-dir="$RPI_ROOT/usr/lib/gcc/arm-linux-gnueabihf/14" -Wl,-z,notext -Wno-unused-command-line-argument "$@"' > /usr/local/bin/clang-rpi && \
88+
chmod +x /usr/local/bin/clang-rpi
7989

8090
RUN echo '#!/bin/bash\n\
8191
RPI_ROOT="/rpi-root"\n\
82-
export PKG_CONFIG_SYSROOT_DIR="$RPI_ROOT"\n\
83-
export PKG_CONFIG_LIBDIR="$RPI_ROOT/usr/lib/arm-linux-gnueabihf/pkgconfig"\n\
84-
export CC="clang-rpi"\n\
85-
export CXX="clang-rpi"\n\
92+
export OpenCV_DIR="$RPI_ROOT/usr/lib/arm-linux-gnueabihf/cmake"\n\
93+
export CC_arm_unknown_linux_gnueabihf=clang-rpi\n\
94+
export CXX_arm_unknown_linux_gnueabihf=clang-rpi\n\
95+
export CARGO_TARGET_ARM_UNKNOWN_LINUX_GNUEABIHF_LINKER=clang-rpi\n\
96+
export BINDGEN_EXTRA_CLANG_ARGS_arm_unknown_linux_gnueabihf="--sysroot=${RPI_ROOT}"\n\
97+
export CMAKE_CROSSCOMPILING=TRUE\n\
8698
cargo build -vv --target arm-unknown-linux-gnueabihf' > /usr/local/bin/cargo-xbuild && chmod +x /usr/local/bin/cargo-xbuild

tools/docker/ubuntu-22.04-opencv-full-build.Dockerfile renamed to tools/docker/ubuntu-24.04-opencv-full-build.Dockerfile

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Ubuntu 22.04 container builds OpenCV from source with the maximum possible enabled amount of features
1+
# Ubuntu 24.04 container builds OpenCV from source with the maximum possible enabled amount of features
22

3-
FROM ubuntu:22.04
3+
FROM ubuntu:24.04
44

55
RUN set -xeu && \
66
apt-get update && \
@@ -9,29 +9,60 @@ RUN set -xeu && \
99
apt-get -y autoclean
1010

1111
RUN set -xeu && \
12-
DEBIAN_FRONTEND=noninteractive apt-get install -y curl clang libclang-dev \
13-
cmake python3-numpy libatlas-base-dev libceres-dev libeigen3-dev liblapacke-dev libprotobuf-dev protobuf-compiler nvidia-cuda-dev libtesseract-dev \
14-
libwebp-dev libpng-dev libtiff-dev libopenexr-dev libgdal-dev libopenjp2-7-dev libopenjpip-server libopenjpip-dec-server libopenjp2-tools libhdf5-dev \
15-
libavcodec-dev libavformat-dev libavutil-dev libgphoto2-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libva-dev libdc1394-dev \
16-
libfreetype6-dev libharfbuzz-dev qtbase5-dev libvtk9-dev libogre-1.12-dev
12+
DEBIAN_FRONTEND=noninteractive apt-get install -y \
13+
clang \
14+
cmake \
15+
curl \
16+
libatlas-base-dev \
17+
libavcodec-dev \
18+
libavformat-dev \
19+
libavutil-dev \
20+
libceres-dev \
21+
libclang-dev \
22+
libdc1394-dev \
23+
libeigen3-dev \
24+
libfreetype6-dev \
25+
libgdal-dev \
26+
libgphoto2-dev \
27+
libgstreamer-plugins-base1.0-dev \
28+
libgstreamer1.0-dev \
29+
libharfbuzz-dev \
30+
libhdf5-dev \
31+
liblapacke64-dev \
32+
libogre-1.12-dev \
33+
libopenexr-dev \
34+
libopenjp2-7-dev \
35+
libopenjp2-tools \
36+
libopenjpip-dec-server \
37+
libopenjpip-server \
38+
libpng-dev \
39+
libprotobuf-dev \
40+
libtesseract-dev \
41+
libtiff-dev \
42+
libva-dev \
43+
libvtk9-dev \
44+
libwebp-dev \
45+
nvidia-cuda-dev \
46+
protobuf-compiler \
47+
python3-numpy \
48+
qtbase5-dev
1749

1850
RUN set -xeu && \
1951
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile=minimal
2052

2153
ENV PATH="${PATH}:/root/.cargo/bin"
2254

23-
ARG OPENCV_VERSION=4.8.0
55+
ARG OPENCV_VERSION=4.11.0
2456

2557
RUN set -xeu && \
2658
mkdir -p /root/dist && \
2759
curl -sSfL "https://github.com/opencv/opencv/archive/refs/tags/${OPENCV_VERSION}.tar.gz" | tar xz -C /root/dist && \
28-
curl -sSfL "https://github.com/opencv/opencv_contrib/archive/refs/tags/${OPENCV_VERSION}.tar.gz" | tar xz -C /root/dist && \
29-
sed -ri 's/Ptr<FarnebackOpticalFlow> cv::cuda::FarnebackOpticalFlow::create/Ptr<cv::cuda::FarnebackOpticalFlow> cv::cuda::FarnebackOpticalFlow::create/' "/root/dist/opencv_contrib-${OPENCV_VERSION}/modules/cudaoptflow/src/farneback.cpp" # patch for version 4.8.0
60+
curl -sSfL "https://github.com/opencv/opencv_contrib/archive/refs/tags/${OPENCV_VERSION}.tar.gz" | tar xz -C /root/dist
3061

3162
RUN set -xeu && \
3263
mkdir -p /root/build && \
3364
cmake -B /root/build -S "/root/dist/opencv-${OPENCV_VERSION}" -D OPENCV_EXTRA_MODULES_PATH="/root/dist/opencv_contrib-${OPENCV_VERSION}/modules" -D CMAKE_INSTALL_PREFIX=/usr \
34-
-D BUILD_CUDA_STUBS=ON \
65+
-D BUILD_CUDA_STUBS=OFF \
3566
-D BUILD_DOCS=OFF \
3667
-D BUILD_EXAMPLES=OFF \
3768
-D BUILD_IPP_IW=ON \

tools/docker/ubuntu-22.04-opencv-system.Dockerfile renamed to tools/docker/ubuntu-24.04-opencv-system.Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Straghtforward Ubuntu 22.04 container that uses system OpenCV
1+
# Straghtforward Ubuntu 24.04 container that uses system OpenCV
22

3-
FROM ubuntu:22.04
3+
FROM ubuntu:24.04
44

55
RUN set -xeu && \
66
apt-get update && \

0 commit comments

Comments
 (0)