1
0
Fork 0
mirror of https://github.com/zigzap/zap.git synced 2025-10-20 15:14:08 +00:00

build.zig changes for conditional openssl support

This commit is contained in:
Rene Schallner 2023-12-29 15:57:20 +01:00
parent cbccf535c3
commit 62fc16aaac
2 changed files with 22 additions and 1 deletions

View file

@ -7,6 +7,8 @@ pub fn build(b: *std.build.Builder) !void {
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
const optimize = b.standardOptimizeOption(.{});
const use_openssl = b.option(bool, "openssl", "Use system-installed openssl for TLS support in zap") orelse false;
// create a module to be used internally.
var zap_module = b.createModule(.{
.source_file = .{ .path = "src/zap.zig" },
@ -15,7 +17,7 @@ pub fn build(b: *std.build.Builder) !void {
// register the module so it can be referenced using the package manager.
try b.modules.put(b.dupe("zap"), zap_module);
const facilio = try build_facilio("facil.io", b, target, optimize);
const facilio = try build_facilio("facil.io", b, target, optimize, use_openssl);
const all_step = b.step("all", "build all examples");

View file

@ -5,6 +5,7 @@ pub fn build_facilio(
b: *std.build.Builder,
target: std.zig.CrossTarget,
optimize: std.builtin.OptimizeMode,
use_openssl: bool,
) !*std.build.CompileStep {
const lib = b.addStaticLibrary(.{
.name = "facil.io",
@ -27,6 +28,8 @@ pub fn build_facilio(
try flags.append("-DFIO_HTTP_EXACT_LOGGING");
if (target.getAbi() == .musl)
try flags.append("-D_LARGEFILE64_SOURCE");
if (use_openssl)
try flags.append("-DHAVE_OPENSSL -DFIO_TLS_FOUND");
// Include paths
lib.addIncludePath(.{ .path = subdir ++ "/." });
@ -35,6 +38,8 @@ pub fn build_facilio(
lib.addIncludePath(.{ .path = subdir ++ "/lib/facil/cli" });
lib.addIncludePath(.{ .path = subdir ++ "/lib/facil/http" });
lib.addIncludePath(.{ .path = subdir ++ "/lib/facil/http/parsers" });
if (use_openssl)
lib.addIncludePath(.{ .path = subdir ++ "/lib/facil/tls" });
// C source files
lib.addCSourceFiles(&.{
@ -56,8 +61,22 @@ pub fn build_facilio(
subdir ++ "/lib/facil/cli/fio_cli.c",
}, flags.items);
if (use_openssl) {
lib.addCSourceFiles(&.{
subdir ++ "/lib/facil/tls/fio_tls_openssl.c",
subdir ++ "/lib/facil/tls/fio_tls_missing.c",
}, flags.items);
}
// link against libc
lib.linkLibC();
// link in libopenssl and libcrypto on demand
if (use_openssl) {
lib.linkSystemLibrary("ssl");
lib.linkSystemLibrary("crypto");
}
b.installArtifact(lib);
return lib;