From 79c3d595d243ba728b20709e2364a8696c36c6e9 Mon Sep 17 00:00:00 2001 From: torque Date: Thu, 31 Aug 2023 22:14:27 -0700 Subject: [PATCH] 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. --- build.zig | 59 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/build.zig b/build.zig index 1dcf28d..0f3bcd2 100644 --- a/build.zig +++ b/build.zig @@ -37,6 +37,35 @@ const LibreSslLibs = struct { b.installArtifact(self.libssl); 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. @@ -208,9 +237,8 @@ pub fn libresslBuild( 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 header_search( + try libressl_libs.header_search( b, - libressl_libs.libcrypto, install_header_prefix, &.{ .{ .starts_with = "compat" }, @@ -306,33 +334,6 @@ const SkipSpec = union(enum) { 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 libcrypto_src_prefix = base_src_prefix ++ "crypto/"; const install_header_prefix = base_src_prefix ++ "include/";