forked from kubo/plthook
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
140 lines (113 loc) · 4.23 KB
/
build.zig
File metadata and controls
140 lines (113 loc) · 4.23 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
const std = @import("std");
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const strip = b.option(bool, "strip", "Forces stripping on all optimization modes") orelse switch (optimize) {
.Debug, .ReleaseSafe => false,
.ReleaseFast, .ReleaseSmall => true,
};
const trace = b.option(bool, "trace", "Enables extremely verbose logging") orelse false;
const lib_mod = b.addModule("plthook", .{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
.strip = strip,
.link_libc = true,
});
lib_mod.addIncludePath(b.path("."));
lib_mod.addIncludePath(b.path("include"));
if (trace) {
lib_mod.addCMacro("PLTHOOK_DEBUG_CMD", "1");
lib_mod.addCMacro("PLTHOOK_DEBUG_BIND", "1");
lib_mod.addCMacro("PLTHOOK_DEBUG_FIXUPS", "1");
lib_mod.addCMacro("PLTHOOK_DEBUG_ADDR", "1");
}
lib_mod.addCSourceFile(.{
.file = b.path(switch (target.result.os.tag) {
.linux => "plthook_elf.c",
.macos => "plthook_osx.c",
.windows => "plthook_win32.c",
else => return error.UnsupportedOS,
}),
.flags = &.{ "-Wall", "-Werror" },
});
switch (target.result.os.tag) {
.macos => {
lib_mod.addIncludePath(b.path("lib/include/osx"));
},
.windows => {
lib_mod.linkSystemLibrary("Dbghelp", .{});
},
else => {},
}
const lib = b.addLibrary(.{
.linkage = .static,
.name = "plthook",
.root_module = lib_mod,
});
b.installArtifact(lib);
b.getInstallStep().dependOn(&b.addInstallHeaderFile(b.path("plthook.h"), "plthook.h").step);
// Creates a step for unit testing. This only builds the test executable
// but does not run it.
const lib_unit_tests = b.addTest(.{
.root_module = lib_mod,
});
const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);
const lib_dummy_mod = b.createModule(.{
.root_source_file = b.path("test/dummy.zig"),
.target = target,
.optimize = optimize,
});
const lib_dummy = b.addLibrary(.{
.name = "plthook-dummy",
.root_module = lib_dummy_mod,
.linkage = .dynamic,
});
const lib_test_mod = b.createModule(.{
.root_source_file = b.path("test/libtest.zig"),
.target = target,
.optimize = optimize,
});
lib_test_mod.linkLibrary(lib_dummy);
const lib_test = b.addLibrary(.{
.name = "plthook-test",
.root_module = lib_test_mod,
.linkage = .dynamic,
});
const install_lib_test = b.addInstallArtifact(lib_test, .{});
b.getInstallStep().dependOn(&install_lib_test.step);
const test_prog_mod = b.createModule(.{
.root_source_file = b.path("test/testprog.zig"),
.target = target,
.optimize = optimize,
});
test_prog_mod.addImport("plthook", lib_mod);
test_prog_mod.addIncludePath(b.path("."));
test_prog_mod.linkLibrary(lib_test);
const test_prog = b.addExecutable(.{
.name = "plthook-testprog",
.root_module = test_prog_mod,
});
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_lib_unit_tests.step);
test_step.dependOn(&b.addInstallArtifact(test_prog, .{}).step);
for ([_][]const u8{ "open", "open_by_handle", "open_by_address" }) |mode| {
const run_lib_test_prog = b.addRunArtifact(test_prog);
run_lib_test_prog.addArg(mode);
run_lib_test_prog.addArg(lib_test.out_filename);
if (target.result.os.tag == .windows) {
const cmd = b.addRunArtifact(b.addExecutable(.{
.name = "copy-libs",
.root_module = b.createModule(.{
.root_source_file = b.path("test/copy-libs.zig"),
.target = b.resolveTargetQuery(.{}),
}),
}));
cmd.addArtifactArg(lib_dummy);
cmd.addArtifactArg(lib_test);
const dir = cmd.addOutputDirectoryArg("libs");
run_lib_test_prog.setCwd(dir);
}
test_step.dependOn(&run_lib_test_prog.step);
}
}