Skip to content

Added pure C runfiles implementation - #849

Open
UebelAndre wants to merge 2 commits into
bazelbuild:mainfrom
UebelAndre:runfiles
Open

Added pure C runfiles implementation#849
UebelAndre wants to merge 2 commits into
bazelbuild:mainfrom
UebelAndre:runfiles

Conversation

@UebelAndre

Copy link
Copy Markdown
Contributor

This change re-implements the backbone of the runfiles library in C from C++ and introduces a new top level C interface at @rules_cc//cc/runfiles:runfiles_c. Documentation for the interfaces and high level differences between the C and C++ interfaces have been added to ./docs/runfiles.md

closes #400

@cerisier

cerisier commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

That's a good idea :) I'll battle test that in existing projects with cross-compilation to help validate.

@cerisier cerisier left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A few comments from early review.

Comment thread cc/runfiles/runfiles.h
//
// The current instance remains valid.
std::unique_ptr<Runfiles> WithSourceRepository(
const std::string& source_repository) const {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this intentional ?

This removes it entirely from the public API. And I see that tests changes below stopped exercising the method so it hid the breakage.

This should have its own C counter part.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, this was not intentional, restored!

Comment thread cc/runfiles/runfiles.cc Outdated
// returns <=0 for invalid paths, unknown runfiles, or buffer-too-
// small; all of those legitimately produce the empty string on the
// C++ side.
char buf[8192];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So this is not true on windows where paths can be 32k.
So either respect that or make a growing equivalent of std::string ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This lead to a larger refactor but directionally, the C interface aims to defer how this should be handled to users.

Comment thread cc/runfiles/runfiles_c.c Outdated
const char* source_repo, char* err, int err_len) {
if (!alloc) alloc = &g_libc_allocator;

char resolved_manifest[4096];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same comment here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Comment thread docs/runfiles.md Outdated

int main(int argc, char** argv) {
char err[256];
rf_runfiles* rf = rf_create(argv[0], err, sizeof(err));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Clanker found that the examples do not match the API anymore.

like rf_creates requires a rf_allocator but here not.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed!

Comment thread docs/runfiles.md Outdated
| C++ | `@rules_cc//cc/runfiles:runfiles` | `rules_cc/cc/runfiles/runfiles.h` |
| Pure C | `@rules_cc//cc/runfiles:runfiles_c` | `rules_cc/cc/runfiles/runfiles_c.h` |

The C library exposes a pluggable allocator (`rf_set_allocator`) so C

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Stale documentation, this API doesn't exist.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed!

Comment thread cc/runfiles/runfiles_c.c Outdated
const char* dir_env_key,
const char* source_repo, char* err,
int err_len) {
char* mf = rf_getenv_alloc("RUNFILES_MANIFEST_FILE");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

alloc is bypassed here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch!

@UebelAndre
UebelAndre requested a review from cerisier August 24, 2026 17:34
@trybka
trybka requested review from fmeum and removed request for cerisier August 24, 2026 17:36
@trybka

trybka commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

This generally looks good to me. I'm out the rest of the week, but I think given comments on the bug, would also appreciate a review from @fmeum.

If @fmeum and @cerisier both approve, I would be happy for someone on our end to merge this.

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.

Add C-only implementation of runfiles library

3 participants