zig icon indicating copy to clipboard operation
zig copied to clipboard

liburing: unable to translate function

Open jpittis opened this issue 4 years ago • 3 comments

Ran into some "unable to translate function" errors when trying to use liburing:

./zig-cache/o/yQ6K25ocH8MNArGcIQfQgEaYDzM-vpeJWZlivEDNea4714ETWd35K3XZmZyX1Uuy/cimport.zig:1558:33: error: unable to translate function
pub const __io_uring_peek_cqe = @compileError("unable to translate function");
                                ^
./zig-cache/o/yQ6K25ocH8MNArGcIQfQgEaYDzM-vpeJWZlivEDNea4714ETWd35K3XZmZyX1Uuy/cimport.zig:1564:11: note: referenced here
    err = __io_uring_peek_cqe(ring, cqe_ptr);
          ^
./zig-cache/o/yQ6K25ocH8MNArGcIQfQgEaYDzM-vpeJWZlivEDNea4714ETWd35K3XZmZyX1Uuy/cimport.zig:1275:33: error: unable to translate function
pub const io_uring_cq_advance = @compileError("unable to translate function");
                                ^
./zig-cache/o/yQ6K25ocH8MNArGcIQfQgEaYDzM-vpeJWZlivEDNea4714ETWd35K3XZmZyX1Uuy/cimport.zig:1279:22: note: referenced here
    if (cqe != null) io_uring_cq_advance(ring, @bitCast(c_uint, @as(c_int, 1)));

To reproduce, you can add these to your build file:

lib.linkSystemLibrary("c");
lib.linkSystemLibrary("liburing");

Import liburing:

const liburing = @cImport({
  @cInclude("liburing.h");
});

And try to call liburing.io_uring_wait_cqe and or liburing.io_uring_cqe_seen.

A minimal example would likely be something along the lines of:

var ring: liburing.io_uring = undefined;
_ = liburing.io_uring_queue_init(1, &ring, 0);
var cqe: liburing.io_uring_cqe = undefined;
var ptr: ?*liburing.struct_io_uring_cqe = &cqe;
_ = liburing.io_uring_wait_cqe(&ring, &ptr);
liburing.io_uring_cqe_seen(&ring, &cqe);

Hope this is helpful.

jpittis avatar Apr 18 '20 23:04 jpittis

Note that I've been working on some uring things for the zig std lib. https://github.com/ziglang/zig/pull/3083 is the only published artifact at the moment. At some point in the current release cycle I will revisit it.

daurnimator avatar Apr 19 '20 03:04 daurnimator

Currently const c = @cImport(@cInclude("liburing.h")); works but with warning on atomics, function like io_uring_buf_ring_advance are demoted to pub extern fn but in the c code they are static inline

error when calling io_uring_buf_ring_advance in zig: error: ld.lld: undefined symbol: io_uring_buf_ring_advance

lorislibralato avatar Dec 23 '23 16:12 lorislibralato

__io_uring_peek_cqe also causes an // /usr/include/liburing.h:1245:19: warning: unable to translate function, demoted to extern.

It uses io_uring_smp_load_acquire, which uses __typeof__, which fails.

pub const io_uring_smp_load_acquire = @compileError("unable to translate macro: undefined identifier `__typeof__`"); // /usr/include/liburing/barrier.h:73:9
#define io_uring_smp_load_acquire(p)				\
	atomic_load_explicit((_Atomic __typeof__(*(p)) *)(p),	\
			     memory_order_acquire)`

__typeof__ is a compiler extension.

Edit: typeof is now a c23 standard: https://learn.microsoft.com/de-de/cpp/c-language/typeof-c?view=msvc-170

mayerraphael avatar Mar 14 '24 15:03 mayerraphael