Skip to content

julia: fix bindings build with mirrored types and current CxxWrap#4143

Open
tae0x wants to merge 5 commits into
opencv:4.xfrom
tae0x:fix-julia-module-build
Open

julia: fix bindings build with mirrored types and current CxxWrap#4143
tae0x wants to merge 5 commits into
opencv:4.xfrom
tae0x:fix-julia-module-build

Conversation

@tae0x

@tae0x tae0x commented Jun 7, 2026

Copy link
Copy Markdown

Summary

This PR fixes the Julia bindings build against current OpenCV 4.x and recent Julia/CxxWrap releases.

The main issues addressed are:

  • The Julia generator can emit wrappers for OpenCV value types that are already mapped manually as CxxWrap mirrored types.
  • The Julia generator was not receiving the same OpenCV preprocessor definitions used by other binding generators, so generated wrappers could reference unavailable or version-gated symbols.
  • Recent Julia and CxxWrap releases changed APIs used by the Julia module's C++ support code.

Related issues

Fixes #4142.

Also addresses the mirrored-type failure reported in #3531.

Related to #3915, which reports current Julia/CxxWrap build failures including jl_array_data, vector_int, mirrored-type, and cv::Ptr errors.

Fix approach

The fix keeps manually mirrored OpenCV value types on the manual CxxWrap path and prevents the generator from also emitting regular class wrappers for them. This avoids the invalid map_type plus add_type combination for types such as cv::RotatedRect.

The Julia generator now receives OpenCV binding preprocessor definitions through a small generated JSON config, and the generator entry points pass those definitions to hdr_parser. This makes generated Julia wrappers respect the same module and version guards as the rest of the binding infrastructure.

The C++ support code uses version-gated compatibility paths for Julia and CxxWrap API changes:

  • Julia jl_array_data one-argument versus typed two-argument form.
  • CxxWrap pointer type construction changes.
  • CxxWrap julia_base_type return type handling.

The PR also adds aliases needed by the generated wrappers for current OpenCV headers, including vector_int, CirclesGridFinderParameters::GridType, and newer DNN enum aliases.

Verification

Tested with:

  • Official ubuntu:latest container image
  • OpenCV core 4.x
  • This opencv_contrib branch: fix-julia-module-build
  • Julia 1.12.6
  • CxxWrap 0.17.5
  • Target: opencv_julia

At the time of verification, opencv/opencv:4.x resolved to ab1aaa75, and this branch resolved to 72df737a.

Reproducer:

docker run --rm ubuntu:latest bash -lc '
set -euo pipefail
export DEBIAN_FRONTEND=noninteractive
export JULIA_VERSION=1.12.6
export WORKDIR=/work

apt-get update >/dev/null
apt-get install -y --no-install-recommends \
  ca-certificates curl git build-essential cmake ninja-build python3 pkg-config tar xz-utils >/dev/null

case "$(uname -m)" in
  x86_64|amd64) JULIA_ARCH=x64; JULIA_PLATFORM=linux-x86_64 ;;
  aarch64|arm64) JULIA_ARCH=aarch64; JULIA_PLATFORM=linux-aarch64 ;;
  *) echo "unsupported architecture: $(uname -m)" >&2; exit 2 ;;
esac

JULIA_MINOR="${JULIA_VERSION%.*}"
JULIA_URL="https://julialang-s3.julialang.org/bin/linux/${JULIA_ARCH}/${JULIA_MINOR}/julia-${JULIA_VERSION}-${JULIA_PLATFORM}.tar.gz"
mkdir -p /opt/julia "${WORKDIR}"
curl -fsSL --retry 3 --retry-delay 2 "${JULIA_URL}" -o /tmp/julia.tar.gz
tar -xzf /tmp/julia.tar.gz -C /opt/julia --strip-components=1
export PATH=/opt/julia/bin:${PATH}
export JULIA_DEPOT_PATH=${WORKDIR}/julia-depot

julia --startup-file=no --version
julia --startup-file=no -e "using Pkg; Pkg.add(\"CxxWrap\"); Pkg.precompile()"
JLCXX_PREFIX="$(julia --startup-file=no -e "using CxxWrap; print(CxxWrap.CxxWrapCore.prefix_path())")"
JLCXX_DIR="$(dirname "$(find "${JLCXX_PREFIX}" -name JlCxxConfig.cmake -print -quit)")"
test -n "${JLCXX_DIR}"
julia --startup-file=no -e "using Pkg; deps=Pkg.dependencies(); foreach(d -> d.second.name == \"CxxWrap\" && println(\"CxxWrap \" * string(d.second.version)), deps)"
echo "JlCxx_DIR=${JLCXX_DIR}"

git clone --depth=1 --branch 4.x https://github.com/opencv/opencv.git "${WORKDIR}/opencv"
git clone --depth=1 --branch fix-julia-module-build https://github.com/tae0x/opencv_contrib.git "${WORKDIR}/opencv_contrib"

cmake -S "${WORKDIR}/opencv" -B "${WORKDIR}/build" -G Ninja \
  -DCMAKE_BUILD_TYPE=Release \
  -DOPENCV_EXTRA_MODULES_PATH="${WORKDIR}/opencv_contrib/modules" \
  -DWITH_JULIA=ON \
  -DJulia_EXECUTABLE="$(command -v julia)" \
  -DJlCxx_DIR="${JLCXX_DIR}" \
  -DPYTHON_DEFAULT_EXECUTABLE="$(command -v python3)" \
  -DBUILD_LIST=core,imgproc,imgcodecs,highgui,videoio,dnn,features2d,objdetect,calib3d,julia \
  -DBUILD_TESTS=OFF \
  -DBUILD_PERF_TESTS=OFF \
  -DBUILD_EXAMPLES=OFF \
  -DBUILD_DOCS=OFF \
  -DBUILD_JAVA=OFF \
  -DBUILD_opencv_apps=OFF \
  -DBUILD_opencv_python2=OFF \
  -DBUILD_opencv_python3=OFF \
  -DWITH_FFMPEG=OFF \
  -DWITH_GSTREAMER=OFF \
  -DWITH_GTK=OFF \
  -DWITH_IPP=OFF \
  -DWITH_OPENCL=OFF \
  -DWITH_QT=OFF \
  -DWITH_TBB=OFF \
  -DWITH_V4L=OFF

cmake --build "${WORKDIR}/build" --target opencv_julia --parallel "$(nproc)"
'

This command completes by building and linking libopencv_julia.so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Julia bindings fail to build after RotatedRect became a wrapped type

2 participants