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
This commit is contained in:
Dmitriy Kovalenko
2026-10-14 22:57:03 +00:00
committed by copyberry
parent 1ffa95ee8a
commit e1e2257e29
2 changed files with 34 additions and 11 deletions
+18 -8
View File
@@ -1,5 +1,7 @@
"""Generate API artifacts with the existing Rust and Python exporters.""" """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): def _schema_bundle_impl(ctx):
outputs = [] outputs = []
for mode in ["stable", "experimental"]: for mode in ["stable", "experimental"]:
@@ -41,7 +43,7 @@ schema_bundle = rule(
doc = "Generates both schema modes as cacheable actions with explicit tool dependencies.", doc = "Generates both schema modes as cacheable actions with explicit tool dependencies.",
) )
def _schema_generator_sources_impl(ctx): def _schema_sources_impl(ctx):
sources = [] sources = []
crate_root = None crate_root = None
prefix = ctx.label.package + "/" prefix = ctx.label.package + "/"
@@ -57,22 +59,30 @@ def _schema_generator_sources_impl(ctx):
if crate_root == None: if crate_root == None:
fail("Schema generator sources must include src/lib.rs") fail("Schema generator sources must include src/lib.rs")
# The ignored generation function derives schemas from Rust. These embedded # Runtime builds embed generated bundles. The generator needs only empty
# bundles are unused on that path, so do not read the committed artifacts. # placeholders because its selected test derives the bundles from Rust.
precomputed = [ precomputed = [
ctx.actions.declare_file(ctx.label.name + "/schema/precomputed/app-server-exports-" + mode + ".json.zst") ctx.actions.declare_file(ctx.label.name + "/schema/precomputed/app-server-exports-" + mode + ".json.zst")
for mode in ["stable", "experimental"] for mode in ["stable", "experimental"]
] ]
for output in precomputed: for mode, output in zip(["stable", "experimental"], precomputed):
ctx.actions.write(output, "") 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 [ return [
DefaultInfo(files = depset(sources)), DefaultInfo(files = depset(sources)),
OutputGroupInfo(crate_root = depset([crate_root]), precomputed = depset(precomputed)), OutputGroupInfo(crate_root = depset([crate_root]), precomputed = depset(precomputed)),
] ]
schema_generator_sources = rule( schema_sources = rule(
implementation = _schema_generator_sources_impl, implementation = _schema_sources_impl,
attrs = {"srcs": attr.label_list(allow_files = [".rs"])}, attrs = {
"srcs": attr.label_list(allow_files = [".rs"]),
"schema": attr.label(providers = [OutputGroupInfo]),
},
toolchains = COPY_FILE_TOOLCHAINS,
) )
def _python_sdk_exports_impl(ctx): def _python_sdk_exports_impl(ctx):
+16 -3
View File
@@ -1,12 +1,25 @@
load("@crates//:defs.bzl", "all_crate_deps") load("@crates//:defs.bzl", "all_crate_deps")
load("@rules_rust//rust:defs.bzl", "rust_binary") load("@rules_rust//rust:defs.bzl", "rust_binary")
load("//:defs.bzl", "WINDOWS_RUSTC_LINK_FLAGS", "codex_rust_crate") 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( codex_rust_crate(
name = "app-server-protocol", name = "app-server-protocol",
compile_data = glob(["schema/precomputed/**"]), compile_data = [":schema-precomputed"],
crate_name = "codex_app_server_protocol", crate_name = "codex_app_server_protocol",
crate_srcs = [":schema-sources"],
test_data_extra = glob( test_data_extra = glob(
["schema/**"], ["schema/**"],
allow_empty = True, allow_empty = True,
@@ -21,7 +34,7 @@ alias(
visibility = ["//bazel/schema:__pkg__"], visibility = ["//bazel/schema:__pkg__"],
) )
schema_generator_sources( schema_sources(
name = "schema-generator-sources", name = "schema-generator-sources",
srcs = glob(["src/**/*.rs"]), srcs = glob(["src/**/*.rs"]),
tags = ["manual"], tags = ["manual"],