UINT64_MAX (and other stdint.h types) not available in Swift

I'm calling into a C library from Swift. I ran into an issue when building on Linux:
error: cannot find 'WGPU_WHOLE_SIZE' in scope

WGPU_WHOLE_SIZE is a constant defined in the C library like so:
#define WGPU_WHOLE_SIZE UINT64_MAX

And tracing UINT64_MAX to /usr/include/stdint.h, I noticed it is defined like so:

# if __WORDSIZE == 64
#  define __INT64_C(c)  c ## L
#  define __UINT64_C(c) c ## UL
# else
#  define __INT64_C(c)  c ## LL
#  define __UINT64_C(c) c ## ULL
# endif

# define UINT64_MAX             (__UINT64_C(18446744073709551615))

My guess is that Swift cannot process this particular macro, though I'm surprised I haven't come across this issue before.

I can probably get around this by defining UINT64_MAX myself before importing the C library. But I was wondering if this is expected behavior?

It's expected that "complex" C macros aren't imported into Swift. You can use a C function, imported as a computed property by using the swift_name attribute.

// C header.
static inline uint64_t get_WGPU_WHOLE_SIZE(void)
__attribute__((swift_name("getter:WGPU_WHOLE_SIZE()"))) {
  return WGPU_WHOLE_SIZE;
}
// Swift generated interface.
public var WGPU_WHOLE_SIZE: UInt64 { get }
4 Likes