-
Notifications
You must be signed in to change notification settings - Fork 0
feat(codegen): generate wasm bridge callbacks #265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pgherveou
wants to merge
76
commits into
main
Choose a base branch
from
rust-core/04-wasm-bridge-codegen
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
76 commits
Select commit
Hold shift + click to select a range
8e0e71f
feat(truapi): add testing API and versioned wiring
pgherveou dea080a
fixup! feat(truapi): add testing API and versioned wiring
pgherveou 3409152
fixup! feat(truapi): add testing API and versioned wiring
pgherveou 0569aaf
fixup! feat(truapi): add testing API and versioned wiring
pgherveou 8c93e99
feat(truapi-platform): add host capability traits
pgherveou 97d0b79
fixup! feat(truapi-platform): add host capability traits
pgherveou d2e3674
fixup! feat(truapi-platform): add host capability traits
pgherveou c6f888c
feat(truapi-codegen): emit Rust dispatcher, wire table, and host call…
pgherveou a37abae
fixup! feat(truapi-codegen): emit Rust dispatcher, wire table, and ho…
pgherveou 99d1b7e
fixup! feat(truapi-codegen): emit Rust dispatcher, wire table, and ho…
pgherveou 1c46353
fixup! feat(truapi-codegen): emit Rust dispatcher, wire table, and ho…
pgherveou 2c52262
fixup! feat(truapi-codegen): emit Rust dispatcher, wire table, and ho…
pgherveou 7bd57b8
fixup! feat(truapi-codegen): emit Rust dispatcher, wire table, and ho…
pgherveou 6964df3
feat(truapi-server): add host logic primitives
pgherveou c8c4595
fixup! feat(truapi-server): add host logic primitives
pgherveou 88cf1a9
fixup! feat(truapi-server): add host logic primitives
pgherveou 2d88bdf
fixup! feat(truapi-server): add host logic primitives
pgherveou e1f6790
feat(truapi-server): add wire and chain infrastructure
pgherveou d959726
fixup! feat(truapi-server): add wire and chain infrastructure
pgherveou fa642c1
fixup! feat(truapi-server): add host logic primitives
pgherveou 176c6b1
feat(truapi-server): add platform runtime and host bridge
pgherveou 6aa9887
fixup! feat(truapi-server): add platform runtime and host bridge
pgherveou 0f6e16c
fixup! feat(truapi-server): add platform runtime and host bridge
pgherveou 80ff2c7
fixup! feat(truapi-server): add platform runtime and host bridge
pgherveou c6091f0
fixup! feat(truapi-server): add platform runtime and host bridge
pgherveou e4d9a0d
fixup! feat(truapi-server): add wire and chain infrastructure
pgherveou 7ac562a
fixup! feat(truapi-server): add platform runtime and host bridge
pgherveou dab5395
Merge origin/main into rust-core/04-codegen
pgherveou 15e1594
Merge branch 'rust-core/04-codegen' into rust-core/04a-server-host-logic
pgherveou 54f0b20
docs(host-logic): link host-spec sections
pgherveou 2da3da5
Merge branch 'rust-core/04a-server-host-logic' into rust-core/04b-ser…
pgherveou f7b2424
Merge branch 'rust-core/04b-server-wire-chain' into rust-core/03-serv…
pgherveou ac7992f
docs(runtime): link host-spec sections
pgherveou cda27e1
fixup! feat(truapi-server): add wire and chain infrastructure
pgherveou 227f47c
Merge branch 'rust-core/04b-server-wire-chain' into rust-core/03-serv…
pgherveou 8bd9085
fixup! feat(truapi-server): add platform runtime and host bridge
pgherveou ba2571a
Merge branch 'main' into rust-core/03-server-runtime
pgherveou b804d04
fix(server): enforce runtime permissions
pgherveou f22b4b5
feat(codegen): generate wasm bridge callbacks
pgherveou 5de806e
fix(server): include runtime crate in workspace
pgherveou 460dc77
Merge branch 'rust-core/03-server-runtime' into rust-core/04-wasm-bri…
pgherveou 0d304f8
docs(server): describe permission flow
pgherveou cddce3e
Merge branch 'rust-core/03-server-runtime' into rust-core/04-wasm-bri…
pgherveou a253874
fix(codegen): satisfy wasm bridge clippy
pgherveou 1735b8a
test(server): wait for auth sync callback
pgherveou 01ddadc
Merge remote-tracking branch 'origin/rust-core/03-server-runtime' int…
pgherveou f421258
test(server): make pairing snapshot test deterministic
pgherveou 2fc5be9
Merge remote-tracking branch 'origin/rust-core/03-server-runtime' int…
pgherveou 7190552
chore(stack): move wasm bridge out of runtime layer
pgherveou c3c243b
Merge remote-tracking branch 'origin/rust-core/03-server-runtime' int…
pgherveou 5fbf0b3
fixup! feat(truapi-server): add platform runtime and host bridge
pgherveou 07a3a1c
Merge branch 'rust-core/03-server-runtime' into rust-core/04-wasm-bri…
pgherveou 95516f7
fixup! feat(truapi-server): add platform runtime and host bridge
pgherveou 9f0a7ef
Merge branch 'rust-core/03-server-runtime' into rust-core/04-wasm-bri…
pgherveou 86ffc19
fixup! feat(truapi-server): add platform runtime and host bridge
pgherveou 5f21721
Merge branch 'rust-core/03-server-runtime' into rust-core/04-wasm-bri…
pgherveou 98b1023
fixup! feat(truapi-server): add platform runtime and host bridge
pgherveou c4f7c02
Merge branch 'rust-core/03-server-runtime' into rust-core/04-wasm-bri…
pgherveou b639cb7
fixup! feat(truapi-server): add platform runtime and host bridge
pgherveou ee797ed
Merge branch 'rust-core/03-server-runtime' into rust-core/04-wasm-bri…
pgherveou 95ce2e9
fixup! feat(codegen): generate wasm bridge callbacks
pgherveou 4bdb9b5
fixup! feat(truapi-server): add platform runtime and host bridge
pgherveou 9875241
Merge branch 'rust-core/03-server-runtime' into rust-core/04-wasm-bri…
pgherveou 4fb288e
fixup! feat(codegen): generate wasm bridge callbacks
pgherveou 3a64291
refactor(platform): derive allowance Debug
pgherveou 4757653
Merge branch 'rust-core/03-server-runtime' into rust-core/04-wasm-bri…
pgherveou a99f0e5
fix(runtime): keep allowance signing in Rust
pgherveou e53b78e
Merge branch 'rust-core/03-server-runtime' into rust-core/04-wasm-bri…
pgherveou 80135ef
fix(runtime): harden pairing failures
pgherveou b24a693
Merge branch 'rust-core/03-server-runtime' into rust-core/04-wasm-bri…
pgherveou 3f775f3
fix(runtime): simplify pairing outcome
pgherveou defe071
Merge branch 'rust-core/03-server-runtime' into rust-core/04-wasm-bri…
pgherveou 3c97ceb
ci: format generated Rust codegen output
pgherveou 4132406
fixup! feat(codegen): generate wasm bridge callbacks
pgherveou 747f412
Merge remote-tracking branch 'origin/main' into rust-core/04-wasm-bri…
pgherveou f90c233
ci: install rustfmt for codegen job
pgherveou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,181 @@ | ||
| //! Shared callback naming and selection rules for generated platform bridges. | ||
|
|
||
| use std::collections::BTreeSet; | ||
|
|
||
| use crate::platform::{PlatformDefinition, PlatformInner, PlatformMethod, PlatformTrait}; | ||
| use crate::rustdoc::TypeRef; | ||
|
|
||
| pub(crate) fn composed_traits(definition: &PlatformDefinition) -> Vec<&PlatformTrait> { | ||
| let composed: BTreeSet<String> = match &definition.super_trait { | ||
| Some(s) => s.composes.iter().cloned().collect(), | ||
| None => definition.traits.iter().map(|t| t.name.clone()).collect(), | ||
| }; | ||
| definition | ||
| .traits | ||
| .iter() | ||
| .filter(|t| composed.contains(&t.name)) | ||
| .collect() | ||
| } | ||
|
|
||
| pub(crate) fn raw_callback_name(method: &PlatformMethod) -> String { | ||
| to_camel_case(&method.name) | ||
| } | ||
|
|
||
| pub(crate) fn platform_trait_names(definition: &PlatformDefinition) -> BTreeSet<String> { | ||
| definition.traits.iter().map(|t| t.name.clone()).collect() | ||
| } | ||
|
|
||
| pub(crate) fn trait_object_return_name<'a>( | ||
| method: &'a PlatformMethod, | ||
| platform_trait_names: &BTreeSet<String>, | ||
| ) -> Option<&'a str> { | ||
| match &method.return_shape.inner { | ||
| PlatformInner::TraitObject(name) => Some(name.as_str()), | ||
| PlatformInner::Result { ok, .. } | PlatformInner::Plain(ok) => { | ||
| named_platform_trait(ok, platform_trait_names) | ||
| } | ||
| PlatformInner::Unit | PlatformInner::Stream(_) => None, | ||
| } | ||
| } | ||
|
|
||
| pub(crate) fn raw_callback_wire_name( | ||
| trait_def: &PlatformTrait, | ||
| method: &PlatformMethod, | ||
| platform_trait_names: &BTreeSet<String>, | ||
| ) -> String { | ||
| let raw = raw_callback_name(method); | ||
| if trait_object_return_name(method, platform_trait_names).is_some() { | ||
| return format!( | ||
| "{}{}", | ||
| callback_namespace(&trait_def.name), | ||
| upper_first(&raw) | ||
| ); | ||
| } | ||
| raw | ||
| } | ||
|
|
||
| pub(crate) fn raw_callback_field_name( | ||
| trait_def: &PlatformTrait, | ||
| method: &PlatformMethod, | ||
| platform_trait_names: &BTreeSet<String>, | ||
| ) -> String { | ||
| snake_case(&raw_callback_wire_name( | ||
| trait_def, | ||
| method, | ||
| platform_trait_names, | ||
| )) | ||
| } | ||
|
|
||
| pub(crate) fn raw_callback_type_name( | ||
| trait_def: &PlatformTrait, | ||
| method: &PlatformMethod, | ||
| platform_trait_names: &BTreeSet<String>, | ||
| ) -> String { | ||
| upper_first(&raw_callback_wire_name( | ||
| trait_def, | ||
| method, | ||
| platform_trait_names, | ||
| )) | ||
| } | ||
|
|
||
| pub(crate) fn raw_callback_adapter_name( | ||
| trait_def: &PlatformTrait, | ||
| method: &PlatformMethod, | ||
| platform_trait_names: &BTreeSet<String>, | ||
| ) -> String { | ||
| format!( | ||
| "{}Adapter", | ||
| raw_callback_wire_name(trait_def, method, platform_trait_names) | ||
| ) | ||
| } | ||
|
|
||
| pub(crate) fn callback_namespace(trait_name: &str) -> String { | ||
| let stem = ["Provider", "Presenter", "Host"] | ||
| .into_iter() | ||
| .find_map(|suffix| trait_name.strip_suffix(suffix)) | ||
| .unwrap_or(trait_name); | ||
| lower_pascal_case(stem) | ||
| } | ||
|
|
||
| fn named_platform_trait<'a>( | ||
| ty: &'a TypeRef, | ||
| platform_trait_names: &BTreeSet<String>, | ||
| ) -> Option<&'a str> { | ||
| let TypeRef::Named { name, args } = ty else { | ||
| return None; | ||
| }; | ||
| if args.is_empty() && platform_trait_names.contains(name) { | ||
| return Some(name.as_str()); | ||
| } | ||
| None | ||
| } | ||
|
|
||
| /// Unwrap a `Result<T, E>` stream item to its `T`; other item types pass | ||
| /// through. Streams carry `Result`s on the Rust side but the JS raw bridge | ||
| /// already unwraps them before handing each item to the WASM callback sink. | ||
| pub(crate) fn stream_item(item: &TypeRef) -> &TypeRef { | ||
| if let TypeRef::Named { name, args } = item | ||
| && name == "Result" | ||
| && let Some(ok) = args.first() | ||
| { | ||
| return ok; | ||
| } | ||
| item | ||
| } | ||
|
|
||
| pub(crate) fn to_camel_case(name: &str) -> String { | ||
| let mut out = String::with_capacity(name.len()); | ||
| let mut upper_next = false; | ||
| for (idx, ch) in name.chars().enumerate() { | ||
| if ch == '_' { | ||
| upper_next = idx != 0; | ||
| continue; | ||
| } | ||
| if upper_next { | ||
| out.extend(ch.to_uppercase()); | ||
| upper_next = false; | ||
| } else { | ||
| out.push(ch); | ||
| } | ||
| } | ||
| out | ||
| } | ||
|
|
||
| fn lower_pascal_case(name: &str) -> String { | ||
| let mut chars = name.chars(); | ||
| let Some(first) = chars.next() else { | ||
| return String::new(); | ||
| }; | ||
| format!( | ||
| "{}{}", | ||
| first.to_ascii_lowercase(), | ||
| chars.collect::<String>() | ||
| ) | ||
| } | ||
|
|
||
| fn upper_first(name: &str) -> String { | ||
| let mut chars = name.chars(); | ||
| let Some(first) = chars.next() else { | ||
| return String::new(); | ||
| }; | ||
| format!( | ||
| "{}{}", | ||
| first.to_ascii_uppercase(), | ||
| chars.collect::<String>() | ||
| ) | ||
| } | ||
|
|
||
| pub(crate) fn snake_case(name: &str) -> String { | ||
| let mut out = String::with_capacity(name.len() + 4); | ||
| for (idx, ch) in name.chars().enumerate() { | ||
| if ch.is_ascii_uppercase() { | ||
| if idx != 0 { | ||
| out.push('_'); | ||
| } | ||
| out.push(ch.to_ascii_lowercase()); | ||
| } else { | ||
| out.push(ch); | ||
| } | ||
| } | ||
| out | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.