#is zig abi stable with the same compiler

1 messages · Page 1 of 1 (latest)

crisp saddle
#

Suppose I have a program A written in zig, it dynamically loads dyn lib B written in zig. Both are compiled with the same flags and the same compiler. Will program A and B have the same ABI? Is it possible for some of the structs have different memory layout, or some function call mismatch?

dry yacht
#

while it may work in some cases you should not expect it to work.

For example in the future there are plans to randomize struct layouts in debug mode.

If you need ABI compatability use the c abi with extern structs and functions or your own serde

vast cove
#

no, Zig doesn't guarantee ABI stability across compilation even when using the same compiler, in practice, I don't think it actively swaps fields around to discourage relying on ABI stability

dry yacht
#

%%4336 like I noted it is planned

crisp saddle
crisp saddle
#

having to copy stuff over C ABI boundary is kind of annoying

wanton crown
#

don't have to copy if the shared/base state is defined as extern struct, instead of it being just a data transfer channel

neon saffron
# crisp saddle i wonder why not add stable abi at least with the same compiler

Because having a stable abi is an insane burden, and could lead to massive issues when they want to fix something, but can't modify the ABI. I think very few of the people asking for a stable ABI understand how hard it is to have a good stable ABI. And the biggest issue then is that you can't make it better, because that'd make it unstable.

wanton crown
#

you'd just end up with yet another flawed, C like ABI

crisp saddle
crisp saddle
wanton crown
crisp saddle
#

maybe you can use comptime to generate extern struct

weary forge