From 7a0f10f403fe4b34dab62a246953620358f00e1d Mon Sep 17 00:00:00 2001 From: Lukas Kastern Date: Mon, 20 Jul 2026 22:53:37 +0200 Subject: [PATCH 1/4] 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/4] 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 3e257d0073af0fe3eafb1543608f308381b5f94d Mon Sep 17 00:00:00 2001 From: Lukas Kastern Date: Thu, 13 Aug 2026 13:59:39 +0200 Subject: [PATCH 3/4] update readme --- README.md | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index aa08d86..2891628 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 21475868166298b3c4504f7439e40ffee3901d33 Mon Sep 17 00:00:00 2001 From: Lukas Kastern Date: Thu, 13 Aug 2026 14:04:21 +0200 Subject: [PATCH 4/4] better highlighting --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2891628..148101b 100644 --- a/README.md +++ b/README.md @@ -31,14 +31,14 @@ Declare a source file that imports the C includes. For example: -src/my_ssl.c: +`src/my_ssl.c:` ```c #include "openssl/ssl.h" ... ... ``` -Convert that source file into zig using the declared translate-c dependency. +Convert that source file into zig using the declared `translate-c` dependency. ```zig // Translate my_ssl.c into zig