build.zig: fix header search paths

These are not handled properly when used as a dependency unless they
are attached to all of the artifacts because if a user only depends on
libssl, it doesn't include the headers attached to libcrypto.
This commit is contained in:
torque 2023-08-31 22:14:27 -07:00
parent dd538e896b
commit 79c3d595d2
Signed by: torque
SSH Key Fingerprint: SHA256:nCrXefBNo6EbjNSQhv0nXmEg/VuNq3sMF5b8zETw3Tk

View File

@ -37,6 +37,35 @@ const LibreSslLibs = struct {
b.installArtifact(self.libssl); b.installArtifact(self.libssl);
b.installArtifact(self.libtls); b.installArtifact(self.libtls);
} }
pub fn header_search(
self: LibreSslLibs,
b: *std.Build,
base: []const u8,
skiplist: []const SkipSpec,
) !void {
const dir = try b.build_root.handle.openIterableDir(base, .{});
var walker = try dir.walk(b.allocator);
defer walker.deinit();
walker: while (try walker.next()) |child| {
for (skiplist) |entry| {
switch (entry) {
.starts_with => |name| if (std.mem.startsWith(u8, child.path, name)) continue :walker,
.ends_with => |name| if (std.mem.startsWith(u8, child.path, name)) continue :walker,
}
}
if (std.mem.endsWith(u8, child.basename, ".h")) {
const full = try std.mem.concat(b.allocator, u8, &.{ base, child.path });
defer b.allocator.free(full);
self.libcrypto.installHeader(full, child.path);
self.libssl.installHeader(full, child.path);
self.libtls.installHeader(full, child.path);
}
}
}
}; };
// TODO: this doesn't get cached, so it runs on every single build, which kind of sucks. // TODO: this doesn't get cached, so it runs on every single build, which kind of sucks.
@ -208,9 +237,8 @@ pub fn libresslBuild(
const include_dir = try b.build_root.handle.openDir(install_header_prefix ++ "openssl", .{}); const include_dir = try b.build_root.handle.openDir(install_header_prefix ++ "openssl", .{});
try b.build_root.handle.copyFile(header, include_dir, "opensslconf.h", .{}); try b.build_root.handle.copyFile(header, include_dir, "opensslconf.h", .{});
try header_search( try libressl_libs.header_search(
b, b,
libressl_libs.libcrypto,
install_header_prefix, install_header_prefix,
&.{ &.{
.{ .starts_with = "compat" }, .{ .starts_with = "compat" },
@ -306,33 +334,6 @@ const SkipSpec = union(enum) {
ends_with: []const u8, ends_with: []const u8,
}; };
pub fn header_search(
b: *std.Build,
lib: *std.Build.Step.Compile,
base: []const u8,
skiplist: []const SkipSpec,
) !void {
const dir = try b.build_root.handle.openIterableDir(base, .{});
var walker = try dir.walk(b.allocator);
defer walker.deinit();
walker: while (try walker.next()) |child| {
for (skiplist) |entry| {
switch (entry) {
.starts_with => |name| if (std.mem.startsWith(u8, child.path, name)) continue :walker,
.ends_with => |name| if (std.mem.startsWith(u8, child.path, name)) continue :walker,
}
}
if (std.mem.endsWith(u8, child.basename, ".h")) {
const full = try std.mem.concat(b.allocator, u8, &.{ base, child.path });
defer b.allocator.free(full);
lib.installHeader(full, child.path);
}
}
}
const base_src_prefix = "./"; const base_src_prefix = "./";
const libcrypto_src_prefix = base_src_prefix ++ "crypto/"; const libcrypto_src_prefix = base_src_prefix ++ "crypto/";
const install_header_prefix = base_src_prefix ++ "include/"; const install_header_prefix = base_src_prefix ++ "include/";