Hey everyone - it’s been a while and I hope all is well
I’ve been building a lot of C-Libraries lately and I’ve found one that is puzzling. I want to wrap tlse
in a zig library for some backwards compatibility with TLS 1.2 but I keep running into roadblocks with this one. I’m hoping that some of our build system wizards here can point me in the right direction.
For context, I’m compiling on MacOS
and using Zig 0.13.0
.
Here’s the library: GitHub - eduardsui/tlse: Single C file TLS 1.2/1.3 implementation, using tomcrypt as crypto library
I went for this library because it looks like it should be a snap - there’s about 3 files to care about - tlse.c
, tlse.h
, and libtomcrypt.c
.
The header and source pair are as you’d expect, and you can link in libtomcrypt.c
using a flag -DTLS_AMALGAMATION
.
Here’s how I am putting this together:
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const tlse_src = b.dependency("tlse_src", .{ .target = target, .optimize = optimize });
const lib = b.addStaticLibrary(.{
.name = "tlse_lib",
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
lib.addIncludePath(tlse_src.path("."));
lib.addCSourceFile(.{
.file = tlse_src.path("tlse.c"),
.flags = &.{ "-DTLS_AMALGAMATION", "-DTLS_CURVE25519" },
});
b.installArtifact(lib);
const module = b.addModule("tlse", .{
.root_source_file = b.path("src/mod.zig"),
.link_libc = true,
.imports = &.{.{
.name = "tlse_lib"
.module = &lib.root_module,
}},
});
There may be typo in there but sadly this laptop doesn’t have Zig installed on it. I’m sure if you probably get the idea…
Anyhow, this deceptively compiles. The moment it runs, I hit a trap and it kills the program. I’m curious if someone would be willing to take a crack at building this library and would be willing to share their thoughts.
Thanks!