For funzies and practice I’m trying to make a binding for raysan’s rini.h single header project.
Link: https://github.com/raysan5/rini
However I’m constantly running into compile errors.
C:\zig\zig versions\zig-x86_64-windows-0.16.0\lib\std\Io\Writer.zig:1077:32: error: no field or member function named 'format' in 'Build.LazyPath'
'f' => return value.format(w),
~~~~~^~~~~~~
C:\zig\zig versions\zig-x86_64-windows-0.16.0\lib\std\Build.zig:2336:22: note: union declared here
pub const LazyPath = union(enum) {
^~~~~
referenced by:
print__anon_159585: C:\zig\zig versions\zig-x86_64-windows-0.16.0\lib\std\Io\Writer.zig:719:25
allocPrint__anon_159579: C:\zig\zig versions\zig-x86_64-windows-0.16.0\lib\std\fmt.zig:633:20
10 reference(s) hidden; use '-freference-trace=12' to see all references
zig-pkg\aro-0.0.0-JSD1Qum6OgB83hmRWguTl2Z9x3rEjHWIu8f_RsMXJTTg\build.zig:248:16: error: no field or member function named 'addPassthruArgs' in 'Build.Step.Run'
run_cmd.addPassthruArgs();
~~~~~~~^~~~~~~~~~~~~~~~
C:\zig\zig versions\zig-x86_64-windows-0.16.0\lib\std\Build\Step\Run.zig:1:1: note: struct declared here
const Run = @This();
^~~~~
zig-pkg\aro-0.0.0-JSD1Qum6OgB83hmRWguTl2Z9x3rEjHWIu8f_RsMXJTTg\build.zig:248:16: note: method invocation only supports up to one level of implicit pointer dereferencing
zig-pkg\aro-0.0.0-JSD1Qum6OgB83hmRWguTl2Z9x3rEjHWIu8f_RsMXJTTg\build.zig:248:16: note: use '.*' to dereference pointer
zig-pkg\translate_c-0.0.0-Q_BUWuEVBwCbZUsNorTQ6-d3nYx8KDgHHWtVWBzgzyB5\build.zig:77:16: error: no field or member function named 'addPassthruArgs' in 'Build.Step.Run'
run_cmd.addPassthruArgs();
~~~~~~~^~~~~~~~~~~~~~~~
C:\zig\zig versions\zig-x86_64-windows-0.16.0\lib\std\Build\Step\Run.zig:1:1: note: struct declared here
const Run = @This();
^~~~~
zig-pkg\translate_c-0.0.0-Q_BUWuEVBwCbZUsNorTQ6-d3nYx8KDgHHWtVWBzgzyB5\build.zig:77:16: note: method invocation only supports up to one level of implicit pointer dereferencing
zig-pkg\translate_c-0.0.0-Q_BUWuEVBwCbZUsNorTQ6-d3nYx8KDgHHWtVWBzgzyB5\build.zig:77:16: note: use '.*' to dereference pointer
zig-pkg\translate_c-0.0.0-Q_BUWuEVBwCbZUsNorTQ6-d3nYx8KDgHHWtVWBzgzyB5\build\Translator.zig:134:48: error: union 'Build.LazyPath' has no member named 'zig_lib'
run.addPrefixedDirectoryArg("--zig-lib=", .zig_lib);
~^~~~~~~
C:\zig\zig versions\zig-x86_64-windows-0.16.0\lib\std\Build.zig:2336:22: note: union declared here
pub const LazyPath = union(enum) {
^~~~~
I also tried to clone the Translate-C repo and build the examples there but I get the same error.
Here’s my build.zig:
const std = @import("std");
const Translator = @import("translate_c").Translator;
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// Prepare the `translate-c` dependency.
const translate_c = b.dependency("translate_c", .{});
const header: Translator = .init(translate_c, .{
.c_source_file = b.path("src/rini.h"),
.target = target,
.optimize = optimize,
});
header.run.addArg("-Wno-pramga-once-outside-header");
const exe = b.addExecutable(.{
.name = "zig-rini",
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.optimize = optimize,
.target = target,
.imports = &.{
.{
.name = "c",
.module = header.mod,
},
},
.link_libc = true,
}),
});
exe.root_module.addIncludePath(b.path("src"));
b.installArtifact(exe);
}
I’m guessing the Translate-C repo is broken, but I don’t see that others have any problems with compilation. (I’m using zig 0.16.0 and tried the main and the 0.16.x branch too).
How should I tackle this problem? Or to say, how others make bindings for single header projects or C projects?