I am stuck for a solution for this, well not “stuck” but stuck in a non-manual override.
I am currently hitting this bug in C-Translate: Support _Atomic in translate-c · Issue #11415 · ziglang/zig · GitHub
Effectively it takes:
typedef struct zend_atomic_bool_s {
_Atomic(_Bool) value;
} zend_atomic_bool;
And just turns it into an *anyopaque:
pub const struct_zend_atomic_bool_s = opaque {};
pub const zend_atomic_bool = struct_zend_atomic_bool_s;
This is a core struct used in the same namespace, same cImport all over the place. Problem is this creates a compiler error:
/Users/josephmontanez/Documents/GitHub/zig-php-ext/.zig-cache/o/cc86f11777ca8f405ed93dfdd6763ce3/cimport.zig:28545:19: error: opaque types have unknown size and therefore cannot be directly embedded in structs
vm_interrupt: zend_atomic_bool = @import("std").mem.zeroes(zend_atomic_bool),
^~~~~~~~~~~~~~~~
/Users/josephmontanez/Documents/GitHub/zig-php-ext/.zig-cache/o/cc86f11777ca8f405ed93dfdd6763ce3/cimport.zig:28499:39: note: opaque declared here
pub const struct_zend_atomic_bool_s = opaque {};
^~~~~~~~~
I have already correct this in Zig’s cImport.zig
and it works great…
pub const struct_zend_atomic_bool_s = extern struct {
value: @import("std").atomic.Value(bool),
};
pub const zend_atomic_bool = struct_zend_atomic_bool_s;
However I must manually patch the cImport.zig file at this time. I’ve tried introducing ZIG_SKIP_ZEND_ATOMIC_BOOL
to bypass the struct completely and then tried a manual definition on my end:
const php = @cImport({
_ = @import("fixes.zig");
@cDefine("ZIG_SKIP_ZEND_ATOMIC_BOOL", "1");
@cInclude("php_config.h");
@cInclude("zend_API.h");
@cInclude("php.h");
@cInclude("ext/standard/info.h");
@cInclude("wrapper.h");
});
However the scope of fixes.zig
does not get applied to the c-translate namespace. I tried also using namespace:
const php = @cImport({
const fixes = @import("fixes.zig");
pub usingnamespace fixes;
@cDefine("ZIG_SKIP_ZEND_ATOMIC_BOOL", "1");
@cInclude("php_config.h");
@cInclude("zend_API.h");
@cInclude("php.h");
@cInclude("ext/standard/info.h");
@cInclude("wrapper.h");
});
This is not valid Zig code. I already patch the c-codebase with fixes to allow Zig to translate certain things correctly and provide work around for certain functions, but this is a low level type used all over the place and must be available in the same namespace. My last ditch effort is to disable atomic outright in the codebase as it’s already possible but I want this to be the last possible solution.