Skip to content

Port over vezel/libffi zig package - #1

Merged
Tomcat-42 merged 2 commits into
allyourcodebase:mainfrom
Techatrix:port-vezel-libffi
Aug 31, 2026
Merged

Port over vezel/libffi zig package#1
Tomcat-42 merged 2 commits into
allyourcodebase:mainfrom
Techatrix:port-vezel-libffi

Conversation

@Techatrix

Copy link
Copy Markdown
Member

This PR ports over https://codeberg.org/vezel/libffi which is also packages libffi for Zig. It has been maintained by alexrp, a ZSF core team member which as has extensive knowledge in compilation target support. Unfortunately, this fork is no longer maintained so I'm hoping to revive it in the allyourcodebase organization.

I have tested this port with https://github.com/allyourcodebase/tracy which depends on https://github.com/allyourcodebase/wayland and therefore libffi.

Techatrix and others added 2 commits August 17, 2026 19:58
Co-authored-by: Alex Rønne Petersen <alex@alexrp.com>
@Techatrix

Copy link
Copy Markdown
Member Author

@Tomcat-42

@Tomcat-42

Copy link
Copy Markdown
Collaborator

Hi @Techatrix, thanks for the patch. One thing, I will merge this and point a 0.16 branch to HEAD, and then commit:

diff --git a/build.zig b/build.zig
index e393ccd..ce29cb4 100644
--- a/build.zig
+++ b/build.zig
@@ -209,8 +209,8 @@ pub fn build(b: *std.Build) !void {
     inline for (.{ "include", "src", b.pathJoin(&.{ "src", arch_name }) }) |inc|
         mod.addIncludePath(upstream.path(inc));
 
-    const double_size = t.cTypeByteSize(.double);
-    const long_double_size = t.cTypeByteSize(.longdouble);
+    const double_size = t.cTypeByteSize(.double).?;
+    const long_double_size = t.cTypeByteSize(.longdouble).?;
 
     const long_double_variant = switch (t.os.tag) {
         .freebsd, .netbsd, .openbsd => t.cpu.arch == .powerpc,

on top. It is ok for you? I was long wanting to separate the master and 0.xx branch for bindings repos like this.

@Tomcat-42

Copy link
Copy Markdown
Collaborator

Also thanks for the patch, this repo was in need of a little housekeeping

@Techatrix

Copy link
Copy Markdown
Member Author

You can also keep a single branch and check whether cTypeByteSize will need to be unwrapped at comptime:

diff --git a/build.zig b/build.zig
index e393ccd..b101896 100644
--- a/build.zig
+++ b/build.zig
@@ -209,8 +209,11 @@ pub fn build(b: *std.Build) !void {
     inline for (.{ "include", "src", b.pathJoin(&.{ "src", arch_name }) }) |inc|
         mod.addIncludePath(upstream.path(inc));
 
-    const double_size = t.cTypeByteSize(.double);
-    const long_double_size = t.cTypeByteSize(.longdouble);
+    // the `is_c_byte_size_optional` check can be removed when targetting 0.17.0+
+    comptime std.debug.assert((std.SemanticVersion.parse(manifest.minimum_zig_version) catch unreachable).minor < 17);
+    const is_c_byte_size_optional = @typeInfo(@typeInfo(@TypeOf(std.Target.cTypeBitSize)).@"fn".return_type.?) == .optional;
+    const double_size = if (is_c_byte_size_optional) t.cTypeByteSize(.double).? else t.cTypeByteSize(.double);
+    const long_double_size = if (is_c_byte_size_optional) t.cTypeByteSize(.longdouble).? else t.cTypeByteSize(.longdouble);
 
     const long_double_variant = switch (t.os.tag) {
         .freebsd, .netbsd, .openbsd => t.cpu.arch == .powerpc,

@Tomcat-42
Tomcat-42 merged commit 29f3c29 into allyourcodebase:main Aug 31, 2026
8 checks passed
@Techatrix
Techatrix deleted the port-vezel-libffi branch August 31, 2026 00:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants