mirror of
https://github.com/zigzap/zap.git
synced 2025-10-20 23:24:09 +00:00
build.zig changes for conditional openssl support
This commit is contained in:
parent
cbccf535c3
commit
62fc16aaac
2 changed files with 22 additions and 1 deletions
|
@ -7,6 +7,8 @@ pub fn build(b: *std.build.Builder) !void {
|
||||||
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
|
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
|
||||||
const optimize = b.standardOptimizeOption(.{});
|
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.
|
// create a module to be used internally.
|
||||||
var zap_module = b.createModule(.{
|
var zap_module = b.createModule(.{
|
||||||
.source_file = .{ .path = "src/zap.zig" },
|
.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.
|
// register the module so it can be referenced using the package manager.
|
||||||
try b.modules.put(b.dupe("zap"), zap_module);
|
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");
|
const all_step = b.step("all", "build all examples");
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ pub fn build_facilio(
|
||||||
b: *std.build.Builder,
|
b: *std.build.Builder,
|
||||||
target: std.zig.CrossTarget,
|
target: std.zig.CrossTarget,
|
||||||
optimize: std.builtin.OptimizeMode,
|
optimize: std.builtin.OptimizeMode,
|
||||||
|
use_openssl: bool,
|
||||||
) !*std.build.CompileStep {
|
) !*std.build.CompileStep {
|
||||||
const lib = b.addStaticLibrary(.{
|
const lib = b.addStaticLibrary(.{
|
||||||
.name = "facil.io",
|
.name = "facil.io",
|
||||||
|
@ -27,6 +28,8 @@ pub fn build_facilio(
|
||||||
try flags.append("-DFIO_HTTP_EXACT_LOGGING");
|
try flags.append("-DFIO_HTTP_EXACT_LOGGING");
|
||||||
if (target.getAbi() == .musl)
|
if (target.getAbi() == .musl)
|
||||||
try flags.append("-D_LARGEFILE64_SOURCE");
|
try flags.append("-D_LARGEFILE64_SOURCE");
|
||||||
|
if (use_openssl)
|
||||||
|
try flags.append("-DHAVE_OPENSSL -DFIO_TLS_FOUND");
|
||||||
|
|
||||||
// Include paths
|
// Include paths
|
||||||
lib.addIncludePath(.{ .path = subdir ++ "/." });
|
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/cli" });
|
||||||
lib.addIncludePath(.{ .path = subdir ++ "/lib/facil/http" });
|
lib.addIncludePath(.{ .path = subdir ++ "/lib/facil/http" });
|
||||||
lib.addIncludePath(.{ .path = subdir ++ "/lib/facil/http/parsers" });
|
lib.addIncludePath(.{ .path = subdir ++ "/lib/facil/http/parsers" });
|
||||||
|
if (use_openssl)
|
||||||
|
lib.addIncludePath(.{ .path = subdir ++ "/lib/facil/tls" });
|
||||||
|
|
||||||
// C source files
|
// C source files
|
||||||
lib.addCSourceFiles(&.{
|
lib.addCSourceFiles(&.{
|
||||||
|
@ -56,8 +61,22 @@ pub fn build_facilio(
|
||||||
subdir ++ "/lib/facil/cli/fio_cli.c",
|
subdir ++ "/lib/facil/cli/fio_cli.c",
|
||||||
}, flags.items);
|
}, 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
|
// link against libc
|
||||||
lib.linkLibC();
|
lib.linkLibC();
|
||||||
|
|
||||||
|
// link in libopenssl and libcrypto on demand
|
||||||
|
if (use_openssl) {
|
||||||
|
lib.linkSystemLibrary("ssl");
|
||||||
|
lib.linkSystemLibrary("crypto");
|
||||||
|
}
|
||||||
|
|
||||||
b.installArtifact(lib);
|
b.installArtifact(lib);
|
||||||
|
|
||||||
return lib;
|
return lib;
|
||||||
|
|
Loading…
Add table
Reference in a new issue