Skip to content

Commit

Permalink
Use latest rust sdk complement-crypto branch
Browse files Browse the repository at this point in the history
  • Loading branch information
kegsay committed Feb 12, 2024
1 parent 89d9b3c commit 668a425
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 109 deletions.
3 changes: 2 additions & 1 deletion FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ cd ..
cargo install uniffi-bindgen-go --path ./uniffi-bindgen-go/bindgen
```
- Compile the rust SDK: `cargo build -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`
- **In the matrix-rust-sdk working directory**: generate the Go bindings to `../complement-crypto/internal/api/rust`: `uniffi-bindgen-go -o ../complement-crypto/internal/api/rust --library ../matrix-rust-sdk/target/debug/libmatrix_sdk_ffi.a`
- Patch up the generated code as it's not quite right:
* Add `// #cgo LDFLAGS: -lmatrix_sdk_ffi` immediately after `// #include <matrix_sdk_ffi.h>` at the top of `matrix_sdk_ffi.go`.
* Patch up the import: replace `matrix_sdk_ui` with `github.com/matrix-org/complement-crypto/internal/api/rust/matrix_sdk_ui`.
* https://github.com/NordSecurity/uniffi-bindgen-go/issues/36
- Sanity check compile `LIBRARY_PATH="$LIBRARY_PATH:/path/to/matrix-rust-sdk/target/debug" go test -c ./tests`

Expand Down
152 changes: 44 additions & 108 deletions internal/api/rust/matrix_sdk_ffi/matrix_sdk_ffi.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"sync/atomic"
"time"
"unsafe"

"github.com/matrix-org/complement-crypto/internal/api/rust/matrix_sdk_ui"

Check failure on line 20 in internal/api/rust/matrix_sdk_ffi/matrix_sdk_ffi.go

View workflow job for this annotation

GitHub Actions / Tests

no required module provides package github.com/matrix-org/complement-crypto/internal/api/rust/matrix_sdk_ui; to add it:
)

