core-agent-ide/codex-rs/utils
Michael Bolin f6b563ec64
feat: introduce find_resource! macro that works with Cargo or Bazel (#8879)
To support Bazelification in https://github.com/openai/codex/pull/8875,
this PR introduces a new `find_resource!` macro that we use in place of
our existing logic in tests that looks for resources relative to the
compile-time `CARGO_MANIFEST_DIR` env var.

To make this work, we plan to add the following to all `rust_library()`
and `rust_test()` Bazel rules in the project:

```
rustc_env = {
    "BAZEL_PACKAGE": native.package_name(),
},
```

Our new `find_resource!` macro reads this value via
`option_env!("BAZEL_PACKAGE")` so that the Bazel package _of the code
using `find_resource!`_ is injected into the code expanded from the
macro. (If `find_resource()` were a function, then
`option_env!("BAZEL_PACKAGE")` would always be
`codex-rs/utils/cargo-bin`, which is not what we want.)

Note we only consider the `BAZEL_PACKAGE` value when the `RUNFILES_DIR`
environment variable is set at runtime, indicating that the test is
being run by Bazel. In this case, we have to concatenate the runtime
`RUNFILES_DIR` with the compile-time `BAZEL_PACKAGE` value to build the
path to the resource.

In testing this change, I discovered one funky edge case in
`codex-rs/exec-server/tests/common/lib.rs` where we have to _normalize_
(but not canonicalize!) the result from `find_resource!` because the
path contains a `common/..` component that does not exist on disk when
the test is run under Bazel, so it must be semantically normalized using
the [`path-absolutize`](https://crates.io/crates/path-absolutize) crate
before it is passed to `dotslash fetch`.

Because this new behavior may be non-obvious, this PR also updates
`AGENTS.md` to make humans/Codex aware that this API is preferred.
2026-01-07 18:06:08 -08:00
..
absolute-path fix: implement 'Allow this session' for apply_patch approvals (#8451) 2026-01-07 20:11:12 +00:00
cache chore: add cargo-deny configuration (#7119) 2025-11-24 12:22:18 -08:00
cargo-bin feat: introduce find_resource! macro that works with Cargo or Bazel (#8879) 2026-01-07 18:06:08 -08:00
git fix: parse git apply paths correctly (#8824) 2026-01-07 13:00:31 +00:00
image chore: add cargo-deny configuration (#7119) 2025-11-24 12:22:18 -08:00
json-to-toml chore: add cargo-deny configuration (#7119) 2025-11-24 12:22:18 -08:00
pty feat: fallback unified_exec to shell_command (#8075) 2025-12-17 10:29:45 +00:00
readiness fix: fix readiness subscribe token wrap-around (#8770) 2026-01-06 13:09:02 +00:00
string chore: add cargo-deny configuration (#7119) 2025-11-24 12:22:18 -08:00