From 7a0f10f403fe4b34dab62a246953620358f00e1d Mon Sep 17 00:00:00 2001 From: Lukas Kastern Date: Mon, 20 Jul 2026 22:53:37 +0200 Subject: [PATCH 1/5] export lazy path instead of installing headers --- build.zig | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/build.zig b/build.zig index 84c4934..c1d4e07 100644 --- a/build.zig +++ b/build.zig @@ -319,6 +319,5 @@ pub fn build(b: *std.Build) !void { b.installArtifact(mod); } - // Install headers directory - should only ssl do this or crypto as well? - steps.get("ssl").?.installHeadersDirectory(upstream_root.path(b, "include"), "", .{}); + b.addNamedLazyPath("ssl_include", upstream_root.path(b, "include")); } From a9cfe6e88957c414c5f3018cfd8f1c991f58d0af Mon Sep 17 00:00:00 2001 From: Lukas Kastern Date: Mon, 20 Jul 2026 23:18:52 +0200 Subject: [PATCH 2/5] fix translate c --- patches/translate_c_pragma.patch | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 patches/translate_c_pragma.patch diff --git a/patches/translate_c_pragma.patch b/patches/translate_c_pragma.patch new file mode 100644 index 0000000..c8f0989 --- /dev/null +++ b/patches/translate_c_pragma.patch @@ -0,0 +1,13 @@ +diff --git a/include/openssl/base.h b/include/openssl/base.h +index 1ce0e1bb2..ebc058e63 100644 +--- a/include/openssl/base.h ++++ b/include/openssl/base.h +@@ -148,7 +148,7 @@ extern "C" { + // OPENSSL_GNUC_CLANG_PRAGMA emits a pragma on GCC or clang and nothing on other + // compilers. + #if defined(__GNUC__) || defined(__clang__) +-#define OPENSSL_GNUC_CLANG_PRAGMA(arg) _Pragma(arg) ++#define OPENSSL_GNUC_CLANG_PRAGMA(arg) + #else + #define OPENSSL_GNUC_CLANG_PRAGMA(arg) + #endif From 8ee7f1bf7e6abf83034e5376a4b5fa91b8d798aa Mon Sep 17 00:00:00 2001 From: Lukas Kastern Date: Mon, 10 Aug 2026 21:52:45 +0200 Subject: [PATCH 3/5] upgrade PatchStep to use an executable instead of a custom step --- build.zig | 24 +++++++++++++----------- build.zig.zon | 4 ++-- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/build.zig b/build.zig index c1d4e07..cc44e91 100644 --- a/build.zig +++ b/build.zig @@ -122,25 +122,27 @@ pub fn build(b: *std.Build) !void { const upstream = b.dependency("boringssl", .{}); - const patch_step = patch.PatchStep.create(b, .{ + var patches: std.ArrayList(std.Build.LazyPath) = .empty; + + // Add patches + const patch_dir = try build_root.openDir(b.graph.io, "patches", .{ .iterate = true }); + var iterator = patch_dir.iterate(); + while (try iterator.next(b.graph.io)) |p| { + const patch_path = try std.fmt.allocPrint(b.allocator, "patches/{s}", .{p.name}); + try patches.append(b.allocator, b.path(patch_path)); + } + + // Patch boringssl + const upstream_root = patch.PatchStep.patch(b, .{ .optimize = .ReleaseSafe, .target = b.graph.host, .root_directory = upstream.path(""), .strip = 1, + .patches = patches.items, }); const io = b.graph.io; - // Add patches - const patch_dir = try build_root.openDir(io, "patches", .{ .iterate = true }); - var iterator = patch_dir.iterate(); - while (try iterator.next(io)) |p| { - const patch_path = try std.fmt.allocPrint(b.allocator, "patches/{s}", .{p.name}); - patch_step.addPatch(b.path(patch_path)); - } - - const upstream_root = patch_step.getDirectory(); - // Grab the sources.json which tells us what to build const source_content = upstream.builder.build_root.handle.readFileAlloc( io, diff --git a/build.zig.zon b/build.zig.zon index d23dabe..8e464da 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -13,8 +13,8 @@ .hash = "nasm-3.0.1-B_NnpQpTAAA25UxvqONakXtmj-a78PGe3xfgyDFgetb0", }, .patch = .{ - .url = "git+https://github.com/akunaakwei/zig-patch.git#a5bf3778de3cae7ee7cdbaa0db3cdc3715b1bcbf", - .hash = "patch-2.6.1-po1jOY5vAABWkdNnlxzrwMOSWfjOb_RUH8tcJVPK8Mgl", + .url = "git+https://github.com/lukaskastern/patch#ee92862bd9353c351697b36d12290caff213504e", + .hash = "patch-2.6.1-po1jOaJpAABylvuBy5C6R6BZO3coh-yD6FOZqwjkFVrs", }, .googletest = .{ .url = "git+https://github.com/allyourcodebase/googletest#1c0070a093a1f4b17f0cddf5c20f3fc63681191b", From c633e6ca0b529f6d597cfe7991b8f3630b91bab1 Mon Sep 17 00:00:00 2001 From: Lukas Kastern Date: Thu, 13 Aug 2026 15:39:27 +0200 Subject: [PATCH 4/5] fix: Translate-c (#14) * export lazy path instead of installing headers * fix translate c * update readme * better highlighting --- README.md | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index aa08d86..148101b 100644 --- a/README.md +++ b/README.md @@ -12,23 +12,51 @@ zig init zig fetch --save git+https://github.com/lukaskastern/boringssl.git ``` -You can then import `boringssl` in your `build.zig` with: +You can then link `boringssl` in your `build.zig` with: ```zig const boringssl_dependency = b.dependency("boringssl", .{ .target = target, .optimize = optimize, }); -your_exe.linkLibrary(boringssl_dependency.artifact("bcm")); -your_exe.linkLibrary(boringssl_dependency.artifact("ssl")); -your_exe.linkLibrary(boringssl_dependency.artifact("crypto")); +your_module.linkLibrary(boringssl_dependency.artifact("bcm")); +your_module.linkLibrary(boringssl_dependency.artifact("ssl")); +your_module.linkLibrary(boringssl_dependency.artifact("crypto")); ``` -And use the library like this: +To use the library first declare translate-c as a dependency. +See [here](https://codeberg.org/ziglang/translate-c) for more information. + +Declare a source file that imports the C includes. + +For example: + +`src/my_ssl.c:` +```c +#include "openssl/ssl.h" +... +... +``` + +Convert that source file into zig using the declared `translate-c` dependency. + ```zig -const ssl = @cImport({ - @cInclude("openssl/ssl.h"); +// Translate my_ssl.c into zig +const Translator = @import("translate_c").Translator; +const t: Translator = .init(translate_c, .{ + .c_source_file = b.path("src/my_ssl.c"), + .target = target, + .optimize = optimize, }); +t.addIncludePath(boringssl_dependency.namedLazyPath("ssl_include")); + +your_module.addImport("boringssl", t.mod); +``` + + +And use the library like this: +```zig +const ssl = @import("boringssl"); const ctx = ssl.EVP_CIPHER_CTX_new(); ... From 631c37197af9880d09134586058188e6102faafc Mon Sep 17 00:00:00 2001 From: Lukas Kastern Date: Thu, 13 Aug 2026 19:45:33 +0200 Subject: [PATCH 5/5] update zig-patch --- build.zig | 3 ++- build.zig.zon | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/build.zig b/build.zig index cc44e91..dbbde1f 100644 --- a/build.zig +++ b/build.zig @@ -133,13 +133,14 @@ pub fn build(b: *std.Build) !void { } // Patch boringssl - const upstream_root = patch.PatchStep.patch(b, .{ + const patcher = patch.Patcher.init(b, .{ .optimize = .ReleaseSafe, .target = b.graph.host, .root_directory = upstream.path(""), .strip = 1, .patches = patches.items, }); + const upstream_root = patcher.output_directory; const io = b.graph.io; diff --git a/build.zig.zon b/build.zig.zon index 8e464da..506389a 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -13,8 +13,8 @@ .hash = "nasm-3.0.1-B_NnpQpTAAA25UxvqONakXtmj-a78PGe3xfgyDFgetb0", }, .patch = .{ - .url = "git+https://github.com/lukaskastern/patch#ee92862bd9353c351697b36d12290caff213504e", - .hash = "patch-2.6.1-po1jOaJpAABylvuBy5C6R6BZO3coh-yD6FOZqwjkFVrs", + .url = "git+https://github.com/akunaakwei/zig-patch#918b45387bb0e8afe629984faf2353fab0efab21", + .hash = "patch-2.6.1-po1jOedqAADkiQDv3hXHuQBDzGLVhCfrp38vXHB6xZ1W", }, .googletest = .{ .url = "git+https://github.com/allyourcodebase/googletest#1c0070a093a1f4b17f0cddf5c20f3fc63681191b",