NordSecurity / uniffi-bindgen-go

Uniffi bindings generator for Golang
Mozilla Public License 2.0
75 stars 21 forks source link

Multiple crates sharing RustBufferI doesn't compile #43

Closed kegsay closed 6 months ago

kegsay commented 7 months ago

RustBufferI is defined at the package level, depending on the rust library being built. However, one library may refer to other libraries which expose uniffi types. When this happens, uniffi-bindgen-go produces multiple Go packages, one for each library. However, each package defines its own RustBufferI. This can cause the compiler to get confused and return vague sounding errors:

matrix_sdk_ffi.go:6302:3: type func(rb matrix_sdk.RustBufferI) matrix_sdk.RoomPowerLevelChanges of matrix_sdk.FfiConverterTypeRoomPowerLevelChangesINSTANCE.Lift does not match inferred type func(RustBufferI) U for func(T) U

This is saying that matrix_sdk.RustBufferI != RustBufferI so the generated code cannot compile. This is fixed by manually choosing one RustBufferI and sticking with it. uniffi-bindgen-go should handle this better, by choosing the leaf package (due to circular imports you can't always choose the main package).