Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Without this, Bazel will consider BUILD.bazel files in
# .git/sl/origbackups (which can be populated by Sapling SCM).
.git
codex-rs/target
6 changes: 5 additions & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
common --repo_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
common --repo_env=BAZEL_NO_APPLE_CPP_TOOLCHAIN=1
# Dummy xcode config so we don't need to build xcode_locator in repo rule.
common --xcode_version_config=//:disable_xcode

common --disk_cache=~/.cache/bazel-disk-cache
common --repo_contents_cache=~/.cache/bazel-repo-contents-cache
Expand All @@ -9,6 +11,9 @@ startup --experimental_remote_repo_contents_cache

common --experimental_platform_in_output_dir

# Runfiles strategy rationale: codex-rs/utils/cargo-bin/README.md
common --noenable_runfiles

common --enable_platform_specific_config
# TODO(zbarsky): We need to untangle these libc constraints to get linux remote builds working.
common:linux --host_platform=//:local
Expand Down Expand Up @@ -44,4 +49,3 @@ common --jobs=30
common:remote --extra_execution_platforms=//:rbe
common:remote --remote_executor=grpcs://remote.buildbuddy.io
common:remote --jobs=800

4 changes: 4 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
load("@apple_support//xcode:xcode_config.bzl", "xcode_config")

xcode_config(name = "disable_xcode")

# We mark the local platform as glibc-compatible so that rust can grab a toolchain for us.
# TODO(zbarsky): Upstream a better libc constraint into rules_rust.
# We only enable this on linux though for sanity, and because it breaks remote execution.
Expand Down
7 changes: 7 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ register_toolchains(
"@toolchains_llvm_bootstrapped//toolchain:all",
)

# Needed to disable xcode...
bazel_dep(name = "apple_support", version = "2.1.0")
bazel_dep(name = "rules_cc", version = "0.2.16")
bazel_dep(name = "rules_platform", version = "0.1.0")
bazel_dep(name = "rules_rust", version = "0.68.1")
Expand Down Expand Up @@ -90,6 +92,11 @@ crate.annotation(

inject_repo(crate, "openssl")

crate.annotation(
crate = "runfiles",
workspace_cargo_toml = "rust/runfiles/Cargo.toml",
)

# Fix readme inclusions
crate.annotation(
crate = "windows-link",
Expand Down
4 changes: 3 additions & 1 deletion MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion codex-rs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions codex-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ regex = "1.12.2"
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)

schemars = "0.8.22"
seccompiler = "0.5.0"
sentry = "0.46.0"
Expand Down
2 changes: 1 addition & 1 deletion codex-rs/core/tests/suite/cli_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use wiremock::matchers::path;

fn repo_root() -> std::path::PathBuf {
#[expect(clippy::expect_used)]
find_resource!(".").expect("failed to resolve repo root")
codex_utils_cargo_bin::repo_root().expect("failed to resolve repo root")
}

fn cli_responses_fixture() -> std::path::PathBuf {
Expand Down
3 changes: 1 addition & 2 deletions codex-rs/exec/tests/suite/auth_env.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![allow(clippy::unwrap_used, clippy::expect_used)]
use codex_utils_cargo_bin::find_resource;
use core_test_support::responses::ev_completed;
use core_test_support::responses::mount_sse_once_match;
use core_test_support::responses::sse;
Expand All @@ -11,7 +10,7 @@ use wiremock::matchers::header;
async fn exec_uses_codex_api_key_env_var() -> anyhow::Result<()> {
let test = test_codex_exec();
let server = start_mock_server().await;
let repo_root = find_resource!(".")?;
let repo_root = codex_utils_cargo_bin::repo_root()?;

mount_sse_once_match(
&server,
Expand Down
2 changes: 1 addition & 1 deletion codex-rs/exec/tests/suite/resume.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ fn exec_fixture() -> anyhow::Result<std::path::PathBuf> {
}

fn exec_repo_root() -> anyhow::Result<std::path::PathBuf> {
Ok(find_resource!(".")?)
Ok(codex_utils_cargo_bin::repo_root()?)
}

#[test]
Expand Down
6 changes: 6 additions & 0 deletions codex-rs/utils/cargo-bin/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@ load("//:defs.bzl", "codex_rust_crate")
codex_rust_crate(
name = "cargo-bin",
crate_name = "codex_utils_cargo_bin",
compile_data = ["repo_root.marker"],
lib_data_extra = ["repo_root.marker"],
test_data_extra = ["repo_root.marker"],
rustc_env = {
"CODEX_REPO_ROOT_MARKER": "$(rlocationpath :repo_root.marker)",
},
)
2 changes: 1 addition & 1 deletion codex-rs/utils/cargo-bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ workspace = true

[dependencies]
assert_cmd = { workspace = true }
path-absolutize = { workspace = true }
runfiles = { workspace = true }
thiserror = { workspace = true }
20 changes: 20 additions & 0 deletions codex-rs/utils/cargo-bin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# codex-utils-cargo-bin runfiles strategy

We disable the directory-based runfiles strategy and rely on the manifest
strategy across all platforms. This avoids Windows path length issues and keeps
behavior consistent in local and remote builds on all platforms. Bazel sets
`RUNFILES_MANIFEST_FILE`, and the `codex-utils-cargo-bin` helpers use the
`runfiles` crate to resolve runfiles via that manifest.

Function behavior:
- `cargo_bin`: reads `CARGO_BIN_EXE_*` environment variables (set by Cargo or
Bazel) and resolves them via the runfiles manifest when `RUNFILES_MANIFEST_FILE`
is present. When not under runfiles, it only accepts absolute paths from
`CARGO_BIN_EXE_*` and returns an error otherwise.
- `find_resource!`: used by tests to locate fixtures. It chooses the Bazel
runfiles resolution path when `RUNFILES_MANIFEST_FILE` is set, otherwise it
falls back to a `CARGO_MANIFEST_DIR`-relative path for Cargo runs.

Background:
- https://bazel.build/docs/runfiles
- https://bazel.build/docs/runfiles#runfiles-manifest
1 change: 1 addition & 0 deletions codex-rs/utils/cargo-bin/repo_root.marker
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Loading
Loading