Skip to content

Fix cross compilation of binding-generator - #720

Closed
AlexanderStein wants to merge 1 commit into
twistedfall:masterfrom
AlexanderStein:fix-cross-compile-isystem
Closed

Fix cross compilation of binding-generator#720
AlexanderStein wants to merge 1 commit into
twistedfall:masterfrom
AlexanderStein:fix-cross-compile-isystem

Conversation

@AlexanderStein

Copy link
Copy Markdown

Pass -nostdlibinc to clang so that host path will not be included, as they will break compilation with target SDK toolchain:
=== Using OpenCV headers from: /opt/sdk/dev/sysroots/armv8a-tq-linux/usr/include/opencv4
=== Clang: clang version 22.1.8
=== Clang command line args: [
"-isystem/opt/sdk/dev/sysroots/x86_64-tqsdk-linux/usr/lib/clang/22/include",
"-isystem/usr/local/include",
"-isystem/usr/include",
[...]

Please also consider adding this as a fix to 0.99.1. Currently build breaks on master for systems with both openvc5 and opencv4 installed, but the project requiring opencv4.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts how the binding generator discovers Clang’s default C/C++ include search paths so cross-compilation header parsing won’t accidentally pick up host system include directories.

Changes:

  • Pass -nostdlibinc to clang_sys::support::Clang::find(...) when collecting cpp_search_paths, to prevent host standard library include paths from being captured and later forwarded into the libclang parse.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@twistedfall

Copy link
Copy Markdown
Owner

This breaks the CI unfortunately, with errors indicating being unable to include system headers, e.g.:

  ===    /Users/runner/work/opencv-rust/opencv-rust/src_cpp/ocvrs_common.hpp:4:10: fatal error: 'memory' file not found

@AlexanderStein

Copy link
Copy Markdown
Author

I have no idea why the ubuntu 22.04 build breaks

[opencv 0.99.0] ===    /../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/cstdint:47:11: error: no member named 'int8_t' in the global namespace
[opencv 0.99.0] ===    /../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/cstdint:48:11: error: no member named 'int16_t' in the global namespace
[opencv 0.99.0] ===    /../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/cstdint:49:11: error: no member named 'int32_t' in the global namespace
[opencv 0.99.0] ===    /../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/cstdint:50:11: error: no member named 'int64_t' in the global namespace
[...]

As the include paths compared to ubuntu 24.04 are identical beside the version number, I suspect the LLVM-14 installation is somehow borked.
BTW: Why is clang-15 used with LLVM-14?

For Mac the include paths look good

  === Clang command line args: [
      "-isystem/Applications/Xcode_16.4.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/17/include",
      "-I/Users/runner/build/opencv/opencv-4.13.0-build",
      "-F/Users/runner/build/opencv/opencv-4.13.0-build",
      "-I/Users/runner/work/opencv-rust/opencv-rust/src_cpp",
      "-F/Users/runner/work/opencv-rust/opencv-rust/src_cpp",
      "-DOCVRS_PARSING_HEADERS",
      "-includeocvrs_common.hpp",
      "-std=c++17",
  ]

I don't have a Mac so I don't know where the memory header actually is located. How can we debug/proceed here?

@twistedfall

Copy link
Copy Markdown
Owner

Can you please try rebasing on the current master? I've made some changes that should hopefully make these errors disappear

Pass -nostdlibinc to clang so that host path will not be included, as they
will break compilation with target SDK toolchain:
  === Using OpenCV headers from: /opt/sdk/dev/sysroots/armv8a-tq-linux/usr/include/opencv4
  === Clang: clang version 22.1.8
  === Clang command line args: [
      "-isystem/opt/sdk/dev/sysroots/x86_64-tqsdk-linux/usr/lib/clang/22/include",
      "-isystem/usr/local/include",
      "-isystem/usr/include",
  [...]
@AlexanderStein
AlexanderStein force-pushed the fix-cross-compile-isystem branch from 5d66fcd to b86cb1e Compare July 23, 2026 18:15
@AlexanderStein

Copy link
Copy Markdown
Author

Okay, something is wrong with that GitHub container. Looking at Install dependencies job at https://github.com/twistedfall/opencv-rust/actions/runs/30032924477/job/89294032143?pr=720 you can see clearly that clang-14 is installed. I don't know where clang-15 is coming from. But in the end 2899f73 should most probably be reverted. I had to in my try below

Going on. I've tried to replicate the situation locally using podman. Here is what I got:

Dockerfile

FROM ubuntu:22.04

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y \
    curl \
    sudo \
    && rm -rf /var/lib/apt/lists/*

# rustup
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y
ENV PATH=/root/.cargo/bin:$PATH

RUN rustup default stable

WORKDIR /workspace

podman-compose.yml

version: "3.9"

services:
  opencv-rust-ubuntu2204:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: opencv-rust-ubuntu2204
    working_dir: /workspace

    volumes:
      - /home/alex/Dokumente/programmieren/rust/opencv-rust:/workspace:Z
      - cargo-registry:/root/.cargo/registry
      - cargo-git:/root/.cargo/git
      - target:/workspace/target
      - build-cache:/root/build

    environment:
      OPENCV_VERSION: "4.5.4"

    tty: true
    stdin_open: true

    command: >
      bash -lc "
        ci/install.sh &&
        ci/script.sh
      "

volumes:
  cargo-registry:
  cargo-git:
  target:
  build-cache:

Starting with podman-compose run --rm opencv-rust-ubuntu2204 bash and running

  • ci/install.sh
  • ci/script.sh

and everything compiles smoothly. I don't know what kind of ubuntu container is used here. But IMHO it is somehow borked.

@AlexanderStein

Copy link
Copy Markdown
Author

I think this is a dead end. This isn't the right way to fix it.

Meanwhile I've found a way to properly detect the SDK include paths. I have to set export OPENCV_CLANG_ARGS="--sysroot=$OECORE_TARGET_SYSROOT" to use the correct headers.

Sorry for the noise

@twistedfall

Copy link
Copy Markdown
Owner

I would say this is the correct way to go, your setup seems quite unique, so using some local-only overrides will be a faster way forward than trying to find a generic solution.

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.

3 participants