Skip to content

Conversation

@hofbi
Copy link
Contributor

@hofbi hofbi commented Sep 22, 2025

#3399 changed the behavior of runfiles. Due to this change a few cases no longer work with bazel run that did work before. I tried to create a more complex runfiles example since rules_rust does not have anyone yet + we can use it for discussing what should be the correct behavior.

# Everything with bazel test still works
bazel test //...

# bazel run no longer works for all cases that work with bazel test
bazel run //pkg_a:pkg_a_binary
bazel run //pkg_b:pkg_b_binary

I added a comment to the few cases that still work with bazel test but no longer work with bazel run. In particular, this happens when requesting a folder through runfiles instead of an individual file.

@scasagrande
Copy link

In particular, this happens when requesting a folder through runfiles instead of an individual file.

I recently noticed this as well. To get around this I adjusted some code to look for the BUILD.bazel file in the directory, and then trim off the file.

@hofbi
Copy link
Contributor Author

hofbi commented Sep 23, 2025

In particular, this happens when requesting a folder through runfiles instead of an individual file.

I recently noticed this as well. To get around this I adjusted some code to look for the BUILD.bazel file in the directory, and then trim off the file.

Could you share an example?

@scasagrande
Copy link

Small correction, I just look for any specific file in the directory.

something along the lines of this should return the relative path to a/b/c/ . This would require a data dependency on a filegroup target under @a//b:c which at least contains the file somefile.txt.

        let target = "a/b/c/somefile.txt";
        let rf = runfiles::Runfiles::create()?;
        let path = runfiles::rlocation!(rf, target);
        let path = match path {
            Some(value) => value,
            None => {
                return Err(...)
            }
        };
        let path = match path.parent() {
            Some(value) => value,
            None => {
                return Err(...)
            }
        };

@hofbi
Copy link
Contributor Author

hofbi commented Sep 25, 2025

Yes, getting the parent of a particular file is what I also used for a quick fix. But it feels a bit hacky.

@scasagrande
Copy link

Well yeah 😆

@hofbi hofbi force-pushed the complex-runfiles-example branch from ab76d2a to c88c3cf Compare October 15, 2025 07:59
Copy link
Collaborator

@UebelAndre UebelAndre left a comment

Choose a reason for hiding this comment

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

Awesome, thank you so much!

@UebelAndre UebelAndre enabled auto-merge October 15, 2025 23:50
@hofbi
Copy link
Contributor Author

hofbi commented Oct 16, 2025

@UebelAndre Could you retigger the buildkite job. The 2 failing Mac build seem to be unrelated.

@UebelAndre UebelAndre added this pull request to the merge queue Oct 16, 2025
Merged via the queue into bazelbuild:main with commit a14b741 Oct 16, 2025
3 checks 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.

3 participants