std.testing.refAllDeclsRecursive fails on @cImport, what can I do?

I want to use this and run it in the CI of my project to make it easier for people to make small PRs.
However it seems to fail inside the cImport of freetype:

/home/mint/Cubyz/.zig-cache/o/928e51574ef433e2a1d8184448833ac7/cimport.zig:681:5: error: dependency loop detected
pub const FT_Alloc_Func = ?*const fn (FT_Memory, c_long) callconv(.c) ?*anyopaque;
~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/mint/Cubyz/.zig-cache/o/21238c19f109f34cd7fb772eb3c2e08d/cimport.zig:2418:33: error: unable to translate macro: undefined identifier `L`
pub const __INTMAX_C_SUFFIX__ = @compileError("unable to translate macro: undefined identifier `L`");
                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/mint/Cubyz/.zig-cache/o/cfdffff4ced7fd6161a8c22e7ac29b4d/cimport.zig:755:33: error: unable to translate macro: undefined identifier `L`
pub const __INTMAX_C_SUFFIX__ = @compileError("unable to translate macro: undefined identifier `L`");
                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/mint/Cubyz/.zig-cache/o/68d665b125a2f9a9bc0a8de10bf2b83f/cimport.zig:2609:33: error: unable to translate macro: undefined identifier `L`
pub const __INTMAX_C_SUFFIX__ = @compileError("unable to translate macro: undefined identifier `L`");
                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Now I know that translate-c is rather incomplete, so this behavior is to be expected and there is not much I can do about it.

The simple solution would probably be to just modify std.testing.refAllDeclsRecursive to exclude cImports. So my question is:
How can I exclude detect and exclude cImports in Zig’s reflection? Is there some simple and reliable way to check if a struct is from a C import? If not I’d probably just exclude it by the name I gave it, but that seems rather unsatisfying.

The dependency loop detected is incorrect here, because the dependencies are pointers.

  struct FT_MemoryRec_
  {
    void*            user;
    FT_Alloc_Func    alloc;
    FT_Free_Func     free;
    FT_Realloc_Func  realloc;
  };
  typedef struct FT_MemoryRec_* FT_Memory;
  typedef void* (*FT_Alloc_Func)(FT_Memory memory, long size);

Instead of modifying std.testing.refAllDeclsRecursive you can use std.testing.refAllDecls.
To include your nested tests, redeclare their namespaces at your testing root.

1 Like