buffa-build: shared_descriptor_pool with include_bytes! sidecar - #369
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
e99b93c to
8c81700
Compare
Adds buffa_build::Config::shared_descriptor_pool. buffa-build emits the shared __buffa_fds root module into the include file and writes the descriptor set once as a binary sidecar (named from the include-file stem so parallel compile() calls don't clobber) that the module include_bytes!s - keeping the bytes out of the generated Rust source entirely, on top of the cross-package dedup. - FdsEmbedding::Sidecar drives the include_bytes! path (relative or OUT_DIR) - errors without reflection, and without include_file, checked up front - feature overrides are threaded through so the shared bytes match generate's embedding (buffa-build is one process, unlike the plugin path) Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
8c81700 to
6d92c60
Compare
…pool and thread the sidecar name through validation
|
[claude code] Reviewed with the code and API-ergonomics reviewers. The mechanics are right: the sidecar path and the emitted I pushed one fixup commit (611aaae) rather than round-tripping, all doc and comment level plus two small code items:
Left for follow-ups rather than this PR: an |
iainmcgin
left a comment
There was a problem hiding this comment.
[claude code]
Approving on Iain's instruction. Sidecar path and emitted include_bytes! are driven by the same switch in both modes, the descriptor closure matches the non-shared path including feature overrides, fingerprinting needs nothing extra, and the buffa-test $OUT_DIR run proves pool identity and now byte identity across packages. 11/11 green on b8c69b9.
Part of #310. Third of the three PRs splitting that work by crate (1: the
buffa-codegenmechanism, #311, merged; 2: the plugin path, in a sibling PR).What this does
Adds
buffa_build::Config::shared_descriptor_pool(bool), thebuild.rsfront end for the mechanism #311 merged. When enabled,compile()writes the full-closureFileDescriptorSetonce as a binary sidecar next to the generated tree (<include-file-stem>.descriptor_set.binpb, via the existingwrite_if_changed) and prepends the shared__buffa_fdsroot module to the include file usingbuffa_codegen::shared_descriptor_root_modulewithFdsEmbedding::Sidecar— so the descriptor bytes never expand into Rust source at all, and every package'sdescriptor_pool()/FILE_DESCRIPTOR_SET_BYTESdelegates to the one shared copy.The sidecar's
include_bytes!form follows the samerelative_includesselection the module tree already uses (include!-relative for an explicitout_dir,concat!(env!("OUT_DIR"), ...)otherwise), so the pair always resolves together. Deriving the sidecar name from the include-file stem keeps twocompile()calls sharing anout_dirfrom clobbering each other's descriptor set.Prerequisites are validated up front with buffa-build-shaped errors: reflection must be enabled, and
include_filemust be set with a usable file-name stem (the shared module needs a tree root to live in, and the sidecar is named after the stem — a stemless name like".."would otherwise write a stray misnamed sidecar before the include-file write fails). Checks run in that order so the error names the first actually-missing prerequisite.The include file keeps its
// @generatedmarker on line 1: the shared root module is spliced between the header and theinclude!items, mirroring the packaging plugin's placement on the plugin path, so first-line generated-file detection (rustfmt's@generatedwindow, diff-collapse heuristics) keeps working on checked-in trees.Because the shared root module comes from the merged mechanism, it inherits #311's review hardening as-is: the bounded
decode_with_options(len()*64floored atDEFAULT_ELEMENT_MEMORY_LIMIT) rather than the untrusted-input default.Testing
compile()using thedescriptor_set()source (no protoc): asserts the sidecar is written with the exact encoded bytes, the include file hosts__buffa_fdsandinclude_bytes!s the sidecar rather than inlining a byte literal, and the package stitcher delegates instead of embedding its own copy.include_file, and aninclude_filewithout a file-name stem (which would otherwise write a stray misnamed sidecar before the include-file write fails).Arc::ptr_eqpool-identity evidence for exactly this embedding lives in the#[ignore]dshared_pool_tree_compiles_include_bytes_sidecarfixture merged with reflect: shared descriptor pool mechanism (opt-in) #311 (passes against this branch).$OUT_DIRmode end-to-end inbuffa-test: its build script compiles a two-package proto set withshared_descriptor_pool(true)and no explicitout_dir(so cargo's realOUT_DIRdrives both the sidecar write and the emittedconcat!(env!("OUT_DIR"), ...)reference), the crateinclude!s the result, and tests assertArc::ptr_eqpool identity across packages plus cross-package symbol resolution. This covers the composition a unit test can't safely exercise (settingOUT_DIRraces under the multithreaded test runner).Docs: the
Config::shared_descriptor_poolrustdoc names the sidecar file and the commit-it-with-a-checked-in-out_dirguidance,compile()'s# Errorslists the new rejections, and the guide's Runtime reflection section gains a shared-pool paragraph (one pool instance across packages, sidecar semantics, the set-it-uniformly caveat).