type RustBuffer = C.RustBuffer
Expand Down Expand Up @@ -1208,7 +1210,7 @@ func uniffiCheckChecksums() {
checksum := rustCall(func(uniffiStatus *C.RustCallStatus) C.uint16_t {
return C.uniffi_matrix_sdk_ffi_checksum_method_eventtimelineitem_origin(uniffiStatus)
})
if checksum != 28263 {
if checksum != 512 {
// If this happens try cleaning and rebuilding your project
panic("matrix_sdk_ffi: uniffi_matrix_sdk_ffi_checksum_method_eventtimelineitem_origin: UniFFI API checksum mismatch")
}
Expand Down Expand Up @@ -3107,7 +3109,7 @@ func uniffiCheckChecksums() {
checksum := rustCall(func(uniffiStatus *C.RustCallStatus) C.uint16_t {
return C.uniffi_matrix_sdk_ffi_checksum_method_backpaginationstatuslistener_on_update(uniffiStatus)
})
if checksum != 2582 {
if checksum != 13839 {
// If this happens try cleaning and rebuilding your project
panic("matrix_sdk_ffi: uniffi_matrix_sdk_ffi_checksum_method_backpaginationstatuslistener_on_update: UniFFI API checksum mismatch")
}
Expand Down Expand Up @@ -4929,7 +4931,7 @@ func (_self *EventTimelineItem) LocalSendState() *EventSendState {
}))
}

func (_self *EventTimelineItem) Origin() *EventItemOrigin {
func (_self *EventTimelineItem) Origin() *matrix_sdk_ui.EventItemOrigin {
_pointer := _self.ffiObject.incrementPointer("*EventTimelineItem")
defer _self.ffiObject.decrementPointer()
return FfiConverterOptionalTypeEventItemOriginINSTANCE.Lift(rustCall(func(_uniffiStatus *C.RustCallStatus) RustBufferI {
Expand Down Expand Up @@ -12378,39 +12380,6 @@ func (c FfiConverterTypeAuthenticationError) Write(writer io.Writer, value *Auth
}
}

type BackPaginationStatus uint

const (
BackPaginationStatusIdle BackPaginationStatus = 1
BackPaginationStatusPaginating BackPaginationStatus = 2
BackPaginationStatusTimelineStartReached BackPaginationStatus = 3
)

type FfiConverterTypeBackPaginationStatus struct{}

var FfiConverterTypeBackPaginationStatusINSTANCE = FfiConverterTypeBackPaginationStatus{}

func (c FfiConverterTypeBackPaginationStatus) Lift(rb RustBufferI) BackPaginationStatus {
return LiftFromRustBuffer[BackPaginationStatus](c, rb)
}

func (c FfiConverterTypeBackPaginationStatus) Lower(value BackPaginationStatus) RustBuffer {
return LowerIntoRustBuffer[BackPaginationStatus](c, value)
}
func (FfiConverterTypeBackPaginationStatus) Read(reader io.Reader) BackPaginationStatus {
id := readInt32(reader)
return BackPaginationStatus(id)
}

func (FfiConverterTypeBackPaginationStatus) Write(writer io.Writer, value BackPaginationStatus) {
writeInt32(writer, int32(value))
}

type FfiDestroyerTypeBackPaginationStatus struct{}

func (_ FfiDestroyerTypeBackPaginationStatus) Destroy(value BackPaginationStatus) {
}

type BackupState uint

const (
Expand Down Expand Up @@ -12869,39 +12838,6 @@ func (_ FfiDestroyerTypeEncryptionSystem) Destroy(value EncryptionSystem) {
value.Destroy()
}

type EventItemOrigin uint

const (
EventItemOriginLocal EventItemOrigin = 1
EventItemOriginSync EventItemOrigin = 2
EventItemOriginPagination EventItemOrigin = 3
)

type FfiConverterTypeEventItemOrigin struct{}

var FfiConverterTypeEventItemOriginINSTANCE = FfiConverterTypeEventItemOrigin{}

func (c FfiConverterTypeEventItemOrigin) Lift(rb RustBufferI) EventItemOrigin {
return LiftFromRustBuffer[EventItemOrigin](c, rb)
}

func (c FfiConverterTypeEventItemOrigin) Lower(value EventItemOrigin) RustBuffer {
return LowerIntoRustBuffer[EventItemOrigin](c, value)
}
func (FfiConverterTypeEventItemOrigin) Read(reader io.Reader) EventItemOrigin {
id := readInt32(reader)
return EventItemOrigin(id)
}

func (FfiConverterTypeEventItemOrigin) Write(writer io.Writer, value EventItemOrigin) {
writeInt32(writer, int32(value))
}

type FfiDestroyerTypeEventItemOrigin struct{}

func (_ FfiDestroyerTypeEventItemOrigin) Destroy(value EventItemOrigin) {
}

type EventSendState interface {
Destroy()
}
Expand Down Expand Up @@ -17454,7 +17390,7 @@ func (c *FfiConverterCallbackInterface[CallbackInterface]) Write(writer io.Write

// Declaration and FfiConverters for BackPaginationStatusListener Callback Interface
type BackPaginationStatusListener interface {
OnUpdate(status BackPaginationStatus)
OnUpdate(status matrix_sdk_ui.BackPaginationStatus)
}

// foreignCallbackCallbackInterfaceBackPaginationStatusListener cannot be callable be a compiled function at a same time
Expand Down Expand Up @@ -17487,7 +17423,7 @@ func matrix_sdk_ffi_cgo_BackPaginationStatusListener(handle C.uint64_t, method C

func (foreignCallbackCallbackInterfaceBackPaginationStatusListener) InvokeOnUpdate(callback BackPaginationStatusListener, args []byte, outBuf *C.RustBuffer) uniffiCallbackResult {
reader := bytes.NewReader(args)
callback.OnUpdate(FfiConverterTypeBackPaginationStatusINSTANCE.Read(reader))
callback.OnUpdate(matrix_sdk_ui.FfiConverterTypeBackPaginationStatusINSTANCE.Read(reader))

return uniffiCallbackResultSuccess
}
Expand Down Expand Up @@ -19969,43 +19905,6 @@ func (_ FfiDestroyerOptionalTypeAssetType) Destroy(value *AssetType) {
}
}

type FfiConverterOptionalTypeEventItemOrigin struct{}

var FfiConverterOptionalTypeEventItemOriginINSTANCE = FfiConverterOptionalTypeEventItemOrigin{}

func (c FfiConverterOptionalTypeEventItemOrigin) Lift(rb RustBufferI) *EventItemOrigin {
return LiftFromRustBuffer[*EventItemOrigin](c, rb)
}

func (_ FfiConverterOptionalTypeEventItemOrigin) Read(reader io.Reader) *EventItemOrigin {
if readInt8(reader) == 0 {
return nil
}
temp := FfiConverterTypeEventItemOriginINSTANCE.Read(reader)
return &temp
}

func (c FfiConverterOptionalTypeEventItemOrigin) Lower(value *EventItemOrigin) RustBuffer {
return LowerIntoRustBuffer[*EventItemOrigin](c, value)
}

func (_ FfiConverterOptionalTypeEventItemOrigin) Write(writer io.Writer, value *EventItemOrigin) {
if value == nil {
writeInt8(writer, 0)
} else {
writeInt8(writer, 1)
FfiConverterTypeEventItemOriginINSTANCE.Write(writer, *value)
}
}

type FfiDestroyerOptionalTypeEventItemOrigin struct{}

func (_ FfiDestroyerOptionalTypeEventItemOrigin) Destroy(value *EventItemOrigin) {
if value != nil {
FfiDestroyerTypeEventItemOrigin{}.Destroy(*value)
}
}

type FfiConverterOptionalTypeEventSendState struct{}

var FfiConverterOptionalTypeEventSendStateINSTANCE = FfiConverterOptionalTypeEventSendState{}
Expand Down Expand Up @@ -20561,6 +20460,43 @@ func (_ FfiDestroyerOptionalSequenceTypeRequiredState) Destroy(value *[]Required
}
}

type FfiConverterOptionalTypeEventItemOrigin struct{}

var FfiConverterOptionalTypeEventItemOriginINSTANCE = FfiConverterOptionalTypeEventItemOrigin{}

func (c FfiConverterOptionalTypeEventItemOrigin) Lift(rb RustBufferI) *matrix_sdk_ui.EventItemOrigin {
return LiftFromRustBuffer[*matrix_sdk_ui.EventItemOrigin](c, rb)
}

func (_ FfiConverterOptionalTypeEventItemOrigin) Read(reader io.Reader) *matrix_sdk_ui.EventItemOrigin {
if readInt8(reader) == 0 {
return nil
}
temp := matrix_sdk_ui.FfiConverterTypeEventItemOriginINSTANCE.Read(reader)
return &temp
}

func (c FfiConverterOptionalTypeEventItemOrigin) Lower(value *matrix_sdk_ui.EventItemOrigin) RustBuffer {
return LowerIntoRustBuffer[*matrix_sdk_ui.EventItemOrigin](c, value)
}

func (_ FfiConverterOptionalTypeEventItemOrigin) Write(writer io.Writer, value *matrix_sdk_ui.EventItemOrigin) {
if value == nil {
writeInt8(writer, 0)
} else {
writeInt8(writer, 1)
matrix_sdk_ui.FfiConverterTypeEventItemOriginINSTANCE.Write(writer, *value)
}
}

type FfiDestroyerOptionalTypeEventItemOrigin struct{}

func (_ FfiDestroyerOptionalTypeEventItemOrigin) Destroy(value *matrix_sdk_ui.EventItemOrigin) {
if value != nil {
matrix_sdk_ui.FfiDestroyerTypeEventItemOrigin{}.Destroy(*value)
}
}

type FfiConverterSequenceUint16 struct{}

var FfiConverterSequenceUint16INSTANCE = FfiConverterSequenceUint16{}
Expand Down

0 comments on commit 668a425

Please sign in to comment.