jedisct1 / libsodium

A modern, portable, easy to use crypto library.
https://libsodium.org
Other
12.06k stars 1.72k forks source link

Allow other zig projects to use libsodium as a dependency #1300

Closed fjebaker closed 10 months ago

fjebaker commented 10 months ago

With the advent of the Zig Package Manager, I've made a couple of changes to the build.zig file that allows libsodium to be used as a dependency in Zig projects.

This includes adding a number of options so that the static and shared library can be built in isolation. On non-Windows OSs, the shared / static artifacts share the same name from Zig's perspective (from my naive understanding), so you get an error message about ambiguity if you try to depend on the artifact. Now, you can just pass some options to avoid that.

The options have been implemented so the default behaviour should be identical to how the build.zig script previously worked. An addendum to this is that I have explicitly made Zig include all header files in zig-out/include -- again, so downstream projects can easily depend on it.

A downstream library may unambiguously build against the shared or static library by adding the artifact to their build.zig.zon and then with e.g.

const libsodium = b.dependency(
    "libsodium",
    .{
        .target = target,
        .optimize = optimize,
        .@"test" = false, // `test` is a keyword in zig
        .static = false,
    },
);

in their build.zig.

Hope these changes are okay!

jedisct1 commented 10 months ago

Thank you! This is great!