Skip to content

[bazel] Improve runfiles handling#10098

Merged
zbarsky-openai merged 2 commits intomainfrom
zbarsky/rust-up
Jan 29, 2026
Merged

[bazel] Improve runfiles handling#10098
zbarsky-openai merged 2 commits intomainfrom
zbarsky/rust-up

Conversation

@zbarsky-openai
Copy link
Contributor

we can't use runfiles directory on Windows due to path lengths, so swap to manifest strategy. Parsing the manifest is a bit complex and the format is changing in Bazel upstream, so pull in the official Rust library (via a small hack to make it importable...) and cleanup all the associated logic to work cleanly in both bazel and cargo without extra confusion

@zbarsky-openai zbarsky-openai force-pushed the zbarsky/rust-up branch 2 times, most recently from 4c176aa to cae3169 Compare January 28, 2026 18:35
@@ -72,6 +58,27 @@ fn cargo_bin_env_keys(name: &str) -> Vec<String> {
keys
}

fn resolve_bin_from_env(key: &str, value: OsString) -> Result<PathBuf, CargoBinError> {
let raw = PathBuf::from(&value);
if std::env::var_os("RUN_UNDER_RUNFILES").is_some() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's make this a constant with a docstring?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok will do, but that can only be used in this method, not in the macro (inlined to callers)


if let Some(root) =
buck_project_root().map_err(|source| CargoBinError::CurrentExe { source })?
#[doc(hidden)]
Copy link
Collaborator

Choose a reason for hiding this comment

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

#[doc(hidden)] is unnecessary for our purposes, I believe.

regex-lite = "0.1.8"
reqwest = "0.12"
rmcp = { version = "0.12.0", default-features = false }
runfiles = { git = "https://github.com/dzbarsky/rules_rust", rev = "b56cbaa8465e74127f1ea216f813cd377295ad81" }
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is our long-term plan for this dep?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

there's a few potential options:

  1. We figure out who owns the runfiles crate on crates.io and get it bumped
  2. We upstream this fix back to rules_rust so it's consumable from the "official" github
  3. We make it part of rules_rs and that becomes "official" as it continues to get traction

By the way, this is only necessary for cargo test and non-bazel clippy, so if there's a world where those flows are both bazelized, this can be removed (I will teach rules_rs to alias @crates//:runfiles to @rules_rust//rust/runfiles instead of the crate from crates.io)

.bazelrc Outdated
common --experimental_platform_in_output_dir

# Runfile paths are too long on Windows, so we can't enable them there. Disable directory strategy everywhere for consistency.
# Instead we use the runfiles manifest strategy.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you cite a path that is likely to be stable: maybe utils/cargo-bin/README.md (which would need to be created?)

@zbarsky-openai zbarsky-openai force-pushed the zbarsky/rust-up branch 2 times, most recently from 41affed to 89a88b5 Compare January 28, 2026 18:54
@zbarsky-openai zbarsky-openai enabled auto-merge (squash) January 28, 2026 18:55
@zbarsky-openai zbarsky-openai force-pushed the zbarsky/rust-up branch 5 times, most recently from d6b86ad to 6a091d6 Compare January 28, 2026 22:12
@etraut-openai etraut-openai added the oai PRs contributed by OpenAI employees label Jan 28, 2026
@zbarsky-openai zbarsky-openai merged commit 8497163 into main Jan 29, 2026
33 checks passed
@zbarsky-openai zbarsky-openai deleted the zbarsky/rust-up branch January 29, 2026 00:15
@github-actions github-actions bot locked and limited conversation to collaborators Jan 29, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

oai PRs contributed by OpenAI employees

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants