feat(bridge-gen): configurable derives and optional client feature#3202
feat(bridge-gen): configurable derives and optional client feature#3202xsistens wants to merge 1 commit intogolemcloud:mainfrom
Conversation
64354b1 to
660586e
Compare
|
I will provide a more detailed review as well, but some preliminary comments:
|
660586e to
d4ab4c7
Compare
|
Thanks for the reply @vigoo I really appreciate this. I double checked the issue with the duplicated type definitions and it was a stupid mistake on my side, I'm sorry for bothering you with it. I removed the adjustments in this PR for this part and was able to fix it on my side. There is no rush from my side to push this in any way, we can take our time and polish it they way it's best for golems future plans. My main goal was to check with you if the general idea is reasonable and fits to your future plans, that's why I'm happy to hear that you had similar plans for the future anyway. Im not sure if I can make the required adjustments for the feature gates on my own (i just started learning rust) but I'm happy to assist where I can. |
|
I will get back to this PR after 1.5.0 (and possible include it in a patch release) |
Motivation
When consuming generated bridge SDKs from a frontend (e.g. a Dioxus fullstack app), I ran into two friction points:
The generated types can't be used without pulling in the full networking stack. All types,
IntoValue/FromValueimpls, and the client struct live in a single flat module with hard dependencies ongolem-client,golem-common, andgolem-wasm. If you only need the data types for serde on the WASM side of a fullstack app, you're forced to compile the entire Golem client stack for a target that can't use it.No way to add derives to generated types. Bridge SDK types only get
DebugandClone. In practice you almost always needPartialEqfor diffing/caching in a reactive UI, and sometimesEq/Hashfor map keys. This currently requires post-generation patching or wrapper types.Changes
Optional
clientfeature for Rust bridge SDKsThe generated
Cargo.tomlnow has a[features]section:client(default): Full networking — the agent struct,configure(),IntoValue/FromValueimpls, and all golem dependencies.serde: Only serde derives on the data types. No networking deps.The client struct,
configure(),IntoValue/FromValue, and all golem imports are gated behind#[cfg(feature = "client")]. Data type definitions (structs, enums) are always available regardless of features.This lets downstream crates do:
Configurable derive rules via
golem.yamland CLINew
additionalDerivesfield ingolem.yamlbridge SDK targets:Each rule is a regex pattern matched against type names. Matching derives are merged and deduplicated. Also available via CLI:
BridgeGeneratorConfigplumbingThe
BridgeGeneratortrait'snew()method now takes aBridgeGeneratorConfigstruct that carries the derive rules. The TypeScript generator accepts but ignores it (prefixed_config) since the feature is Rust-specific for now. Config flows from YAML parsing throughBridgeSdkTargetandCustomBridgeSdkTargetall the way to the generator.Files changed
bridge_gen/mod.rsDeriveRule,BridgeGeneratorConfigtypes; updatedBridgeGeneratortraitbridge_gen/rust/mod.rsbase_derive_attrs(), optional deps in Cargo.toml generationbridge_gen/typescript/mod.rs_configparam (no-op)app/build/gen_bridge.rsapp/context.rscommand.rs--derive-ruleCLI flagcommand_handler/bridge.rs--derive-ruleformat, pass config throughcommand_handler/mod.rsmodel/app.rsderive_ruleson target structsmodel/app_raw.rsDeriveRuleRawserde type, new YAML fieldTesting
Tested against a Dioxus 0.7 fullstack app with 7 bridge SDK agents:
features = ["client"]— full networkingdefault-features = false, features = ["serde"]— types onlyadditionalDeriveswithPartialEqon all types andEq/Hashon UUIDs — verified in generated output