Modularize 2624-line generator/src/build/build.rs #56
Labels
No labels
prio_critical
prio_low
type_bug
type_contact
type_issue
type_lead
type_question
type_story
type_task
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
lhumina_code/hero_rpc#56
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
crates/generator/src/build/build.rsis a 2624-line single file handling schema parsing, six code generators (Rust types, OSIS server, RPC, OpenRPC, JS/TS, Rhai), directory creation, file emission, rustfmt invocation, and theOschemaBuilderpublic API. It is hard to extend, hard to debug, and forces every change to load the full file into context.Proposed split
Keep the public surface (
OschemaBuildConfig,OschemaBuilder) stable so service-sidebuild.rsfiles don't change. Move internals into modules undercrates/generator/src/build/:Each
emit/*.rsshould be < 400 lines and own one output target.Side benefit
Letting
fs.rsown rustfmt invocation and output-path defaults lets the service-sidebuild.rscollapse from 42 lines (currentrecipe_server/build.rs) to ~3:This is half of why the meeting asked for "smaller build.rs" — see issue body of #scaffold for the other half.
Acceptance
crates/generator/src/build/exceeds ~500 lines.recipe_serverbuilds unchanged (its current 42-linebuild.rskeeps working).build.rsshape (≤5 lines, no output-path constants) also works.cargo test -p hero_rpc_generatorstays green.Notes
Refactor only — no behaviour change. If a behaviour change is needed (e.g., to support the ≤5-line build.rs), open a follow-up referencing the codegen-alignment issue.
hero_rpc scaffold) #54Parent / context tracker: hero_skills#262 — read it before starting work on this issue. Locked decisions, reference materials, and execution order live there. Iterate via comments here; consolidation passes on the body only after feedback settles.
State refresh
Pulled latest.
crates/generator/src/build/already has some structure:mod.rs(40 lines),scaffold.rs(1208 lines) split out separately. Butbuild.rsis still 2653 lines (+29 vs my original count) — modularization not yet done.This issue is still valid as written. The split is the gentler one I proposed since the directory structure already exists. Just need to extract the per-target emitters out of
build.rsintobuild/emit/{rust_types,rust_server,rust_rpc,openrpc,js,rhai,python}.rsplusbuild/fs.rs+build/layout.rs.Adding Python emitter to the split list (per #55 comment 33682).
example/recipe_serverto end-to-end demo of new pattern #57Done in
8a8d66d(development)Split
crates/generator/src/build/build.rs(2653 LOC) into focused submodules. Public surface unchanged — recipe_server builds without modification.File layout & sizes
mod.rsconfig.rsOschemaBuildConfig,SingleBinConfig,GenerationTarget+ Default + builder methods + 2 unit testsbuilder.rsOschemaBuilder::{new, with_manifest_dir, generate}+determine_domains+ flat-layoutmod.rs/lib.rswriterserror.rsBuildError+BuildResultfs.rscollect_schema_fileslayout.rspascal_case,title_case_acronym_aware,generate_domain_mod_flat+ its unit testemit/mod.rsemit/domain.rscrate::generate::Generatoremit/bin.rsemit/rust_server.rsmod.rs+lib.rsemit/rust_sdk.rsemit/docs.rsREADME.mdindexemit/services.rssrc/services/mod.rsplaceholderAll new files are under the issue's ~500-LOC target (largest:
config.rs490,emit/bin.rs433).scaffold.rs(1208) is unchanged — out of scope per the issue.Acceptance check
build/exceeds ~500 lines (except pre-existingscaffold.rs).recipe_serverbuilds unchanged (its 42-linebuild.rskeeps working — no edits).cargo test -p hero_rpc_generatorgreen (105 passed).cargo clippy -p hero_rpc_generator --all-targetsclean (preserved theptr_argallow that was on the oldmod build).cargo build --workspacegreen.≤5-line build.rsshape — not in scope here: that needsOschemaBuildConfig::from_service_toml(), which doesn't exist yet and is part of #55 (codegen alignment +service.tomlsource-of-truth). Tracked there.Naming deviation — flag for review
The issue body proposed
emit/{rust_types,rust_rpc,openrpc,js,rhai,python}.rs— these names describe per-output-target emission. But in this crate, that code lives incrate::generate::Generator, not inbuild.rs. The build.rs file only orchestrates: it configuresGenerator, then writes the scaffolding around it (bins, server-crate mods, SDK crate, docs index).So I split along what
build.rsactually does. Emit-tree concerns map cleanly:emit/bin.rs— owns both bin shapes (per-domain + single-bin orchestrator)emit/rust_server.rs— server-crate mods (kept the name from the issue)emit/rust_sdk.rs— SDK/client crate scaffoldingemit/docs.rs,emit/services.rs,emit/domain.rs— supporting emittersPushing per-target emission out of
Generatorintoemit/{rust_types,rust_rpc,openrpc,js,rhai,python}.rswould be a much larger refactor crossing thebuild/boundary, with behaviour-change risk. The issue says "Refactor only — no behaviour change." so I leftGeneratoruntouched. If you want that bigger split, happy to open a follow-up issue.Python emitter (per #55 comment 33682) is not added here — it doesn't exist yet. That's part of #55.
Opened follow-up #58 for the deferred work — pushing per-target emission code out of
crate::generate::Generatorintobuild/emit/{rust_types,rust_rpc,openrpc,js,rhai,python}.rs, matching the original file-naming proposal here.crate::generate::Generatorper-target emission into modules #59