Skip to content

fix(cgo): Handle headers in external repositories from cc_imports#4583

Open
blorente wants to merge 2 commits intobazel-contrib:masterfrom
blorente:blorente/fix_cc_import_headers
Open

fix(cgo): Handle headers in external repositories from cc_imports#4583
blorente wants to merge 2 commits intobazel-contrib:masterfrom
blorente:blorente/fix_cc_import_headers

Conversation

@blorente
Copy link
Copy Markdown

@blorente blorente commented Apr 5, 2026

What type of PR is this?

Bug fix

What does this PR do? Why is it needed?

When depending on cc_import targets from external repositories, their includes attribute doesn't get resolved to execroot-relative paths. This means that we end up having -Imy/includes/dir instead of -Iexternal/external_repo_name/my/includes/dir, which leads to missing headers during compilation.

As a consequence, the -dev packages generated by rules_distroless were not being imported correctly, and we had to manually insert -isystem flags with canonical repository names.

Which issues(s) does this PR fix?

Fixes #

Other notes for review
This PR doesn't really depend on #4574, but both are needed for the project I'm working on and I'd rather that one merges first if possible, as it doesn't have a workaround.

@blorente blorente force-pushed the blorente/fix_cc_import_headers branch from a038f38 to e5b0c15 Compare April 5, 2026 18:36
@blorente blorente force-pushed the blorente/fix_cc_import_headers branch from e5b0c15 to 92676bf Compare April 5, 2026 18:37
@blorente blorente marked this pull request as ready for review April 5, 2026 18:39
pure = "on",
)

go_bazel_test(
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I'm happy to move this somewhere else, but I'm not quite sure where the best place would be. Any suggestions?

@fmeum
Copy link
Copy Markdown
Member

fmeum commented Apr 9, 2026

@keith Do you see a less manual way to produce the correct paths?

@keith
Copy link
Copy Markdown
Member

keith commented Apr 9, 2026

fwiw i fixed the cc_import not resolving includes like cc_library in bazel 9.x bazelbuild/bazel@d948e4d

@blorente
Copy link
Copy Markdown
Author

@keith that is so cool! I think that change makes this one unnecessary for Bazel 9.x because the external includes will be resolved correctly. Since it's also in rules_cc, I guess we should be able to just update rules_cc and consume it? I'll do some experimenting.

However, that would mean bumping the rules_cc requirement in rules_go to at least 0.2.0, I think (link). @fmeum is that something we're comfortable doing in this repository, or are we trying to not to impose dependency versions if we can avoid it? I think we can always "vendor in" the change if we need to as an alternative.

@fmeum
Copy link
Copy Markdown
Member

fmeum commented Apr 13, 2026

No, we usually just bump dependencies when a feature in them could be useful.

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