Opencv-rust: Fails to load .so at runtime

I opened a detailed issue in the repository, but just in case… I created a Docker image from rust:1.57.0-bullseye and compiled OpenCV with the contrib and non-free modules. I can see the .so files in /usr/local/lib, and based on the output from cargo test -vv I can see that /usr/local/lib is being included in the link paths. However, when I try to run my tests (which is where OpenCV is used), I get this error:

Finished test [unoptimized + debuginfo] target(s) in 1m 59s
     Running `/usr/src/app/rust/target/debug/deps/backend-e32510369b055f2d`
/usr/src/app/rust/target/debug/deps/backend-e32510369b055f2d: error while loading shared libraries: libopencv_xfeatures2d.so.4.5: cannot open shared object file: No such file or directory
error: test failed, to rerun pass '--bin backend'

Is there something more I need to do for Rust to be able to find the library? I tried with OPENCV_LINK_PATHS=+/usr/local/lib as well, but the result was the same. I’ve uploaded the full RUST_BACKTRACE=1 cargo -vv test output separately. I’ll repeat the dev Dockerfile here (note that I’m mounting my source as a volume):

FROM rust:1.57.0-bullseye

ARG OPENCV_VERSION=4.5.1

RUN apt-get update -qq && apt-get install -qqy wget software-properties-common libclang-dev cmake make unzip

RUN bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)"

RUN cd /tmp && \
    wget -O opencv.zip https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip && \
    wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/${OPENCV_VERSION}.zip && \
    unzip opencv.zip && \
    unzip opencv_contrib.zip && \
    mkdir build && \
    cd build && \
    cmake -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib-${OPENCV_VERSION}/modules -DOPENCV_ENABLE_NONFREE:BOOL=ON ../opencv-${OPENCV_VERSION} && \
    cmake --build . -j $(nproc) && \
    make install

RUN ln -s /usr/lib/llvm-13/bin/llvm-config /usr/local/bin/llvm-config

Fixed by setting LD_LIBRARY_PATH programmatically. Now I can get back to debugging my own problematic code!