diff --git a/defs.bzl b/defs.bzl index 7c89a05aea..315328e72b 100644 --- a/defs.bzl +++ b/defs.bzl @@ -84,6 +84,11 @@ def codex_rust_crate( "INSTA_SNAPSHOT_PATH": "src", } + cargo_like_package = native.package_name() + if cargo_like_package.startswith("codex-rs/"): + cargo_like_package = cargo_like_package[len("codex-rs/"):] + snapshot_path_remap = "--remap-path-prefix=%s=%s" % (native.package_name(), cargo_like_package) + rustc_env = { "BAZEL_PACKAGE": native.package_name(), } | rustc_env @@ -128,8 +133,8 @@ def codex_rust_crate( env = test_env, deps = all_crate_deps(normal = True, normal_dev = True) + maybe_deps + deps_extra, # Keep `file!()` paths Cargo-like (`core/src/...`) instead of - # Bazel workspace-prefixed (`codex-rs/core/src/...`) for snapshot parity. - rustc_flags = rustc_flags_extra + ["--remap-path-prefix=codex-rs="], + # Bazel package-prefixed (`codex-rs/core/src/...`) for snapshot parity. + rustc_flags = rustc_flags_extra + [snapshot_path_remap], rustc_env = rustc_env, data = test_data_extra, tags = test_tags, @@ -176,8 +181,8 @@ def codex_rust_crate( compile_data = native.glob(["tests/**"], allow_empty = True) + integration_compile_data_extra, deps = all_crate_deps(normal = True, normal_dev = True) + maybe_deps + deps_extra, # Keep `file!()` paths Cargo-like (`core/tests/...`) instead of - # Bazel workspace-prefixed (`codex-rs/core/tests/...`) for snapshot parity. - rustc_flags = rustc_flags_extra + ["--remap-path-prefix=codex-rs="], + # Bazel package-prefixed (`codex-rs/core/tests/...`) for snapshot parity. + rustc_flags = rustc_flags_extra + [snapshot_path_remap], rustc_env = rustc_env, # Important: do not merge `test_env` here. Its unit-test-only # `INSTA_WORKSPACE_ROOT="codex-rs"` can point integration tests at the