-
Notifications
You must be signed in to change notification settings - Fork 23
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
[uniffi] Add support for custom GroupStateStorage interface #86
Conversation
@mulmarta I think this helps us not go too crazy in the short term. If we can get this to work then we can decide later if mls-rs should erase these generics or not and the change won't break this interface since they are already erased. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #86 +/- ##
==========================================
- Coverage 88.89% 88.66% -0.24%
==========================================
Files 172 174 +2
Lines 31128 31211 +83
==========================================
Hits 27672 27672
- Misses 3456 3539 +83 ☔ View full report in Codecov by Sentry. |
This will only build in async once
|
I tried using the code here from Python via #87. I got the error @mulmarta talked about:
I looked some more and the support for foreign traits (implementing a Rust trait in another language) seems very new:
(and possibly more). The second of these made me aware of a It's not clear to me what the overall state of all this is, but if I use When generate the Python bindings, class GroupStateStorage(typing.Protocol):
def state(self, group_id: "bytes"):
raise NotImplementedError
def epoch(self, group_id: "bytes", epoch_id: "int"):
raise NotImplementedError
def write(self, state: "GroupState",
epoch_inserts: "typing.List[EpochRecord]",
epoch_updates: "typing.List[EpochRecord]"):
raise NotImplementedError
def max_epoch_id(self, group_id: "bytes"):
raise NotImplementedError before it looked like this: class GroupStateStorage:
_pointer: ctypes.c_void_p
def __del__(self):
# In case of partial initialization of instances.
pointer = getattr(self, "_pointer", None)
if pointer is not None:
_rust_call(_UniffiLib.uniffi_mls_rs_uniffi_fn_free_groupstatestorage, pointer)
def _uniffi_clone_pointer(self):
return _rust_call(_UniffiLib.uniffi_mls_rs_uniffi_fn_clone_groupstatestorage, self._pointer) I can now generate a from mls_rs_uniffi import *
signature_keypair = generate_signature_keypair(CipherSuite.CURVE25519_AES128)
class PythonGroupStateStorage(GroupStateStorage):
def state(self, group_id: "bytes"):
raise NotImplementedError
def epoch(self, group_id: "bytes",epoch_id: "int"):
raise NotImplementedError
def write(self, state: "GroupState",epoch_inserts: "typing.List[EpochRecord]",epoch_updates: "typing.List[EpochRecord]"):
raise NotImplementedError
def max_epoch_id(self, group_id: "bytes"):
raise NotImplementedError
group_state_storage = PythonGroupStateStorage()
client_config = ClientConfig(group_state_storage)
client = Client(b"alice", signature_keypair, client_config) I pushed the change here: mgeisler@35b19d5. |
c7633cc
to
659ed06
Compare
Hey @mgeisler funny I was deep into looking through issues on uniffi and found the I also added async_trait in there, so if you patch in mainline uniffi it should work (I think) |
1b3bb15
1b3bb15
to
cf32ac9
Compare
The need to patch in mainline uniffi also breaks the CI. You can ignore the test for now https://github.com/awslabs/mls-rs/blob/main/mls-rs-uniffi/src/lib.rs#L594 |
@mulmarta removed the file / ignored the test for now to avoid rewriting it. Lets just wait until uniffi updates and rewrite the test based on whatever progress we make on the API in the meantime |
UniFFI added support for async traits in mozilla/uniffi-rs#1981, but this is not yet released. This commit temporarily introduces a Git dependency on UniFFI to let us test the async functionality which was removed in awslabs#86. An unrelated UniFFI change (mozilla/uniffi-rs#1840) made our existing test fail.
UniFFI added support for async traits in mozilla/uniffi-rs#1981, but this is not yet released. This commit temporarily introduces a Git dependency on UniFFI to let us test the async functionality which was removed in awslabs#86. An unrelated UniFFI change (mozilla/uniffi-rs#1840) made our existing test fail.
UniFFI added support for async traits in mozilla/uniffi-rs#1981, but this is not yet released. This commit temporarily introduces a Git dependency on UniFFI to let us test the async functionality which was removed in awslabs#86. An unrelated UniFFI change (mozilla/uniffi-rs#1840) made our existing test fail.
Issues:
#81
Description of changes:
Arc<dyn GroupStateStorage>
as input that works with uniffi and converts it into a GroupStateStorageWrapper that we can then pass to mls-rs upon configuration.Call-outs:
I am unsure if this actually works in practice yet. The code does generate for Swift, but it looks rather odd (which might just be a quirk of how uniffi handles traits more generally.
Testing:
Keeping this as a draft until someone can create a swift / kotlin / python program that proves the basic strategy is ok.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT license.