Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

Preserve Cargo package names in Bazel Rust builds (#51847)

Dmitriy Kovalenko6ea82c59c63f
diff --git a/defs.bzl b/defs.bzl
index a3bf72185d..8d1b1a378f 100644
--- a/defs.bzl
+++ b/defs.bzl
@@ -299,8 +299,10 @@ def codex_rust_crate(
visibility = ["//visibility:public"],
)
+ package_data = DEP_DATA.get(native.package_name())
rustc_env = {
"BAZEL_PACKAGE": native.package_name(),
+ "CARGO_PKG_NAME": package_data["package_name"],
} | rustc_env
manifest_relpath = native.package_name()
@@ -308,7 +310,6 @@ def codex_rust_crate(
manifest_relpath = manifest_relpath[len("codex-rs/"):]
manifest_path = manifest_relpath + "/Cargo.toml"
- package_data = DEP_DATA.get(native.package_name())
crate_version = package_data["version"]
binaries = package_data["binaries"]
@@ -319,6 +320,7 @@ def codex_rust_crate(
if build_script_enabled and native.glob(["build.rs"], allow_empty = True):
cargo_build_script(
name = name + "-build-script",
+ pkg_name = package_data["package_name"],
srcs = ["build.rs"],
deps = all_crate_deps(build = True),
data = build_script_data,
@@ -416,6 +418,7 @@ def codex_rust_crate(
# generated rust_binary instead of leaking it to sibling binaries.
compile_data = binary_compile_data_extra.get(binary, []),
rustc_flags = rustc_flags_extra + binary_rustc_flags_extra.get(binary, []) + WINDOWS_RUSTC_LINK_FLAGS,
+ rustc_env = rustc_env,
# Keep stamp = 0: rules_rust otherwise makes stable-status.txt and
# volatile-status.txt compiler inputs, even though we only consume
# STABLE_GIT_COMMIT. BUILD_USER and BUILD_HOST vary across developers
diff --git a/patches/rules_rs_workspace_package_version.patch b/patches/rules_rs_workspace_package_version.patch
index 909637afdc..e55b838a8e 100644
--- a/patches/rules_rs_workspace_package_version.patch
+++ b/patches/rules_rs_workspace_package_version.patch
@@ -1,14 +1,15 @@
-# What: expose resolved Cargo workspace package versions in DEP_DATA.
+# What: expose resolved Cargo workspace package names and versions in DEP_DATA.
# Scope: rules_rs workspace metadata only.
diff --git a/rs/private/cargo_workspace_graph.bzl b/rs/private/cargo_workspace_graph.bzl
--- a/rs/private/cargo_workspace_graph.bzl
+++ b/rs/private/cargo_workspace_graph.bzl
-@@ -762,6 +762,7 @@ def workspace_dep_data(
+@@ -762,6 +762,8 @@ def workspace_dep_data(
"deps": deps,
"deps_by_platform": deps_by_platform,
"dev_deps": dev_deps,
"dev_deps_by_platform": dev_deps_by_platform,
++ "package_name": package["name"],
"shared_libraries": shared_libraries,
+ "version": package["version"],
}
diff --git a/scripts/codex_package/smoke_tests/test_codex_package.py b/scripts/codex_package/smoke_tests/test_codex_package.py
index 8ce57ea4c0..46df0c3cc3 100644
--- a/scripts/codex_package/smoke_tests/test_codex_package.py
+++ b/scripts/codex_package/smoke_tests/test_codex_package.py
@@ -22,6 +22,7 @@ import json
import shutil
import subprocess
import sys
+import tomllib
from pathlib import Path
import pytest
@@ -40,7 +41,6 @@ from fixtures import SmokePackage
("arguments", "expected"),
[
pytest.param(("--help",), "Usage:", id="help"),
- pytest.param(("--version",), None, id="version"),
pytest.param(("features", "list"), "code_mode", id="features"),
pytest.param(("completion", "bash"), "codex", id="completion"),
],
@@ -48,11 +48,23 @@ from fixtures import SmokePackage
def test_cli_public_commands(
package: SmokePackage,
arguments: tuple[str, ...],
- expected: str | None,
+ expected: str,
) -> None:
- """Packaged CLI remains usable for discovery, version, features, and completions."""
+ """Packaged CLI remains usable for discovery, features, and completions."""
output = package.run(*arguments).stdout
- assert expected in output if expected is not None else output.strip()
+ assert expected in output
+
+
+def test_cli_version_matches_release_sources(package: SmokePackage) -> None:
+ """Verify the compiled banner against the sources used to package the release."""
+ root = next(
+ parent
+ for parent in Path(__file__).resolve().parents
+ if (parent / "codex-rs/Cargo.toml").is_file()
+ )
+ manifest = tomllib.loads((root / "codex-rs/Cargo.toml").read_text())
+ version = manifest["workspace"]["package"]["version"]
+ assert package.run("--version").stdout == f"codex-cli {version}\n"
@pytest.mark.parametrize("entrypoint", ["codex", "codex-app-server"])