-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.zig
More file actions
78 lines (64 loc) · 2.47 KB
/
build.zig
File metadata and controls
78 lines (64 loc) · 2.47 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
const std = @import("std");
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const lib_mod = b.addModule("opentelemetry-semconv", .{
.root_source_file = b.path("src/lib.zig"),
.target = target,
.optimize = optimize,
});
const lib = b.addLibrary(.{
.linkage = .static,
.name = "opentelemetry-semconv",
.root_module = lib_mod,
});
b.installArtifact(lib);
const lib_unit_tests = b.addTest(.{
.root_module = lib_mod,
});
const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);
const test_step = b.step("test", "Run library tests");
test_step.dependOn(&run_lib_unit_tests.step);
// Examples step
const examples_step = b.step("examples", "Build and run all example executables");
// Example files
const example_files: []const []const u8 = &.{
"basic.zig",
"advanced.zig",
};
// Create executable for each example
for (example_files) |example| {
const example_exe = b.addExecutable(.{
.name = std.mem.trim(u8, example, ".zig"),
.root_module = b.createModule(.{
.root_source_file = try b.path("examples").join(b.allocator, example),
.target = target,
.optimize = .ReleaseSafe,
}),
});
// Add the semconv module to each example
example_exe.root_module.addImport("opentelemetry-semconv", lib_mod);
// Install the example executable
const run_examples = b.addRunArtifact(example_exe);
// Add to examples step
examples_step.dependOn(&example_exe.step);
examples_step.dependOn(&run_examples.step);
}
// Add a step to generate the code via Weaver
const script_path = try b.path("scripts").join(b.allocator, "generate-consts-from-spec.sh");
const bash_generator = b.addSystemCommand(&.{script_path.getPath(b)});
const gen_step = b.step("generate", "Generate code via Weaver");
gen_step.dependOn(&bash_generator.step);
// Documentation step
const doc_step = b.step("docs", "Generate API documentation");
const docs = b.addObject(.{
.name = "lib",
.root_module = lib_mod,
});
const install_docs = b.addInstallDirectory(.{
.source_dir = docs.getEmittedDocs(),
.install_dir = .prefix,
.install_subdir = "docs",
});
doc_step.dependOn(&install_docs.step);
}