From e1e2257e29724a54b84f58145597fd5ebea2ff70 Mon Sep 17 00:00:00 2001 From: Dmitriy Kovalenko Date: Wed, 14 Oct 2026 21:36:01 +0000 Subject: [PATCH] Embed generated app-server schema bundles in Bazel builds (#54113) ## What changed Use the stable and experimental bundles generated by `//bazel/schema:app-server` as compile-time inputs for `app-server-protocol` instead of the checked-in bundles. Generalize `schema_generator_sources` to `schema_sources` so it can stage Rust sources alongside generated bundles. Keep empty bundle placeholders for the on-demand schema generator, which derives its output from Rust sources. GitOrigin-RevId: a976c420a3698d631f3ea7c698b15b82391158e5 --- bazel/rules/schema_bundle.bzl | 26 ++++++++++++++++-------- codex-rs/app-server-protocol/BUILD.bazel | 19 ++++++++++++++--- 2 files changed, 34 insertions(+), 11 deletions(-) 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"],