Debian Codegraph @

debian/rust-vendor/codspeed/instrument-hooks/build.zig

raw
1 const std = @import("std");
2
3 pub fn build(b: *std.Build) void {
4 // Core Library — one per OS, transpiled to C via .ofmt = .c.
5 const PerOsTarget = struct { name: []const u8, query: std.Target.Query };
6 const targets = [_]PerOsTarget{
7 .{ .name = "core.linux", .query = .{
8 .cpu_arch = .x86_64,
9 .os_tag = .linux,
10 .abi = .gnu,
11 .ofmt = .c,
12 } },
13 .{ .name = "core.macos", .query = .{
14 .cpu_arch = .x86_64,
15 .os_tag = .macos,
16 .abi = .none,
17 .ofmt = .c,
18 } },
19 };
20 for (targets) |t| {
21 const lib = b.addStaticLibrary(.{
22 .name = t.name,
23 .root_source_file = b.path("src/c.zig"),
24 .target = b.resolveTargetQuery(t.query),
25 .optimize = .ReleaseSmall,
26 .link_libc = true,
27 .strip = true,
28 .pic = true,
29 });
30 lib.no_builtin = true;
31 b.installArtifact(lib);
32 }
33
34 // Test shared library fixture
35 //
36 // Builds a tiny .so used by ElfView tests. The tests dlopen() it at runtime
37 // so they exercise the real dl_iterate_phdr path against a known binary.
38 const test_lib = b.addSharedLibrary(.{
39 .name = "test_fixture",
40 .target = b.graph.host,
41 .optimize = .Debug,
42 .link_libc = true,
43 });
44 test_lib.addCSourceFile(.{ .file = b.path("src/environment/linked_libraries/testdata/test_lib.c") });
45 test_lib.version_script = b.path("src/environment/linked_libraries/testdata/test_lib.ver");
46 test_lib.build_id = std.zig.BuildId.parse("0xdeadbeef") catch unreachable;
47
48 // Tests
49 //
50 const test_main = b.addTest(.{ .root_source_file = b.path("src/root.zig"), .optimize = .ReleaseSafe, .link_libc = true, .test_runner = .{ .path = b.path("src/tests/runner.zig"), .mode = .simple } });
51 test_main.addCSourceFile(.{ .file = b.path("src/helpers/valgrind_wrapper.c") });
52 test_main.addIncludePath(b.path("includes"));
53 test_main.linkLibC();
54 // Link the test .so so it appears in dl_iterate_phdr during ElfView tests
55 test_main.addLibraryPath(test_lib.getEmittedBin().dirname());
56 test_main.addRPath(test_lib.getEmittedBin().dirname());
57 test_main.linkSystemLibrary2("test_fixture", .{ .preferred_link_mode = .dynamic });
58 const run_test_main = b.addRunArtifact(test_main);
59 b.step("test", "test utility functions").dependOn(&run_test_main.step);
60 }