rules_cc icon indicating copy to clipboard operation
rules_cc copied to clipboard

request: look up runfile matches given only filename

Open peakschris opened this issue 5 months ago • 2 comments

For our use case it would be really helpful if the runfiles library had an API that took a filename and returned a vector of matches for that filename. Clearly this will iterate the entire std::map and be quite expensive and for our use case that is fine. We are replacing lookup of an executable by name in our legacy build with lookup of the same thing via runfiles and having to update all calling sites with bazel path is challenging for us. Plus the name based search would allow us to move executables around in our repo without modifying the call sites.

Thanks! Chris

peakschris avatar Jul 10 '25 22:07 peakschris

The Go runfiles library has a virtual FS implementation (https://github.com/bazel-contrib/rules_go/blob/master/go/runfiles/fs.go) that can do this. Does std::filesystem offer similar abstractions? That could be a better fit than a one-off function.

fmeum avatar Jul 11 '25 06:07 fmeum

That's a really nice concept; unfortunately std::filesystem does not. There are some little used github repos that offer a library for vfs but I don't think this is worth pulling in such a dependency.

A more general API could return the underlying map directly - or if you wanted to avoid exposing internals it could return a vector of structs - one per file.

peakschris avatar Jul 11 '25 07:07 peakschris