Skip to content
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

Generated code for Protobuf failing to build #455

Closed
sqcsabbey opened this issue May 16, 2023 · 7 comments
Closed

Generated code for Protobuf failing to build #455

sqcsabbey opened this issue May 16, 2023 · 7 comments

Comments

@sqcsabbey
Copy link

I'm getting the error message:

Error: Field 'c' requires exactly one annotation to declare its native type, which cannot be Void. dart:ffi Structs and Unions cannot have regular Dart fields.

For the ffigen'd code:

/// A union for storing all possible Protobuf values. Note that owner is
/// responsible for memory management of object types.
typedef GPBGenericValue = UnnamedUnion7;

/// A union for storing all possible Protobuf values. Note that owner is
/// responsible for memory management of object types.
final class UnnamedUnion7 extends ffi.Union {
  external BOOL1 c;

  @ffi.Int()
  external int valueInt32;

  @ffi.Int()
  external int valueInt64;

  @ffi.Int()
  external int valueUInt32;

  @ffi.Int()
  external int valueUInt64;

  @ffi.Float()
  external double valueFloat;

  @ffi.Double()
  external double valueDouble;

  external ffi.Pointer<ffi.Int> valueData;

  external ffi.Pointer<ffi.Int> valueString;

  external ffi.Pointer<ffi.Int> valueMessage;

  @ffi.Int()
  external int valueEnum;
}

I'm not using Protobuf directly, but my Podfile.lock uses Protobuf (3.23.0), and I'm trying to get this working against Dart 3.0.0 and using ffigen 8.0.2 (whatever was generated was working for me before upgrading to Dart 3 and ffigen 8).

Any tips to help me resolve this?

Thanks!

@dcharkes
Copy link
Collaborator

@sqcsabbey thanks for the report.

What is the definition of BOOL1?

(We added bool support in #310.)

@sqcsabbey
Copy link
Author

@dcharkes, thanks for responding to my report so quickly. Here's BOOL1's definition:

/// Verifies that a given value can be represented by an enum type.
typedef BOOL1 = ffi.NativeFunction<
    ffi.NativeFunction<ffi.Int Function()> Function(ffi.Pointer<ffi.Int>)>;

@dcharkes
Copy link
Collaborator

dcharkes commented May 17, 2023

We can't have a NativeFunction<...> as a field of a Union, we can only have a Pointer<NativeFunction<...>>. What is the definition of c in C/C++ that causes this to be generated?

@sqcsabbey
Copy link
Author

sqcsabbey commented May 17, 2023

Here's the header file for it, with this typedef on line 42:

/**
 * Verifies that a given value can be represented by an enum type.
 * */
typedef BOOL (*GPBEnumValidationFunc)(int32_t);

Edit: that's an Obj-C header, and from the matching comments in the ffigen'd code and this header file, I believe this is what's being used.

@dcharkes
Copy link
Collaborator

dcharkes commented May 17, 2023

/**
 * Verifies that a given value can be represented by an enum type.
 * */
typedef BOOL (*GPBEnumValidationFunc)(int32_t);

This is using BOOL and defining GPBEnumValidationFunc.

I'd hope the typedef would simply be this from https://developer.apple.com/documentation/objectivec/bool:

typedef bool BOOL;

Can you check you have got the right include paths and there are no errors on the FFIgen output?

@sqcsabbey
Copy link
Author

sqcsabbey commented May 17, 2023

I did have an error in the FFIgen output; the iOS Foundation header file wasn't found; adding this to my ffigen.yaml got it working for iOS:

compiler-opts:
  - '-F/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks'
  - '-mios-version-min=13.0'

@dcharkes
Copy link
Collaborator

Alright 👌

Please let us know if you have further issues.

@liamappelbe liamappelbe transferred this issue from dart-archive/ffigen Nov 15, 2023
parlough pushed a commit to parlough/native that referenced this issue Apr 8, 2024
* Work around analyzer bug for FfiNatives

* another pointer arg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants