Okay, let me rephrase the whole thing -
I wanted to create a simple library project (which builds perfectly fine with zig build
), accessible via Zig package manager, and a simple project using this library (i call it zsp-user-01
):
.dependencies =
.{
.zigStructPrint =
.{
.url = "https://github.com/Durobot/zigStructPrint/archive/9ced743d434527147a9a61cf11c3db33201f24a3.tar.gz",
.hash = "1220ca283c7e4240adbf9dfa31f7894818efc93ce54300521dad777a2670e9674dd8",
}
},
and in build.zig
:
// --- in your build.zig's build function, add the following before b.installArtifact(exe): ---
const zsp = b.dependency("zigStructPrint",
.{
.target = target,
.optimize = optimize,
.openssl = false, // set to true to enable TLS support
});
exe.root_module.addImport("zigStructPrint", zsp.module("zigStructPrint"));
// --- ---
But I’m getting this error when I try to zig build
zsp-user-01:
$ zig build
error: invalid option: -Dopenssl
/home/archie/apps/zig/lib/std/Build.zig:1873:35: 0x1143249 in dependency__anon_16347 (build)
return dependencyInner(b, name, pkg.build_root, if (@hasDecl(pkg, "build_zig")) pkg.build_zig else null, pkg.deps, args);
^
/home/archie/projects/zig-playground/zsp-user-01/build.zig:43:29: 0x10fa2aa in build (build)
const zsp = b.dependency("zigStructPrint",
^
/home/archie/apps/zig/lib/std/Build.zig:1992:33: 0x10d60e3 in runBuild__anon_8908 (build)
.Void => build_zig.build(b),
^
Could it be because I don’t have call b.addModule
in zigStructPrint’s build.zig
?
I have tried adding this call to zigStructPrint’s fn build
, just before calling b.addStaticLibrary
:
_ = b.addModule("zigStructPrint", // package_name
.{
.root_source_file = .{ .path = "src/root.zig" },
.target = target,
.optimize = optimize,
});
And, since I didn’t want to push this change to github without testing it, I have downloaded zigStructPrint’s tarball, replaced build.zig within with the modified version, replaced .url
in with
.url = "file:///home/.../zsp-user-01/9ced743d434527147a9a61cf11c3db33201f24a3.tar.gz",
fixed the hash, cleared Zig cache both in the project folder and my home folder, …and I’m still getting this error:
$ zig build
error: invalid option: -Dopenssl
/home/archie/.night.zig/zig-linux-x86_64-0.12.0-dev.3123+147beec7d/lib/std/Build.zig:1873:35: 0x1143eb9 in dependency__anon_16347 (build)
return dependencyInner(b, name, pkg.build_root, if (@hasDecl(pkg, "build_zig")) pkg.build_zig else null, pkg.deps, args);
^
/home/archie/projects/zig-playground/zsp-user-01/build.zig:43:29: 0x10fab0c in build (build)
const zsp = b.dependency("zigStructPrint",
^
I could swear I’ve seen different errors before.
So, long story short, could somebody please point me to a simple pair of Zig projects, a library that is accessible via Zig package manager, and a project using that library?