From b21f2e30815a66d96c711f4739b18e7a56e522db Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Wed, 2 Sep 2026 01:42:03 +0000 Subject: [PATCH] Add a cacheable Bazel app-server schema bundle (#42174) ## What changed - Add a `schema_bundle` rule that generates stable and experimental app-server schema directories as declared Bazel actions. - Include the pinned `zstd` executable in the bundle so consumers can normalize generated JSON without a separate `bazel run` invocation. - Expose the app-server protocol test binary as the schema generator and add the manual `//bazel/schema:public-schema-bundle` target. GitOrigin-RevId: 0a7ce47258d297dbf20db78626f2843145ee1b49 --- bazel/rules/BUILD.bazel | 1 + bazel/rules/schema_bundle.bzl | 39 ++++++++++++++++++++++++ bazel/schema/BUILD.bazel | 8 +++++ codex-rs/app-server-protocol/BUILD.bazel | 8 +++++ 4 files changed, 56 insertions(+) create mode 100644 bazel/rules/schema_bundle.bzl create mode 100644 bazel/schema/BUILD.bazel diff --git a/bazel/rules/BUILD.bazel b/bazel/rules/BUILD.bazel index 218872c73c..ab6d1f9763 100644 --- a/bazel/rules/BUILD.bazel +++ b/bazel/rules/BUILD.bazel @@ -2,4 +2,5 @@ package(default_visibility = ["//visibility:public"]) exports_files([ "e2e_benchmark.bzl", + "schema_bundle.bzl", ]) diff --git a/bazel/rules/schema_bundle.bzl b/bazel/rules/schema_bundle.bzl new file mode 100644 index 0000000000..5f8e2eae01 --- /dev/null +++ b/bazel/rules/schema_bundle.bzl @@ -0,0 +1,39 @@ +"""Cache schema generation from the filtered public Rust test executable.""" + +def _schema_bundle_impl(ctx): + outputs = [] + for mode in ["stable", "experimental"]: + schema = ctx.actions.declare_directory(ctx.label.name + "." + mode) + ctx.actions.run( + executable = ctx.executable.generator, + tools = [ctx.attr.generator[DefaultInfo].files_to_run], + arguments = [ + "--exact", + "--ignored", + "schema_fixtures_tests::write_schema_fixtures_from_env", + ], + env = { + "CODEX_APP_SERVER_SCHEMA_ROOT": schema.path, + "CODEX_APP_SERVER_SCHEMA_EXPERIMENTAL": "1" if mode == "experimental" else "0", + "RUST_MIN_STACK": "8388608", + }, + outputs = [schema], + mnemonic = "PublicSchema", + progress_message = "Generating %s public app-server schemas" % mode, + ) + outputs.append(schema) + + # Expose the pinned compressor alongside the cached directories so callers + # can normalize the JSON without a separate `bazel run` invocation. + zstd = ctx.actions.declare_file(ctx.label.name + ".zstd") + ctx.actions.symlink(output = zstd, target_file = ctx.executable.zstd, is_executable = True) + return [DefaultInfo(files = depset(outputs + [zstd]))] + +schema_bundle = rule( + implementation = _schema_bundle_impl, + attrs = { + "generator": attr.label(mandatory = True, executable = True, cfg = "exec"), + "zstd": attr.label(default = "@zstd//:zstd_cli", executable = True, cfg = "exec"), + }, + doc = "Generates both schema modes as cacheable actions with explicit tool dependencies.", +) diff --git a/bazel/schema/BUILD.bazel b/bazel/schema/BUILD.bazel new file mode 100644 index 0000000000..401d30b00f --- /dev/null +++ b/bazel/schema/BUILD.bazel @@ -0,0 +1,8 @@ +load("//bazel/rules:schema_bundle.bzl", "schema_bundle") + +schema_bundle( + name = "public-schema-bundle", + testonly = True, + generator = "//codex-rs/app-server-protocol:schema-generator", + tags = ["manual"], +) diff --git a/codex-rs/app-server-protocol/BUILD.bazel b/codex-rs/app-server-protocol/BUILD.bazel index eb6e1d280a..4ecf754479 100644 --- a/codex-rs/app-server-protocol/BUILD.bazel +++ b/codex-rs/app-server-protocol/BUILD.bazel @@ -9,3 +9,11 @@ codex_rust_crate( allow_empty = True, ), ) + +alias( + name = "schema-generator", + testonly = True, + actual = ":app-server-protocol-unit-tests-bin", + tags = ["manual"], + visibility = ["//bazel/schema:__pkg__"], +)