Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 18, 2025

Fixes #689

Cross-compilation with PKG_CONFIG_SYSROOT_DIR fails when probing OpenCV because multiarch detection queries the build host instead of the target, causing header lookups in wrong paths.

Changes

Modified build/header.rs::get_multiarch_header_dir():

  • Derive target multiarch from CARGO_CFG_TARGET_* instead of querying build host

    • Maps: x86_64-*-linux-gnux86_64-linux-gnu, aarch64-*-linux-gnuaarch64-linux-gnu, etc.
    • Falls back to host detection for native builds
  • Prepend PKG_CONFIG_SYSROOT_DIR to multiarch paths when set

    • Checks {sysroot}/usr/include/{multiarch}/opencv4 before /usr/include/{multiarch}/opencv4
  • Add debug logging to show which multiarch and paths are being checked

Example

Cross-compiling for aarch64 from x86_64 host:

# Before: looks for /usr/include/x86_64-linux-gnu/opencv4 (wrong)
# After: looks for /rpi-root/usr/include/aarch64-linux-gnu/opencv4 (correct)
export PKG_CONFIG_SYSROOT_DIR=/rpi-root
cargo build --target aarch64-unknown-linux-gnu
Original prompt

Check the following issue: #689

User is complaining about the broken build inside example Dockerfile for cross compiling.

Investigate the issue and submit a PR fixing the Dockerfile or the project code if there is something wrong with the code logic.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits November 18, 2025 15:48
When PKG_CONFIG_SYSROOT_DIR is set (cross-compilation scenario), check
for OpenCV headers under the sysroot directory first before falling back
to host system paths.

Co-authored-by: twistedfall <406037+twistedfall@users.noreply.github.com>
When cross-compiling, detect the target's multiarch from CARGO_CFG_TARGET_*
environment variables instead of querying the build host. This ensures we
look for OpenCV headers in the correct multiarch directory for the target
platform.

Co-authored-by: twistedfall <406037+twistedfall@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix broken build in example Dockerfile for cross compiling Fix cross-compilation by deriving target multiarch from Cargo target triple Nov 18, 2025
Copilot AI requested a review from twistedfall November 18, 2025 15:59
Copilot finished work on behalf of twistedfall November 18, 2025 15:59
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.

Commit d4c3879b04dfdf8489ef2c87f7908b6a74d28782 break Cross-Compile using your Docker

2 participants