Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

Embed generated app-server schema bundles in Bazel builds (#54113)

Dmitriy Kovalenkoe1e2257e2972
diff --git a/bazel/rules/schema_bundle.bzl b/bazel/rules/schema_bundle.bzl
index 4a9e559042..38574924da 100644
--- a/bazel/rules/schema_bundle.bzl
+++ b/bazel/rules/schema_bundle.bzl
@@ -1,5 +1,7 @@
"""Generate API artifacts with the existing Rust and Python exporters."""
+load("@bazel_lib//lib:copy_file.bzl", "COPY_FILE_TOOLCHAINS", "copy_file_action")
+
def _schema_bundle_impl(ctx):
outputs = []
for mode in ["stable", "experimental"]:
@@ -41,7 +43,7 @@ schema_bundle = rule(
doc = "Generates both schema modes as cacheable actions with explicit tool dependencies.",
)
-def _schema_generator_sources_impl(ctx):
+def _schema_sources_impl(ctx):
sources = []
crate_root = None
prefix = ctx.label.package + "/"
@@ -57,22 +59,30 @@ def _schema_generator_sources_impl(ctx):
if crate_root == None:
fail("Schema generator sources must include src/lib.rs")
- # The ignored generation function derives schemas from Rust. These embedded
- # bundles are unused on that path, so do not read the committed artifacts.
+ # Runtime builds embed generated bundles. The generator needs only empty
+ # placeholders because its selected test derives the bundles from Rust.
precomputed = [
ctx.actions.declare_file(ctx.label.name + "/schema/precomputed/app-server-exports-" + mode + ".json.zst")
for mode in ["stable", "experimental"]
]
- for output in precomputed:
- ctx.actions.write(output, "")
+ for mode, output in zip(["stable", "experimental"], precomputed):
+ if ctx.attr.schema:
+ directory = getattr(ctx.attr.schema[OutputGroupInfo], mode).to_list()[0]
+ copy_file_action(ctx, directory, output, dir_path = "precomputed/" + output.basename)
+ else:
+ ctx.actions.write(output, "")
return [
DefaultInfo(files = depset(sources)),
OutputGroupInfo(crate_root = depset([crate_root]), precomputed = depset(precomputed)),
]
-schema_generator_sources = rule(
- implementation = _schema_generator_sources_impl,
- attrs = {"srcs": attr.label_list(allow_files = [".rs"])},
+schema_sources = rule(
+ implementation = _schema_sources_impl,
+ attrs = {
+ "srcs": attr.label_list(allow_files = [".rs"]),
+ "schema": attr.label(providers = [OutputGroupInfo]),
+ },
+ toolchains = COPY_FILE_TOOLCHAINS,
)
def _python_sdk_exports_impl(ctx):
diff --git a/codex-rs/app-server-protocol/BUILD.bazel b/codex-rs/app-server-protocol/BUILD.bazel
index 32ae594c77..ff23432505 100644
--- a/codex-rs/app-server-protocol/BUILD.bazel
+++ b/codex-rs/app-server-protocol/BUILD.bazel
@@ -1,12 +1,25 @@
load("@crates//:defs.bzl", "all_crate_deps")
load("@rules_rust//rust:defs.bzl", "rust_binary")
load("//:defs.bzl", "WINDOWS_RUSTC_LINK_FLAGS", "codex_rust_crate")
-load("//bazel/rules:schema_bundle.bzl", "schema_generator_sources")
+load("//bazel/rules:schema_bundle.bzl", "schema_sources")
+
+schema_sources(
+ name = "schema-sources",
+ srcs = glob(["src/**/*.rs"]),
+ schema = "//bazel/schema:app-server",
+)
+
+filegroup(
+ name = "schema-precomputed",
+ srcs = [":schema-sources"],
+ output_group = "precomputed",
+)
codex_rust_crate(
name = "app-server-protocol",
- compile_data = glob(["schema/precomputed/**"]),
+ compile_data = [":schema-precomputed"],
crate_name = "codex_app_server_protocol",
+ crate_srcs = [":schema-sources"],
test_data_extra = glob(
["schema/**"],
allow_empty = True,
@@ -21,7 +34,7 @@ alias(
visibility = ["//bazel/schema:__pkg__"],
)
-schema_generator_sources(
+schema_sources(
name = "schema-generator-sources",
srcs = glob(["src/**/*.rs"]),
tags = ["manual"],