I’m trying to update the pulseaudio bindings for zig 0.15.1 where addStaticLibrary() no longer exists.
Does anyone have a guide on converting a build.zig from addStaticLibrary() to addLibrary()?
I’m trying to update the pulseaudio bindings for zig 0.15.1 where addStaticLibrary() no longer exists.
Does anyone have a guide on converting a build.zig from addStaticLibrary() to addLibrary()?
The options have a linkage that is set to static by default.
But a library has to have a .root_module?
uild.zig:8:31: error: missing struct field: root_module
const lib = b.addLibrary(.{
~^
/Users/edw/.zvm/0.15.1/lib/std/Build.zig:824:28: note: struct declared here
pub const LibraryOptions = struct {
I’m still a beginner to the build system.
Do I need to refactor the code to create a module, and then have addLibrary(.{root_module = mod}) as the final step?
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOptions(.{});
const lib = b.addLibrary(.{
.root_module = b.createModule(.{
.root_source_file = b.path("path relative to build.zig"),
.target = target,
.optimize = optimize,
}),
});
You can ofc create the module separately, especially if you want to use it for other things too.
Thanks for the help! I was able to get it working:
For future readers, you can convert like so:
// pre zig 0.14.0
const lib = b.addStaticLibrary(.{
.name = "mylib",
.target = target,
.optimize = optimize,
});
becomes:
// zig 0.15.1
const lib = b.addLibrary(.{
.linkage = .static,
.name = "mylib",
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
}),
});
Release Notes reference:
Might be worth reading this thread on the same topic as well.