1
1
const std = @import ("std" );
2
+ const builtin = @import ("builtin" );
2
3
3
4
pub fn build (b : * std.Build ) ! void {
4
5
const target = b .standardTargetOptions (.{});
@@ -22,26 +23,36 @@ pub fn build(b: *std.Build) !void {
22
23
.{
23
24
.GIT_THREADS = 1 ,
24
25
.GIT_USE_NSEC = 1 ,
25
- .GIT_RAND_GETLOADAVG = 1 ,
26
26
},
27
27
);
28
28
29
- // TODO: are there more subtleties for other platforms?
30
- // TODO: do we need iconv on other platforms? original cmake enabled it by
29
+ // @Cleanup: all these platform and TLS variants are starting to become unweildly. Compress these codepaths to avoid edgecases.
30
+
31
+ // @Todo: are there more subtleties for other platforms?
32
+ // @Todo: do we need iconv on other platforms? original cmake enabled it by
31
33
// 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
- });
34
+ switch (target .result .os .tag ) {
35
+ .macos = > {
36
+ lib .linkSystemLibrary ("iconv" );
37
+ features .addValues (.{
38
+ .GIT_USE_ICONV = 1 ,
39
+ .GIT_USE_STAT_MTIMESPEC = 1 ,
40
+ .GIT_REGEX_REGCOMP_L = 1 ,
41
+ .GIT_QSORT_BSD = 1 ,
42
+ });
43
+ },
44
+ .windows = > {
45
+ features .addValues (.{
46
+ .GIT_QSORT_MSC = 1 ,
47
+ });
48
+ },
49
+ else = > {
50
+ features .addValues (.{
51
+ .GIT_USE_STAT_MTIM = 1 ,
52
+ .GIT_RAND_GETENTROPY = 1 ,
53
+ .GIT_RAND_GETLOADAVG = 1 ,
54
+ });
55
+ },
45
56
}
46
57
47
58
const flags = [_ ][]const u8 {
@@ -419,8 +430,7 @@ pub fn build(b: *std.Build) !void {
419
430
420
431
const test_step = b .step ("test" , "Run core unit tests (requires python)" );
421
432
{
422
- if (@import ("builtin" ).os .tag != .windows ) {
423
-
433
+ if (builtin .os .tag != .windows ) {
424
434
// Fix the test fixture file permissions. This is necessary because Zig does
425
435
// not respect the execute permission on arbitrary files it extracts from dependencies.
426
436
// Since we need those files to have the execute permission set for tests to
@@ -452,7 +462,7 @@ pub fn build(b: *std.Build) !void {
452
462
.name = "libgit2_tests" ,
453
463
.root_module = b .createModule (.{
454
464
.target = target ,
455
- .optimize = .ReleaseSafe ,
465
+ .optimize = .Debug ,
456
466
.link_libc = true ,
457
467
}),
458
468
});
@@ -477,7 +487,8 @@ pub fn build(b: *std.Build) !void {
477
487
.flags = &.{
478
488
b .fmt (
479
489
"-DCLAR_FIXTURE_PATH=\" {s}\" " ,
480
- .{libgit_src .path ("tests/resources" ).getPath2 (b , & runner .step )}, // @Cleanup
490
+ // clar expects the fixture path to only have posix seperators or else some tests will break on windows
491
+ .{try getNormalizedPath (libgit_src .path ("tests/resources" ), b , & runner .step )},
481
492
),
482
493
"-DCLAR_TMPDIR=\" libgit2_tests\" " ,
483
494
"-DCLAR_WIN32_LONGPATHS" ,
@@ -542,6 +553,18 @@ pub fn build(b: *std.Build) !void {
542
553
}
543
554
}
544
555
556
+ /// Returns the absolute lazy path with posix seperators
557
+ fn getNormalizedPath (lp : std.Build.LazyPath , b : * std.Build , asking_step : * std.Build.Step ) ! []const u8 {
558
+ const p = lp .getPath3 (b , asking_step );
559
+ const result = b .pathResolve (&.{ p .root_dir .path orelse "." , p .sub_path });
560
+ if (builtin .os .tag == .windows ) {
561
+ for (result ) | * c | {
562
+ if (c .* == '\\ ' ) c .* = '/' ;
563
+ }
564
+ }
565
+ return result ;
566
+ }
567
+
545
568
pub const TlsBackend = enum { openssl , mbedtls , securetransport };
546
569
547
570
fn maybeAddTlsIncludes (
0 commit comments