Drop types_wasm_generated.rs — fold WASM-compat into types_generated.rs via cfg #74
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#74
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
The scaffolder emits a duplicate types file at
crates/<name>/src/<domain>/types_wasm_generated.rsfor WASM-target compatibility. Two parallel definitions of the same types is the wrong shape: native code and WASM code both want the sameRecipe/User/ServiceDefinitionstructs.What to do
types_generated.rsusing#[cfg(target_arch = "wasm32")](and the inverse) blocks where the shapes genuinely diverge — but only for the fields/methods that need to differ.cfgis needed; remove the duplication.types_wasm_generated.rsemission.--target wasm32-unknown-unknownbuilds compile.Acceptance
types_generated.rsper domain, not two.cargo buildclean on native.cargo build --target wasm32-unknown-unknown -p <name>clean (or unchanged from prior behaviour if the build was already supported).Implemented on
lab/74-fold-wasm-types(compare).Approach
Added
generate_unified_rust_structsincrates/generator/src/rust/rust_struct.rs. It builds both per-typedef outputs (via the existing native and wasm generators) and:cfggating when the two outputs are byte-identical (the common case — enums, embedded structs);#[cfg(target_arch = "wasm32")]/ its inverse, only when the shapes genuinely diverge (root objects: native addsOsisObjectderive + injectedsid: SmartId/created_at: u64/updated_at: u64; wasm keeps the schema fields as declared);OTime,OCur,OLocation,OAddress) in a gated__wasm_otomlsubmodule;hero_rpc_osis::otoml::*/OsisObjectimports.crates/generator/src/generate/rust_types.rsnow calls the unified emitter once per domain instead of emitting two parallel files, and cleans up any staletypes_wasm_generated.rsleft over from prior scaffold runs. The flat-layoutmod.rs(build/layout.rs) and the per-domainmod.rslose their target-arch branches —types.rsincludes the unified file unconditionally and the cfg gating lives inside the generated file itself.generate_rust_wasm_structsis kept (still used by the SDK and rpc2 trait emit paths inbuild/emit/rust_sdk.rsandbuild/emit/rust_rpc2.rs, which want a fully self-contained types file for separate WASM-targeted SDK crates).Verification
rust_struct.rs::testscovering the dedup and the root-object cfg gating).cargo build -p hero_recipes(native): clean; only pre-existing unused-import warning unchanged from prior behaviour.cargo build -p hero_recipes_sdk --target wasm32-unknown-unknown: clean.types_generated.rsin an isolated crate: clean.hero_recipesitself does not build for wasm32 due to its tokio/runtime deps — same as prior behaviour, the cfg-gated types module compiles fine in isolation.Acceptance
types_generated.rsper domain — verified via the regeneratedexample/recipe_server/crates/hero_recipes/src/recipes/(committed inaad13ff).cargo buildclean on native.cargo build --target wasm32-unknown-unknownclean against the unified types file.Ready for review.