Repository navigation
Expand file tree
/
Copy pathbuild.zig
More file actions
113 lines (97 loc) · 3.17 KB
/
Copy pathbuild.zig
File metadata and controls
113 lines (97 loc) · 3.17 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
const std = @import("std");
const build_zon = @import("build.zig.zon");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// Build options (version from build.zig.zon)
const options = b.addOptions();
options.addOption([]const u8, "version", build_zon.version);
// Build cmark C library
const cmark_dep = b.dependency("cmark", .{});
const cmark_lib = b.addLibrary(.{
.name = "cmark",
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
}),
.linkage = .static,
});
// Add cmark source files
const cmark_sources = &[_][]const u8{
"blocks.c",
"buffer.c",
"cmark.c",
"cmark_ctype.c",
"commonmark.c",
"houdini_href_e.c",
"houdini_html_e.c",
"houdini_html_u.c",
"html.c",
"inlines.c",
"iterator.c",
"latex.c",
"man.c",
"node.c",
"references.c",
"render.c",
"scanners.c",
"utf8.c",
"xml.c",
};
cmark_lib.addCSourceFiles(.{
.root = cmark_dep.path("src"),
.files = cmark_sources,
.flags = &.{"-std=c99"},
});
// Add include paths for cmark headers
cmark_lib.addIncludePath(cmark_dep.path("src"));
cmark_lib.addIncludePath(b.path("src/cmark_compat"));
// Link libc
cmark_lib.linkLibC();
// Create module for our Zig code
const root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "build_options", .module = options.createModule() },
},
});
// Add cmark include path and link library to root module
root_module.addIncludePath(cmark_dep.path("src"));
root_module.addIncludePath(b.path("src/cmark_compat"));
root_module.linkLibrary(cmark_lib);
const exe = b.addExecutable(.{
.name = "defrag",
.root_module = root_module,
});
b.installArtifact(exe);
// Run command: `zig build run -- <args>`
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_step = b.step("run", "Run defrag");
run_step.dependOn(&run_cmd.step);
// Tests: `zig build test`
const test_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "build_options", .module = options.createModule() },
},
});
test_module.addIncludePath(cmark_dep.path("src"));
test_module.addIncludePath(b.path("src/cmark_compat"));
test_module.linkLibrary(cmark_lib);
const exe_tests = b.addTest(.{
.root_module = test_module,
});
const run_tests = b.addRunArtifact(exe_tests);
// Ensure executable is built before running tests (for subprocess tests)
run_tests.step.dependOn(b.getInstallStep());
const test_step = b.step("test", "Run tests");
test_step.dependOn(&run_tests.step);
}