Skip to content

Commit

Permalink
Use 0.25 go bindgen; use async functions not ..Blocking() ones
Browse files Browse the repository at this point in the history
  • Loading branch information
kegsay committed Nov 13, 2023
1 parent 999da0f commit 4322609
Show file tree
Hide file tree
Showing 4 changed files with 1,400 additions and 4,118 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ Prerequisites:
This repo has bindings to the `matrix_sdk` crate in rust SDK, in order to mimic Element X.

In order to generate these bindings, follow these instructions:
- Check out https://github.com/matrix-org/matrix-rust-sdk/tree/kegan/complement-test-fork (TODO: go back to main when async fns work with bindgen)
- Get the bindings generator: (TODO: recheck if https://github.com/NordSecurity/uniffi-bindgen-go/pull/13 lands)
- Check out https://github.com/matrix-org/matrix-rust-sdk/tree/kegan/complement-test-fork (TODO: go back to main when `_ffi_matrix_sdk_ffi_rust_future_continuation_callback_set` is defined)
- Get the bindings generator: (TODO: recheck if https://github.com/NordSecurity/uniffi-bindgen-go/pull/26 lands)
```
git clone https://github.com/dignifiedquire/uniffi-bindgen-go.git
cd uniffi-bindgen-go
git checkout upgarde-uniffi-24
git checkout upgrade-uniffi-25
git submodule init
git submodule update
cd ..
Expand All @@ -104,7 +104,6 @@ cargo install uniffi-bindgen-go --path ./uniffi-bindgen-go/bindgen
- Compile the rust SDK: `cargo build -p matrix-sdk-crypto-ffi -p matrix-sdk-ffi`. Check that `target/debug/libmatrix_sdk_ffi.a` exists.
- Generate the Go bindings to `./rust`: `uniffi-bindgen-go -l ../matrix-rust-sdk/target/debug/libmatrix_sdk_ffi.a -o ./rust ../matrix-rust-sdk/bindings/matrix-sdk-ffi/src/api.udl`
- Patch up the generated code as it's not quite right:
* `sed -i '' 's/bindingsContractVersion := 23/bindingsContractVersion := 24/' rust/matrix_sdk_ffi/matrix_sdk_ffi.go`
* Add `// #cgo LDFLAGS: -lmatrix_sdk_ffi` immediately after `// #include <matrix_sdk_ffi.h>` at the top of `matrix_sdk_ffi.go`.
* Replace field names `Error` with `Error2` to fix `unknown field Error in struct literal`.
- Sanity check compile `LIBRARY_PATH="$LIBRARY_PATH:/path/to/matrix-rust-sdk/target/debug" go test -c ./tests`
Expand Down
8 changes: 4 additions & 4 deletions internal/api/rust.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ func (c *RustClient) Close(t *testing.T) {
// Tests should call stopSyncing() at the end of the test.
func (c *RustClient) StartSyncing(t *testing.T) (stopSyncing func()) {
t.Helper()
syncService, err := c.FFIClient.SyncService().FinishBlocking()
syncService, err := c.FFIClient.SyncService().Finish()
must.NotError(t, fmt.Sprintf("[%s]failed to make sync service", c.userID), err)
//c.syncService = syncService
/* ch := make(chan matrix_sdk_ffi.SyncServiceState, 10)
th := syncService.State(&syncServiceStateObserver{
ch: ch,
}) */
go syncService.StartBlocking()
go syncService.Start()

/*
isSyncing := false
Expand All @@ -102,7 +102,7 @@ func (c *RustClient) StartSyncing(t *testing.T) (stopSyncing func()) {

return func() {
t.Logf("%s: Stopping sync service", c.userID)
syncService.StopBlocking()
syncService.Stop()
}
}

Expand Down Expand Up @@ -191,7 +191,7 @@ func (c *RustClient) ensureListening(t *testing.T, roomID string) *matrix_sdk_ff

t.Logf("[%s]AddTimelineListenerBlocking[%s]", c.userID, roomID)
// we need a timeline listener before we can send messages
r.AddTimelineListenerBlocking(&timelineListener{fn: func(diff []*matrix_sdk_ffi.TimelineDiff) {
r.AddTimelineListener(&timelineListener{fn: func(diff []*matrix_sdk_ffi.TimelineDiff) {
timeline := c.rooms[roomID].timeline
for _, d := range diff {
switch d.Change() {
Expand Down
Loading

0 comments on commit 4322609

Please sign in to comment.