Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 32 additions & 40 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,31 @@ pub fn build(b: *std.Build) !void {
});

if (b.option(bool, "enable-ssh", "Enable SSH support") orelse false) {
mod.linkSystemLibrary("ssh2", .{});
if (b.systemIntegrationOption("ssh2", .{})) {
mod.linkSystemLibrary("ssh2", .{});
} else {
const crypto_backend: enum {
openssl,
mbedtls,
wincng,
} = if (target.result.os.tag == .windows)
.wincng
else switch (tls_backend) {
.openssl => .openssl,
.mbedtls => .mbedtls,
// fallback to mbedtls
else => .mbedtls,
};
if (b.lazyDependency("libssh2", .{
.target = target,
.optimize = optimize,
.@"crypto-backend" = crypto_backend,
.@"link-system-crypto-backend" = false,
.zlib = true,
})) |libssh2| {
mod.linkLibrary(libssh2.artifact("ssh2"));
}
}
features.addValues(.{
.GIT_SSH = 1,
.GIT_SSH_LIBSSH2 = 1,
Expand Down Expand Up @@ -298,36 +322,16 @@ pub fn build(b: *std.Build) !void {
}));
features.addValues(.{ .GIT_REGEX_BUILTIN = 1 });
}
{
// @Todo: support using system zlib?
const zlib = b.createModule(.{
const zlib_includes = blk: {
const zlib_dep = b.dependency("zlib", .{
.target = target,
.optimize = optimize,
.link_libc = true,
});
zlib.addIncludePath(libgit_src.path("deps/zlib"));
zlib.addCSourceFiles(.{
.root = libgit_root,
.files = &zlib_sources,
.flags = &.{
"-Wno-implicit-fallthrough",
"-DNO_VIZ",
"-DSTDC",
"-DNO_GZIP",
"-DHAVE_SYS_TYPES_H",
"-DHAVE_STDINT_H",
"-DHAVE_STDDEF_H",
},
});

mod.addIncludePath(libgit_src.path("deps/zlib"));
mod.linkLibrary(b.addLibrary(.{
.name = "z",
.linkage = .static,
.root_module = zlib,
}));
const zlib = zlib_dep.artifact("z");
mod.linkLibrary(zlib);
features.addValues(.{ .GIT_COMPRESSION_ZLIB = 1 });
}
break :blk zlib.getEmittedIncludeTree();
};
// xdiff
{
// Bundled xdiff dependency relies on libgit2 headers & utils, so we
Expand Down Expand Up @@ -483,7 +487,7 @@ pub fn build(b: *std.Build) !void {
runner.addIncludePath(libgit_src.path("src/util"));
runner.addIncludePath(libgit_src.path("src/libgit2"));

runner.addIncludePath(libgit_src.path("deps/zlib"));
runner.addIncludePath(zlib_includes);
runner.addIncludePath(libgit_src.path("deps/xdiff"));
runner.addIncludePath(libgit_src.path("deps/pcre"));
maybeAddTlsIncludes(runner, tls_dep, tls_backend);
Expand Down Expand Up @@ -892,18 +896,6 @@ const pcre_sources = [_][]const u8{
"deps/pcre/pcreposix.c",
};

const zlib_sources = [_][]const u8{
"deps/zlib/adler32.c",
"deps/zlib/crc32.c",
"deps/zlib/deflate.c",
"deps/zlib/infback.c",
"deps/zlib/inffast.c",
"deps/zlib/inflate.c",
"deps/zlib/inftrees.c",
"deps/zlib/trees.c",
"deps/zlib/zutil.c",
};

const xdiff_sources = [_][]const u8{
"deps/xdiff/xdiffi.c",
"deps/xdiff/xemit.c",
Expand Down
10 changes: 10 additions & 0 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@
.hash = "mbedtls-3.6.4-E4NUR24VAADBF5pt-No-Z90DjozkzySYAgq6eDFy9Xdy",
.lazy = true,
},
.libssh2 = .{
// TODO: merge https://github.com/allyourcodebase/libssh2/pull/11
.url = "git+https://github.com/dasimmet/libssh2?ref=feature/mbedtls-dependency#5e39e4fdde45d031ca417ab7f6a20004264f3acf",
.hash = "libssh2-1.11.1-JgdeR2AYAAAI5JWiLCEquyMH25Q0m3IXODXotOojEsUS",
.lazy = true,
},
.zlib = .{
.url = "git+https://github.com/allyourcodebase/zlib.git?ref=1.3.2#d3b5519d3b73616a6bfece0712f080029d2a9244",
.hash = "zlib-1.3.2-ZZQ7lc8NAAAHm9MDfplvwoesXvk4tVm6VCsiI8KnIbT0",
},
},
.paths = .{
"build.zig",
Expand Down
Loading