Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

Propagate Cargo package versions to Bazel Rust targets (#49074)

Tamir Duberstein22d1d9336f75
diff --git a/MODULE.bazel b/MODULE.bazel
index 001bb19ff7..e1a6a7ff05 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -191,6 +191,7 @@ single_version_override(
"//patches:rules_rs_build_script_deps_annotation.patch",
"//patches:rules_rs_rust_debug_modes.patch",
"//patches:rules_rs_windows_msvc_linker.patch",
+ "//patches:rules_rs_workspace_package_version.patch",
"//patches:rules_rs_zlib_snapshot_urls.patch",
],
version = "0.0.96",
diff --git a/defs.bzl b/defs.bzl
index 7aaf9ac0a9..a3bf72185d 100644
--- a/defs.bzl
+++ b/defs.bzl
@@ -308,7 +308,9 @@ def codex_rust_crate(
manifest_relpath = manifest_relpath[len("codex-rs/"):]
manifest_path = manifest_relpath + "/Cargo.toml"
- binaries = DEP_DATA.get(native.package_name())["binaries"]
+ package_data = DEP_DATA.get(native.package_name())
+ crate_version = package_data["version"]
+ binaries = package_data["binaries"]
lib_srcs = crate_srcs if crate_srcs != None else native.glob(["src/**/*.rs"], exclude = binaries.values(), allow_empty = True)
@@ -320,8 +322,7 @@ def codex_rust_crate(
srcs = ["build.rs"],
deps = all_crate_deps(build = True),
data = build_script_data,
- # Some build script deps sniff version-related env vars...
- version = "0.0.0",
+ version = crate_version,
)
maybe_deps += [name + "-build-script"]
@@ -340,6 +341,7 @@ def codex_rust_crate(
rustc_flags = rustc_flags_extra,
rustc_env = rustc_env,
rustc_env_files = rustc_env_files,
+ version = crate_version,
visibility = ["//visibility:public"],
)
@@ -369,6 +371,7 @@ def codex_rust_crate(
rustc_env = rustc_env,
data = test_data_extra + [binary for binary in extra_binaries if binary not in test_data_extra],
tags = test_tags + ["manual"],
+ version = crate_version,
)
unit_test_kwargs = {}
@@ -423,6 +426,7 @@ def codex_rust_crate(
rustc_env_files = ["//bazel/build-info:build-commit-env"] if binary in binaries_with_build_commit else [],
srcs = native.glob(["src/**/*.rs"]),
stamp = 0,
+ version = crate_version,
visibility = ["//visibility:public"],
)
@@ -444,6 +448,7 @@ def codex_rust_crate(
rustc_env = rustc_env,
data = test_data_extra,
tags = test_tags + ["manual"],
+ version = crate_version,
)
binary_unit_test_kwargs = {}
@@ -575,6 +580,7 @@ def codex_rust_crate(
rustc_env = rustc_env,
target_compatible_with = WINDOWS_GNULLVM_INCOMPATIBLE,
tags = test_tags + ["manual"],
+ version = crate_version,
)
workspace_root_test(
@@ -616,6 +622,7 @@ def codex_rust_crate(
env = integration_test_cargo_env,
target_compatible_with = WINDOWS_GNULLVM_INCOMPATIBLE,
tags = test_tags,
+ version = crate_version,
**test_kwargs
)
@@ -688,6 +695,7 @@ def codex_rust_crate(
env = integration_test_cargo_env,
target_compatible_with = WINDOWS_GNULLVM_ONLY,
tags = test_tags + ["manual"],
+ version = crate_version,
)
workspace_root_test(
diff --git a/patches/BUILD.bazel b/patches/BUILD.bazel
index 65ee3581df..6fd6aded05 100644
--- a/patches/BUILD.bazel
+++ b/patches/BUILD.bazel
@@ -17,6 +17,7 @@ exports_files([
"rules_rs_build_script_deps_annotation.patch",
"rules_rs_rust_debug_modes.patch",
"rules_rs_windows_msvc_linker.patch",
+ "rules_rs_workspace_package_version.patch",
"rules_rs_zlib_snapshot_urls.patch",
"rusty_v8_prebuilt_out_dir.patch",
"ring_windows_msvc_include_dirs.patch",
diff --git a/patches/rules_rs_workspace_package_version.patch b/patches/rules_rs_workspace_package_version.patch
new file mode 100644
index 0000000000..909637afdc
--- /dev/null
+++ b/patches/rules_rs_workspace_package_version.patch
@@ -0,0 +1,14 @@
+# What: expose resolved Cargo workspace package 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(
+ "deps": deps,
+ "deps_by_platform": deps_by_platform,
+ "dev_deps": dev_deps,
+ "dev_deps_by_platform": dev_deps_by_platform,
+ "shared_libraries": shared_libraries,
++ "version": package["version"],
+ }