1const std = @import("std");
2const builtin = @import("builtin");
3
4pub fn build(b: *std.Build) void {
5 const test_step = b.step("test", "Test it");
6 b.default_step = test_step;
7
8 // https://codeberg.org/ziglang/zig/issues/36013
9 if (builtin.os.tag == .freebsd) return;
10
11 const config_header = b.addConfigHeader(
12 .{ .style = .{ .autoconf_undef = b.path("autoconf_undef/config.h.in") } },
13 .{
14 .SOME_NO = null,
15 .SOME_TRUE = true,
16 .SOME_FALSE = false,
17 .SOME_ZERO = 0,
18 .SOME_ONE = 1,
19 .SOME_TEN = 10,
20 .SOME_ENUM = @as(enum { foo, bar }, .foo),
21 .SOME_ENUM_LITERAL = .@"test",
22 .SOME_STRING = "test",
23 .PREFIX_SPACE = null,
24 .PREFIX_TAB = null,
25 .POSTFIX_SPACE = null,
26 .POSTFIX_TAB = null,
27 .SOME_UNDERSCORED = true,
28 },
29 );
30 const check_config_header = b.addCheckFile(config_header.getOutputFile(), .{
31 .expected_exact = @embedFile("autoconf_undef/config.h"),
32 });
33 test_step.dependOn(&check_config_header.step);
34
35 const config_header_autoconf_at = b.addConfigHeader(
36 .{ .style = .{ .autoconf_at = b.path("autoconf_at/autoconf_at.h.in") } },
37 .{
38 .undefined = null,
39 .defined = {},
40 .boolean_true = true,
41 .boolean_false = false,
42 .integer = 42,
43 .string = "text",
44 .string_at = "@string@",
45 .underscored_var = "value",
46 .at_sign = "@",
47 },
48 );
49 const check_config_header_autoconf_at = b.addCheckFile(config_header_autoconf_at.getOutputFile(), .{
50 .expected_exact = @embedFile("autoconf_at/autoconf_at.h"),
51 });
52 test_step.dependOn(&check_config_header_autoconf_at.step);
53
54 const config_header_meson = b.addConfigHeader(
55 .{ .style = .{
56 .meson = b.path("meson/mesondefine.h.in"),
57 } },
58 .{
59 .version = "1.2.3",
60 .boolean_true = true,
61 .boolean_false = false,
62 .uint_64 = 42,
63 .int_64 = -42,
64 .string = "meson",
65 .ident = .meson,
66 .not_defined = null,
67 .is_defined = {},
68 },
69 );
70 const check_config_header_meson = b.addCheckFile(config_header_meson.getOutputFile(), .{
71 .expected_exact = @embedFile("meson/mesondefine.h"),
72 });
73 test_step.dependOn(&check_config_header_meson.step);
74
75 const config_header_blank = b.addConfigHeader(
76 .{
77 .style = .blank,
78 .include_path = "config.h",
79 },
80 .{
81 .UNDEFINED = null,
82 .DEFINED = {},
83 .TRUE = true,
84 .FALSE = false,
85 .ZERO = 0,
86 .ONE = 1,
87 .TEN = 10,
88 .IDENT = @as(enum { identifier }, .identifier),
89 .STRING = "test",
90 },
91 );
92 const check_config_header_blank = b.addCheckFile(config_header_blank.getOutputFile(), .{
93 .expected_exact = @embedFile("blank/config.h"),
94 });
95 test_step.dependOn(&check_config_header_blank.step);
96
97 const config_header_nasm = b.addConfigHeader(
98 .{
99 .style = .nasm,
100 .include_path = "config.asm",
101 },
102 .{
103 .UNDEFINED = null,
104 .DEFINED = {},
105 .TRUE = true,
106 .FALSE = false,
107 .ZERO = 0,
108 .ONE = 1,
109 .TEN = 10,
110 .IDENT = @as(enum { identifier }, .identifier),
111 .STRING = "test",
112 },
113 );
114 const check_config_header_nasm = b.addCheckFile(config_header_nasm.getOutputFile(), .{
115 .expected_exact = @embedFile("nasm/config.asm"),
116 });
117 test_step.dependOn(&check_config_header_nasm.step);
118
119 addCmakeChecks(b, test_step);
120}
121
122fn addCmakeChecks(b: *std.Build, test_step: *std.Build.Step) void {
123 const config_header = b.addConfigHeader(
124 .{ .style = .{ .cmake = b.path("cmake/config.h.in") } },
125 .{
126 .NOVAL = null,
127 .TRUEVAL = true,
128 .FALSEVAL = false,
129 .ZEROVAL = 0,
130 .ONEVAL = 1,
131 .TENVAL = 10,
132 .STRINGVAL = "test",
133 .BOOLNOVAL = {},
134 .BOOLTRUEVAL = true,
135 .BOOLFALSEVAL = false,
136 .BOOLZEROVAL = 0,
137 .BOOLONEVAL = 1,
138 .BOOLTENVAL = 10,
139 .BOOLSTRINGVAL = "test",
140 },
141 );
142 const check_config_header = b.addCheckFile(config_header.getOutputFile(), .{
143 .expected_exact = @embedFile("cmake/config.h"),
144 });
145 test_step.dependOn(&check_config_header.step);
146
147 const pwd_sh = b.addConfigHeader(
148 .{ .style = .{ .cmake = b.path("cmake/pwd.sh.in") } },
149 .{ .DIR = "${PWD}" },
150 );
151 const check_pwd_sh = b.addCheckFile(pwd_sh.getOutputFile(), .{
152 .expected_exact = @embedFile("cmake/pwd.sh"),
153 });
154 test_step.dependOn(&check_pwd_sh.step);
155
156 const config_header_edge_cases = b.addConfigHeader(
157 .{ .style = .{ .cmake = b.path("cmake/edge_cases.h.in") } },
158 .{
159 .DOLLAR = "$",
160 .UNDERSCORE = "_",
161 .STRING = "text",
162 .STRING_PROXY = "STRING",
163 .STRING_AT = "@STRING@",
164 .STRING_CURLY = "{STRING}",
165 .STRING_VAR = "${STRING}",
166 .NEST_UNDERSCORE_PROXY = "UNDERSCORE",
167 .NEST_PROXY = "NEST_UNDERSCORE_PROXY",
168 },
169 );
170 const check_config_header_edge_cases = b.addCheckFile(config_header_edge_cases.getOutputFile(), .{
171 .expected_exact = @embedFile("cmake/edge_cases.h"),
172 });
173 test_step.dependOn(&check_config_header_edge_cases.step);
174
175 const config_header_cmakedefine_edge_cases = b.addConfigHeader(
176 .{
177 .style = .{ .cmake = b.path("cmake/cmakedefine_edge_cases.h.in") },
178 .include_path = "cmakedefine_edge_cases_renamed.h",
179 },
180 .{
181 .MULTI_WORD = true,
182 .MULTI_WORD_FALSE = false,
183 .NO_VALUE = true,
184 .NO_VALUE_FALSE = false,
185 .WITH_UNDERSCORE_TRUE = true,
186 .WITH_UNDERSCORE_FALSE = false,
187 ._LEADING = true,
188 .TRAILING_ = true,
189 ._UNDER_01 = true,
190 .UNDER_01_ = true,
191 .SUBST_VAL = true,
192 .SUBST_VAL_FALSE = false,
193 .STRING = "text",
194 .VAR_NAME = "ACTUAL_VAR",
195 .ACTUAL_VAR = true,
196 .AT_SIGN = "@",
197 .DOLLAR_SIGN = "$",
198 },
199 );
200 const check_config_header_cmakedefine_edge_cases = b.addCheckFile(config_header_cmakedefine_edge_cases.getOutputFile(), .{
201 .expected_exact = @embedFile("cmake/cmakedefine_edge_cases.h"),
202 });
203 test_step.dependOn(&check_config_header_cmakedefine_edge_cases.step);
204}