Skip to content

Commit 84e3689

Browse files
Merge pull request #7 from blurrycat/feat/macos
macOS support
2 parents 0f1d30e + f29cdc9 commit 84e3689

File tree

2 files changed

+48
-17
lines changed

2 files changed

+48
-17
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
zig-version: ["0.14.0"]
1818
os:
1919
- ubuntu-latest
20-
# - macos-latest # Does not build yet
20+
- macos-latest
2121
# - windows-latest # Does not pass tests
2222
runs-on: ${{ matrix.os }}
2323
steps:

build.zig

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,29 @@ pub fn build(b: *std.Build) !void {
2121
.{ .style = .{ .cmake = libgit_src.path("src/util/git2_features.h.in") } },
2222
.{
2323
.GIT_THREADS = 1,
24-
25-
// @Todo: add per target conditionals for these
2624
.GIT_USE_NSEC = 1,
27-
.GIT_USE_STAT_MTIM = 1,
28-
.GIT_RAND_GETENTROPY = 1,
2925
.GIT_RAND_GETLOADAVG = 1,
3026
},
3127
);
3228

29+
// TODO: are there more subtleties for other platforms?
30+
// TODO: do we need iconv on other platforms? original cmake enabled it by
31+
// default on APPLE targets
32+
if (target.result.os.tag == .macos) {
33+
lib.linkSystemLibrary("iconv");
34+
features.addValues(.{
35+
.GIT_USE_ICONV = 1,
36+
.GIT_USE_STAT_MTIMESPEC = 1,
37+
.GIT_REGEX_REGCOMP_L = 1,
38+
.GIT_QSORT_BSD = 1,
39+
});
40+
} else {
41+
features.addValues(.{
42+
.GIT_USE_STAT_MTIM = 1,
43+
.GIT_RAND_GETENTROPY = 1,
44+
});
45+
}
46+
3347
const flags = [_][]const u8{
3448
// @Todo: for some reason on linux, trying to use c90 as specified in the cmake
3549
// files causes compile errors relating to pthreads. Using gnu90 or the
@@ -45,11 +59,11 @@ pub fn build(b: *std.Build) !void {
4559

4660
// The TLS backend logic is only run for non windows builds.
4761
var tls_dep: ?*std.Build.Dependency = null;
48-
const tls_backend = b.option(
62+
const tls_backend: TlsBackend = b.option(
4963
TlsBackend,
5064
"tls-backend",
5165
"Choose Unix TLS/SSL backend (default is mbedtls)",
52-
) orelse .mbedtls;
66+
) orelse if (target.result.os.tag == .macos) .securetransport else .mbedtls;
5367

5468
if (target.result.os.tag == .windows) {
5569
lib.linkSystemLibrary("winhttp");
@@ -73,6 +87,21 @@ pub fn build(b: *std.Build) !void {
7387
lib.addCSourceFiles(.{ .root = libgit_root, .files = &util_win32_sources, .flags = &flags });
7488
} else {
7589
switch (tls_backend) {
90+
.securetransport => {
91+
lib.linkFramework("Security");
92+
lib.linkFramework("CoreFoundation");
93+
features.addValues(.{
94+
.GIT_HTTPS = 1,
95+
.GIT_SECURE_TRANSPORT = 1,
96+
97+
.GIT_SHA1_COLLISIONDETECT = 1,
98+
.GIT_SHA256_COMMON_CRYPTO = 1,
99+
100+
.GIT_USE_FUTIMENS = 1,
101+
.GIT_IO_POLL = 1,
102+
.GIT_IO_SELECT = 1,
103+
});
104+
},
76105
.openssl => {
77106
tls_dep = b.lazyDependency("openssl", .{
78107
.target = target,
@@ -132,21 +161,23 @@ pub fn build(b: *std.Build) !void {
132161
switch (tls_backend) {
133162
.openssl => "-DCRYPT_OPENSSL",
134163
.mbedtls => "-DCRYPT_MBEDTLS",
164+
.securetransport => "-DCRYPT_COMMONCRYPTO",
135165
},
136166
};
137-
ntlm.addCSourceFiles(.{
138-
.root = libgit_root,
139-
.files = &ntlm_sources,
140-
.flags = &ntlm_cflags,
141-
});
142167
ntlm.addCSourceFiles(.{
143168
.root = libgit_root,
144169
.files = switch (tls_backend) {
145170
.openssl => &.{"deps/ntlmclient/crypt_openssl.c"},
146171
.mbedtls => &.{"deps/ntlmclient/crypt_mbedtls.c"},
172+
.securetransport => &.{"deps/ntlmclient/crypt_commoncrypto.c"},
147173
},
148174
.flags = &ntlm_cflags,
149175
});
176+
ntlm.addCSourceFiles(.{
177+
.root = libgit_root,
178+
.files = &ntlm_sources,
179+
.flags = &(ntlm_cflags ++ .{"-Wno-deprecated"}),
180+
});
150181

151182
lib.linkLibrary(ntlm);
152183
lib.addAfterIncludePath(libgit_src.path("deps/ntlmclient")); // avoid aliasing ntlmclient/util.h and src/util/util.h
@@ -163,6 +194,7 @@ pub fn build(b: *std.Build) !void {
163194
.files = switch (tls_backend) {
164195
.openssl => &.{"src/util/hash/openssl.c"},
165196
.mbedtls => &.{"src/util/hash/mbedtls.c"},
197+
.securetransport => &.{"src/util/hash/common_crypto.c"},
166198
},
167199
.flags = &flags,
168200
});
@@ -210,7 +242,7 @@ pub fn build(b: *std.Build) !void {
210242
lib.linkLibrary(llhttp);
211243
features.addValues(.{ .GIT_HTTPPARSER_BUILTIN = 1 });
212244
}
213-
{
245+
if (target.result.os.tag != .macos) {
214246
const pcre = b.addLibrary(.{
215247
.name = "pcre",
216248
.linkage = .static,
@@ -298,8 +330,6 @@ pub fn build(b: *std.Build) !void {
298330
else => |size| std.debug.panic("Unsupported architecture ({d}bit)", .{size}),
299331
}
300332

301-
// @Todo: ICONV?
302-
303333
lib.addConfigHeader(features);
304334

305335
lib.addIncludePath(libgit_src.path("src/libgit2"));
@@ -409,7 +439,7 @@ pub fn build(b: *std.Build) !void {
409439
try file.setPermissions(.{ .inner = .{ .mode = 0o755 } });
410440
}
411441

412-
const gen_cmd = b.addSystemCommand(&.{"python"});
442+
const gen_cmd = b.addSystemCommand(&.{"python3"});
413443
gen_cmd.addFileArg(libgit_src.path("tests/clar/generate.py"));
414444
const clar_suite = gen_cmd.addPrefixedOutputDirectoryArg("-o", "clar_suite");
415445
gen_cmd.addArgs(&.{ "-f", "-xonline", "-xstress", "-xperf" });
@@ -509,7 +539,7 @@ pub fn build(b: *std.Build) !void {
509539
}
510540
}
511541

512-
const TlsBackend = enum { openssl, mbedtls };
542+
pub const TlsBackend = enum { openssl, mbedtls, securetransport };
513543

514544
fn maybeAddTlsIncludes(
515545
compile: *std.Build.Step.Compile,
@@ -518,6 +548,7 @@ fn maybeAddTlsIncludes(
518548
) void {
519549
if (dep) |tls| {
520550
const name = switch (backend) {
551+
.securetransport => unreachable,
521552
.openssl => "openssl",
522553
.mbedtls => "mbedtls",
523554
};

0 commit comments

Comments
 (0)