Repository navigation
Expand file tree
/
Copy pathbuild.zig
More file actions
101 lines (88 loc) · 3.59 KB
/
Copy pathbuild.zig
File metadata and controls
101 lines (88 loc) · 3.59 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
const std = @import("std");
const manifest = @import("build.zig.zon");
pub fn generatePkgconfig(b: *std.Build, version: std.SemanticVersion) !*std.Build.Step.InstallFile {
const allocator = b.allocator;
const version_str = try std.fmt.allocPrint(allocator, "{d}.{d}", .{ version.major, version.minor });
// The install prefix is no longer known at configure time (the new build
// system resolves it during the make/install stage), so the generated
// .pc file derives `prefix` from `${pcfiledir}` at use time instead. Here
// we only need to substitute @VERSION@.
const template = @embedFile("upstream/libdebuginfod.pc.in");
const text = try std.mem.replaceOwned(u8, allocator, template, "@VERSION@", version_str);
const wf = b.addWriteFiles();
const pc = wf.add("libdebuginfod.pc", text);
return b.addInstallFileWithDir(pc, .prefix, "lib/pkgconfig/libdebuginfod.pc");
}
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const version = try std.SemanticVersion.parse(manifest.version);
var linkage: std.builtin.LinkMode = .static;
const linkage_str = b.option(
[]const u8,
"linkage",
"linkage type of result library (default: static), options: static,dynamic",
) orelse "";
if (std.mem.eql(u8, linkage_str, "dynamic")) {
linkage = .dynamic;
}
const zon_module = b.createModule(.{
.root_source_file = b.path("build.zig.zon"),
});
const lib_mod = b.createModule(.{
.root_source_file = b.path("src/binding.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
lib_mod.addImport("build.zig.zon", zon_module);
const include = b.addInstallHeaderFile(b.path("upstream/debuginfod.h"), "elfutils/debuginfod.h");
const pkgconfig = try generatePkgconfig(b, version);
const lib = b.addLibrary(.{
.linkage = linkage,
.name = "debuginfod",
.root_module = lib_mod,
.version = version,
});
if (linkage == .static) {
lib.bundle_compiler_rt = true;
lib.pie = true;
}
lib.setVersionScript(b.path("upstream/libdebuginfod.map"));
lib.step.dependOn(&include.step);
lib.step.dependOn(&pkgconfig.step);
b.installArtifact(lib);
// `debuginfod-find` CLI (see issue #8): thin wrapper over client.zig with
// the same command line as elfutils' debuginfod-find.
const find_mod = b.createModule(.{
.root_source_file = b.path("src/find.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
find_mod.addImport("build.zig.zon", zon_module);
const find_exe = b.addExecutable(.{
.name = "debuginfod-find",
.root_module = find_mod,
.version = version,
});
b.installArtifact(find_exe);
const run_find = b.addRunArtifact(find_exe);
run_find.addPassthruArgs();
const run_step = b.step("run", "Run debuginfod-find (pass args after `--`)");
run_step.dependOn(&run_find.step);
const lib_unit_tests = b.addTest(.{
.root_module = lib_mod,
});
const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);
b.installArtifact(lib_unit_tests);
const find_unit_tests = b.addTest(.{
.name = "test-find",
.root_module = find_mod,
});
const run_find_unit_tests = b.addRunArtifact(find_unit_tests);
b.installArtifact(find_unit_tests);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_lib_unit_tests.step);
test_step.dependOn(&run_find_unit_tests.step);
}