Skip to content

Conversation

@dgoel
Copy link
Contributor

@dgoel dgoel commented Jul 2, 2025

What type of PR is this?

Bug fix

What does this PR do? Why is it needed?

My company has a complicated, uncommon bazel set up with nested bazel modules. We also use cgo extensively and have many go tests and binaries that end up linking to shared C++ libraries generated via other bazel modules. When such go tests are run with rbe, they fail due to failure to locate the shared libraries within the runfiles directory.

On deeper investigation, I found that the existing rpath computation assumes that both the executable and the library are present within the working directory. In reality, the executable is present outside the working directory but within the runfiles directory.

Normalizing the paths with respect to the runfiles directory fixes the issue.

Relevant links:

Other notes for review

I added a test to verify that rpath computation works with nested modules. In fairness, this mainly guarantees that there's no regression in existing functionality as the test passes even without my fix. So far, I've not been able to produce a minimum example that showcases the problem.

Existing tests in tests/core/cgo also exercise rpath computation.

@dgoel dgoel force-pushed the rpath_nested_bzlmods branch from 0957235 to a1d452b Compare July 2, 2025 11:33
Copy link
Member

@fmeum fmeum left a comment

Choose a reason for hiding this comment

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

Functionally looks good to me, just a few stylistic comments.

Copy link
Member

@fmeum fmeum left a comment

Choose a reason for hiding this comment

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

I applied minor edits that inline the new variables to keep the diff small. I hope you don't mind :-)

Dhiraj Goel and others added 5 commits July 2, 2025 17:36
Previous code was assuming that both the binary and the shared library
are present under the working directory. This assumption is violated for
a repo with nested modules.

The fix is to compute rpath relative to the runfiles directory.
@fmeum fmeum force-pushed the rpath_nested_bzlmods branch from ab37811 to 7cfc71c Compare July 2, 2025 15:36
@fmeum fmeum enabled auto-merge (squash) July 2, 2025 15:36
@fmeum fmeum merged commit 98940c3 into bazel-contrib:master Jul 2, 2025
1 check passed
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.

2 participants