Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 3, 2025

Fix OpenCV detection when header files are symlinks (Issue #697)

Problem

The build script fails to detect OpenCV header files when they are symlinks, causing "Generating 0 modules" error. This commonly occurs with bazel builds which use symlinks for include directories.

Root Cause

The files_with_predicate function in build.rs uses DirEntry::file_type().is_file() which doesn't follow symlinks. Symlinks are treated as symlinks, not as regular files.

Solution

Changed to use Path::metadata() which follows symlinks by default, while maintaining the original code style with is_ok_and and then:

// Before (broken with symlinks)
.filter_map(|e| e.file_type().is_ok_and(|typ| typ.is_file()).then(|| e.path()))

// After (works with symlinks, same code style)
.filter_map(|e| {
    let path = e.path();
    // Use path.metadata() instead of e.file_type() to follow symlinks
    path.metadata().is_ok_and(|m| m.is_file()).then(|| path)
})

Testing

  • ✅ Regular files: 6 files detected
  • ✅ Symlinked files: 6 files detected (previously 0)
  • ✅ Code style matches original pattern with is_ok_and + then

Impact

This fix allows opencv-rust to work with:

  • Bazel builds using symlinked include directories
  • Any build system creating symlinked header files
  • Development setups using symlinks for multiple OpenCV versions

Fixes #697

Original prompt

Check the issue report: #697 The last comment from the reporter suggests that there is a problem detecting the OpenCV when they are symlinks. Investigate the codebase and fix this issue.


✨ 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 self-assigned this Nov 3, 2025
Co-authored-by: twistedfall <406037+twistedfall@users.noreply.github.com>
Copilot AI changed the title [WIP] Check the issue report: https://github.com/twistedfall/opencv-rust/issues/697 The last comment from the reporter suggests that there is a problem detecting the OpenCV when they are symlinks. Investigate the codebase and fix this issue. Fix OpenCV header detection for symlinked files Nov 3, 2025
Copilot AI requested a review from twistedfall November 3, 2025 13:52
Copilot finished work on behalf of twistedfall November 3, 2025 13:52
@twistedfall
Copy link
Owner

@copilot Can you please keep the initial code style with is_ok_and + then?

Co-authored-by: twistedfall <406037+twistedfall@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 3, 2025

@copilot Can you please keep the initial code style with is_ok_and + then?

Done! Updated to use is_ok_and + then pattern while maintaining the symlink fix. The code now follows symlinks by using path.metadata() instead of e.file_type(), preserving the original code style. Commit: 2072ad2

Copilot finished work on behalf of twistedfall November 3, 2025 14:06
@twistedfall twistedfall marked this pull request as ready for review November 3, 2025 15:01
@twistedfall twistedfall merged commit 747ddf6 into master Nov 3, 2025
36 checks passed
@twistedfall twistedfall deleted the copilot/fix-406037-33914894-3f08e117-ed71-4eef-a6ad-416ea705d9be branch November 3, 2025 15:01
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.

diagnostics of selective OpenCV build during building

2 participants