jhugman / uniffi-bindgen-react-native

A uniffi bindings generator for calling Rust from react-native
Other
0 stars 0 forks source link

Additional sub-packages are not being registered, causing runtime issues #69

Closed zzorba closed 1 week ago

zzorba commented 3 weeks ago

We got a problem where a uniffi symbol from the MatrixSdkFFI (a dependency of Diode) was getting an undefined error at runtime.

Looking at the generated rn-diode.cpp file (which does registrations) is only registering the top level module:

Here is the generated file as is:

// Generated by uniffi-bindgen-react-native
#include "rn-diode.h"
#include "generated/diode.hpp"

namespace rndiode
{
  using namespace facebook;

  // TODO Remove `multiply` after seeing this work on iOS and Android.
  double multiply(double a, double b)
  {
    return a * b;
  }

  uint8_t installRustCrate(jsi::Runtime &runtime, std::shared_ptr<react::CallInvoker> callInvoker)
  {
    NativeDiode::registerModule(runtime, callInvoker);
    return false;
  }

  uint8_t cleanupRustCrate(jsi::Runtime &runtime, uint8_t b)
  {
    return false;
  }
}

But in the cpp folder, there are lots of other hpp/cpp pairs that each have their own static registerModule method that is not being called (as far as I can tell).

We tried manually editing rn-diode.cpp to include the matrix_sdk_ffi.hpp and call NativeMatrixSdkFfi::registerModule, and it seemed to resolve Wes's issue.

zzorba commented 3 weeks ago

User error, we have to add these to our turbo-modules command as additional packages.

zzorba commented 3 weeks ago

Actually, it looks like if you specify the package names with - instead of _, it produces invalid c++ code:

zzorba commented 3 weeks ago

Looks like a normalize step was missed here to turn them into _ names that match the .hpp files. If you specify matrix-sdk-ffi it produces this, instead of the expected matrix_sdk_ffi.hpp

#include "rn-diode.h"
#include "generated/diode.hpp"
#include "generated/matrix-sdk-ffi.hpp"
#include "generated/matrix-sdk-ui.hpp"
#include "generated/matrix-sdk-crypto.hpp"
#include "generated/matrix-sdk-base.hpp"
#include "generated/matrix-sdk.hpp"
jhugman commented 3 weeks ago

I added #71 in response to this issue, making it easier to generate these files with the correct inputs.