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 😆

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