Skip to content
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

Sdk prototype #6453

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
Draft

Sdk prototype #6453

wants to merge 10 commits into from

Conversation

charlag
Copy link
Contributor

@charlag charlag commented Jan 31, 2024

@charlag
Copy link
Contributor Author

charlag commented Jan 31, 2024

It seems like we are in a pickle with wasm:

  • to load wasm reliably we need import.meta.url
  • it is only available in module context
  • we cannot run worker as a module because of Safari
  • we cannot dynamically import worker entry point because we need to set message handler right away
  • we can postpone message handling by initiating the start from the worker side but we need to build some queue until the proper startup

@charlag
Copy link
Contributor Author

charlag commented Feb 9, 2024

Results for SDK prototype in Rust:

  • on all platforms it is possible:
    • to call functions and methods on class-like objects, also async
    • to pass primitives around
    • to have error handling
    • to generate wrappers for methods & classes
  • lessons learned:
    • We need to manage lifetimes of Rust objects (read: objects with behavior/classes) for all
      targets except Swift
    • we can bundle WASM in a more automatic way than we do now but we need to change worker bootstrap a bit
    • wasm-bindgen can generate the whole npm module for us
    • wasm-bindgen doesn't have a good story for passing data structures around
      • it supports either classes with lifetimes or we have to convert data to/from JsValue
    • uniffi can be integrated into mobile app build but would probably be the best to distribute separate
      packages
    • uniffi can be described with both UDL and/or annotations, wasm-bindgen with annotations
    • uniffi and wasm-bindgen may conflict in some cases, e.g. constructor has different signatures
  • unanswered questions:
    • what is the module structure?
      • we can look at how matrix sdk works with module for cryptography and more
    • how do we facilitate passing plain objects for wasm target?
    • what is the cutoff point for Rust code?
      • Do we want idiomatic wrappers in each language or do we just provide generated mappings?
    • how do we distribute the API metadata (entities & such)
      • does it make sense to only generate them in the target language and have generic/untyped API for Rust?
        • reducing number of types that need to be bridged/converted will reduce the code size a lot
    • do we want to include both WASM & native copy of SDK for mobile apps?

@charlag charlag mentioned this pull request Feb 26, 2024
3 tasks
@charlag charlag modified the milestone: 218.240226.0 Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants