-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.zig
More file actions
117 lines (103 loc) · 3.54 KB
/
Copy pathbuild.zig
File metadata and controls
117 lines (103 loc) · 3.54 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
const std = @import("std");
// NOTE: waiting for https://github.com/ziglang/zig/pull/20510
// const PACKAGE = @import("build.zig.zon");
const NAME = "o2s";
const VERSION = std.mem.trim(u8, @embedFile("version.txt"), &std.ascii.whitespace);
fn buildLibSourceFiles(b: *std.Build) !std.Build.Module.AddCSourceFilesOptions {
var source_files: std.ArrayListUnmanaged([]const u8) = .empty;
defer source_files.deinit(b.allocator);
{
var src = try std.fs.openDirAbsolute(b.pathFromRoot(SRC_DIR), .{ .iterate = true });
var walker = try src.walk(b.allocator);
defer walker.deinit();
while (try walker.next()) |entry| {
if (entry.kind == .file and std.mem.eql(u8, std.fs.path.extension(entry.basename), ".c")) {
try source_files.append(b.allocator, b.dupe(entry.path));
}
}
}
return .{
.root = b.path(SRC_DIR),
.files = b.dupeStrings(source_files.items),
.flags = &(CFLAGS),
};
}
pub fn build(b: *std.Build) !void {
const semver = try std.SemanticVersion.parse(VERSION);
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const include = b.path(INCLUDE_DIR);
const lib = b.addLibrary(.{
.name = NAME,
.version = semver,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
}),
});
lib.root_module.addCMacro("LIBO2S_VERSION", VERSION);
lib.addIncludePath(include);
lib.addCSourceFiles(try buildLibSourceFiles(b));
lib.installHeadersDirectory(include, "", .{});
b.installArtifact(lib);
{ // Test
const test_step = b.step("test", "Run tests");
const test_exe = b.addExecutable(.{
.name = "test_libo2s",
.root_module = b.createModule(.{ .target = target, .optimize = optimize }),
});
const run_test = b.addRunArtifact(test_exe);
const catch2 = b.dependency("catch2", .{ .target = target, .optimize = optimize });
test_exe.addCSourceFiles(.{
.root = b.path(TEST_DIR),
.files = &TEST_SOURCES,
.flags = &.{"--std=c++23"},
});
test_exe.linkLibCpp();
test_exe.linkLibrary(lib);
test_exe.linkLibrary(catch2.artifact("Catch2"));
test_exe.linkLibrary(catch2.artifact("Catch2WithMain"));
test_step.dependOn(&run_test.step);
const test_install = b.step("install_test", "Build tests");
const install_test = b.addInstallArtifact(test_exe, .{});
test_install.dependOn(&install_test.step);
}
{ // Documentation
const doc_step = b.step("doc", "Generate the documentation as a static website");
const run_doxygen = b.addSystemCommand(&.{"doxygen"});
run_doxygen.addFileArg(b.path("doc/Doxyfile.cfg"));
run_doxygen.setEnvironmentVariable("PROJECT_VERSION", VERSION);
doc_step.dependOn(&run_doxygen.step);
}
}
const SRC_DIR = "src";
const INCLUDE_DIR = "include";
const TEST_DIR = "test";
const CFLAGS = .{
"--std=gnu23",
"-Wall",
"-Wextra",
"-Werror",
// "-Wvla",
"-Wformat=2",
"-Wmissing-prototypes",
"-Wmissing-declarations",
"-Wold-style-definition",
"-Wstrict-prototypes",
};
const TEST_SOURCES = .{
"array.cpp",
"deque.cpp",
"file.cpp",
"hashes.cpp",
"input_stream.cpp",
"mutex.cpp",
"serial.cpp",
"string.cpp",
"thread.cpp",
"timer.cpp",
"to_string.cpp",
"version.cpp",
"write.cpp",
};