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(); ... 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")); } 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