-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathbuild.zig
More file actions
109 lines (102 loc) · 3.26 KB
/
build.zig
File metadata and controls
109 lines (102 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const single_threaded = b.option(bool, "single-threaded", "Build artifacts that run in single threaded mode");
const upstream = b.dependency("zlib", .{
.target = target,
.optimize = optimize,
});
const lib_mod = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
.single_threaded = single_threaded,
});
lib_mod.addCSourceFiles(.{
.root = upstream.path("."),
.files = &[_][]const u8{
"adler32.c",
"crc32.c",
"deflate.c",
"infback.c",
"inffast.c",
"inflate.c",
"inftrees.c",
"trees.c",
"zutil.c",
"compress.c",
"uncompr.c",
"gzclose.c",
"gzlib.c",
"gzread.c",
"gzwrite.c",
},
.flags = &.{
"-DHAVE_SYS_TYPES_H",
"-DHAVE_STDINT_H",
"-DHAVE_STDDEF_H",
"-DZ_HAVE_UNISTD_H",
},
});
const lib = b.addLibrary(.{
.linkage = .static,
.name = "z",
.root_module = lib_mod,
});
lib.installHeadersDirectory(upstream.path(""), "", .{
.include_extensions = &.{
"zconf.h",
"zlib.h",
},
});
b.installArtifact(lib);
const dynamic_lib = b.addLibrary(.{
.linkage = .dynamic,
.name = "z",
.root_module = lib_mod,
});
// Install with no version extension
b.installArtifact(dynamic_lib);
// Install with version extension
const output_name = b.fmt("libz{s}.{s}", .{
dynamic_lib.root_module.resolved_target.?.result.dynamicLibSuffix(),
"1.3.1",
});
const install_step = b.addInstallArtifact(dynamic_lib, .{
.dest_dir = .{
.override = .lib,
},
.dest_sub_path = output_name,
});
b.getInstallStep().dependOn(&install_step.step);
// Testing is about running the test binaries and checking they return 0.
const test_step = b.step("test", "Run tests");
const example = addTestExecutable(b, target, optimize, upstream, lib, "example", "test/example.c");
test_step.dependOn(&example.step);
const examplesh = addTestExecutable(b, target, optimize, upstream, dynamic_lib, "examplesh", "test/example.c");
test_step.dependOn(&examplesh.step);
}
fn addTestExecutable(b: *std.Build, target: std.Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode, zlib: *std.Build.Dependency, lib: *std.Build.Step.Compile,
name: []const u8, filename: []const u8) *std.Build.Step.Run {
const test_exe_mod = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
.single_threaded = true,
});
test_exe_mod.addCSourceFiles(.{
.root = zlib.path("."),
.files = &[_][]const u8{
filename,
},
});
test_exe_mod.linkLibrary(lib);
const test_exe = b.addExecutable(.{
.name = name,
.root_module = test_exe_mod,
});
const run_exe_tests = b.addRunArtifact(test_exe);
return run_exe_tests;
}