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

liburing: unable to translate function #5101

Open
jpittis opened this issue Apr 18, 2020 · 3 comments
Open

liburing: unable to translate function #5101

jpittis opened this issue Apr 18, 2020 · 3 comments
Labels
translate-c C to Zig source translation feature (@cImport)
Milestone

Comments

@jpittis
Copy link

jpittis commented Apr 18, 2020

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.

@daurnimator daurnimator added the translate-c C to Zig source translation feature (@cImport) label Apr 19, 2020
@daurnimator
Copy link
Contributor

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

@Vexu Vexu added this to the 0.7.0 milestone Apr 19, 2020
@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Aug 13, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.10.0 May 19, 2021
@lorislibralato
Copy link
Contributor

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

@mayerraphael
Copy link

mayerraphael commented Mar 14, 2024

__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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
translate-c C to Zig source translation feature (@cImport)
Projects
None yet
Development

No branches or pull requests

6 participants