authorgravatar for carl@astholm.seCarl Åstholm <carl@astholm.se> 2024-01-16 17:54:57+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-04-07 16:05:53-07:00
log3ed221f1494be00cc802515e33e18fdd80d41afb
tree34d146a732d76cc3aac63e57f648c1228f240f74
parent05126fc4c575b833e772239426f31af23eba0d20

Promote standalone test cases to packages

This is a prerequisite for removing `b.anonymousDependency()`, but having compiler tests dogfood package management might be a good idea in general.

6 files changed, 227 insertions(+), 232 deletions(-)

build.zig-1
...@@ -521,7 +521,6 @@ pub fn build(b: *std.Build) !void {...@@ -521,7 +521,6 @@ pub fn build(b: *std.Build) !void {
521 optimization_modes,521 optimization_modes,
522 enable_macos_sdk,522 enable_macos_sdk,
523 enable_ios_sdk,523 enable_ios_sdk,
524 false,
525 enable_symlinks_windows,524 enable_symlinks_windows,
526 ));525 ));
527 test_step.dependOn(tests.addCAbiTests(b, skip_non_native, skip_release));526 test_step.dependOn(tests.addCAbiTests(b, skip_non_native, skip_release));
build.zig.zon created+12
...@@ -0,0 +1,12 @@
1// The Zig compiler is not intended to be consumed as a package.
2// The sole purpose of this manifest file is to test the compiler.
3.{
4 .name = "zig",
5 .version = "0.0.0",
6 .dependencies = .{
7 .standalone_test_cases = .{
8 .path = "test/standalone",
9 },
10 },
11 .paths = .{""},
12}
test/standalone.zig-206
...@@ -9,11 +9,6 @@ pub const SimpleCase = struct {...@@ -9,11 +9,6 @@ pub const SimpleCase = struct {
9 os_filter: ?std.Target.Os.Tag = null,9 os_filter: ?std.Target.Os.Tag = null,
10};10};
1111
12pub const BuildCase = struct {
13 build_root: []const u8,
14 import: type,
15};
16
17pub const simple_cases = [_]SimpleCase{12pub const simple_cases = [_]SimpleCase{
18 .{13 .{
19 .src_path = "test/standalone/hello_world/hello.zig",14 .src_path = "test/standalone/hello_world/hello.zig",
...@@ -71,205 +66,4 @@ pub const simple_cases = [_]SimpleCase{...@@ -71,205 +66,4 @@ pub const simple_cases = [_]SimpleCase{
71 .{ .src_path = "tools/update_spirv_features.zig" },66 .{ .src_path = "tools/update_spirv_features.zig" },
72};67};
7368
74pub const build_cases = [_]BuildCase{
75 .{
76 .build_root = "test/standalone/test_runner_path",
77 .import = @import("standalone/test_runner_path/build.zig"),
78 },
79 .{
80 .build_root = "test/standalone/test_runner_module_imports",
81 .import = @import("standalone/test_runner_module_imports/build.zig"),
82 },
83 // https://github.com/ziglang/zig/issues/17483
84 //.{
85 // .build_root = "test/standalone/issue_13970",
86 // .import = @import("standalone/issue_13970/build.zig"),
87 //},
88 .{
89 .build_root = "test/standalone/shared_library",
90 .import = @import("standalone/shared_library/build.zig"),
91 },
92 .{
93 .build_root = "test/standalone/mix_o_files",
94 .import = @import("standalone/mix_o_files/build.zig"),
95 },
96 .{
97 .build_root = "test/standalone/mix_c_files",
98 .import = @import("standalone/mix_c_files/build.zig"),
99 },
100 .{
101 .build_root = "test/standalone/global_linkage",
102 .import = @import("standalone/global_linkage/build.zig"),
103 },
104 .{
105 .build_root = "test/standalone/static_c_lib",
106 .import = @import("standalone/static_c_lib/build.zig"),
107 },
108 .{
109 .build_root = "test/standalone/issue_339",
110 .import = @import("standalone/issue_339/build.zig"),
111 },
112 .{
113 .build_root = "test/standalone/issue_8550",
114 .import = @import("standalone/issue_8550/build.zig"),
115 },
116 .{
117 .build_root = "test/standalone/issue_794",
118 .import = @import("standalone/issue_794/build.zig"),
119 },
120 .{
121 .build_root = "test/standalone/issue_5825",
122 .import = @import("standalone/issue_5825/build.zig"),
123 },
124 .{
125 .build_root = "test/standalone/pkg_import",
126 .import = @import("standalone/pkg_import/build.zig"),
127 },
128 .{
129 .build_root = "test/standalone/use_alias",
130 .import = @import("standalone/use_alias/build.zig"),
131 },
132 .{
133 .build_root = "test/standalone/install_raw_hex",
134 .import = @import("standalone/install_raw_hex/build.zig"),
135 },
136 // https://github.com/ziglang/zig/issues/17484
137 //.{
138 // .build_root = "test/standalone/emit_asm_and_bin",
139 // .import = @import("standalone/emit_asm_and_bin/build.zig"),
140 //},
141 // https://github.com/ziglang/zig/issues/17484
142 //.{
143 // .build_root = "test/standalone/issue_12588",
144 // .import = @import("standalone/issue_12588/build.zig"),
145 //},
146 .{
147 .build_root = "test/standalone/child_process",
148 .import = @import("standalone/child_process/build.zig"),
149 },
150 .{
151 .build_root = "test/standalone/embed_generated_file",
152 .import = @import("standalone/embed_generated_file/build.zig"),
153 },
154 .{
155 .build_root = "test/standalone/extern",
156 .import = @import("standalone/extern/build.zig"),
157 },
158 .{
159 .build_root = "test/standalone/dep_diamond",
160 .import = @import("standalone/dep_diamond/build.zig"),
161 },
162 .{
163 .build_root = "test/standalone/dep_triangle",
164 .import = @import("standalone/dep_triangle/build.zig"),
165 },
166 .{
167 .build_root = "test/standalone/dep_recursive",
168 .import = @import("standalone/dep_recursive/build.zig"),
169 },
170 .{
171 .build_root = "test/standalone/dep_mutually_recursive",
172 .import = @import("standalone/dep_mutually_recursive/build.zig"),
173 },
174 .{
175 .build_root = "test/standalone/dep_shared_builtin",
176 .import = @import("standalone/dep_shared_builtin/build.zig"),
177 },
178 .{
179 .build_root = "test/standalone/dirname",
180 .import = @import("standalone/dirname/build.zig"),
181 },
182 .{
183 .build_root = "test/standalone/empty_env",
184 .import = @import("standalone/empty_env/build.zig"),
185 },
186 .{
187 .build_root = "test/standalone/issue_11595",
188 .import = @import("standalone/issue_11595/build.zig"),
189 },
190 .{
191 .build_root = "test/standalone/load_dynamic_library",
192 .import = @import("standalone/load_dynamic_library/build.zig"),
193 },
194 .{
195 .build_root = "test/standalone/windows_resources",
196 .import = @import("standalone/windows_resources/build.zig"),
197 },
198 .{
199 .build_root = "test/standalone/windows_entry_points",
200 .import = @import("standalone/windows_entry_points/build.zig"),
201 },
202 .{
203 .build_root = "test/standalone/windows_spawn",
204 .import = @import("standalone/windows_spawn/build.zig"),
205 },
206 .{
207 .build_root = "test/standalone/self_exe_symlink",
208 .import = @import("standalone/self_exe_symlink/build.zig"),
209 },
210 .{
211 .build_root = "test/standalone/c_compiler",
212 .import = @import("standalone/c_compiler/build.zig"),
213 },
214 .{
215 .build_root = "test/standalone/pie",
216 .import = @import("standalone/pie/build.zig"),
217 },
218 .{
219 .build_root = "test/standalone/issue_12706",
220 .import = @import("standalone/issue_12706/build.zig"),
221 },
222 // TODO This test is disabled for doing naughty things in the build script.
223 // The logic needs to get moved to a child process instead of build.zig.
224 //.{
225 // .build_root = "test/standalone/sigpipe",
226 // .import = @import("standalone/sigpipe/build.zig"),
227 //},
228 // TODO restore this test
229 //.{
230 // .build_root = "test/standalone/options",
231 // .import = @import("standalone/options/build.zig"),
232 //},
233 .{
234 .build_root = "test/standalone/strip_empty_loop",
235 .import = @import("standalone/strip_empty_loop/build.zig"),
236 },
237 .{
238 .build_root = "test/standalone/strip_struct_init",
239 .import = @import("standalone/strip_struct_init/build.zig"),
240 },
241 .{
242 .build_root = "test/standalone/cmakedefine",
243 .import = @import("standalone/cmakedefine/build.zig"),
244 },
245 .{
246 .build_root = "test/standalone/zerolength_check",
247 .import = @import("standalone/zerolength_check/build.zig"),
248 },
249 .{
250 .build_root = "test/standalone/stack_iterator",
251 .import = @import("standalone/stack_iterator/build.zig"),
252 },
253 .{
254 .build_root = "test/standalone/coff_dwarf",
255 .import = @import("standalone/coff_dwarf/build.zig"),
256 },
257 .{
258 .build_root = "test/standalone/compiler_rt_panic",
259 .import = @import("standalone/compiler_rt_panic/build.zig"),
260 },
261 .{
262 .build_root = "test/standalone/ios",
263 .import = @import("standalone/ios/build.zig"),
264 },
265 .{
266 .build_root = "test/standalone/depend_on_main_mod",
267 .import = @import("standalone/depend_on_main_mod/build.zig"),
268 },
269 .{
270 .build_root = "test/standalone/install_headers",
271 .import = @import("standalone/install_headers/build.zig"),
272 },
273};
274
275const std = @import("std");69const std = @import("std");
test/standalone/build.zig created+46
...@@ -0,0 +1,46 @@
1const std = @import("std");
2const builtin = @import("builtin");
3
4pub fn build(b: *std.Build) void {
5 const step = b.step("test", "Run standalone test cases");
6 b.default_step = step;
7
8 const enable_ios_sdk = b.option(bool, "enable-ios-sdk", "Run tests requiring presence of iOS SDK and frameworks") orelse false;
9 const enable_macos_sdk = b.option(bool, "enable-macos-sdk", "Run tests requiring presence of macOS SDK and frameworks") orelse enable_ios_sdk;
10 const enable_symlinks_windows = b.option(bool, "enable-symlinks-windows", "Run tests requiring presence of symlinks on Windows") orelse false;
11
12 const omit_symlinks = builtin.os.tag == .windows and !enable_symlinks_windows;
13
14 add_dep_steps: for (b.available_deps) |available_dep| {
15 const dep_name, const dep_hash = available_dep;
16
17 const all_pkgs = @import("root").dependencies.packages;
18 inline for (@typeInfo(all_pkgs).Struct.decls) |decl| {
19 const pkg_hash = decl.name;
20 if (std.mem.eql(u8, dep_hash, pkg_hash)) {
21 const pkg = @field(all_pkgs, pkg_hash);
22 if (!@hasDecl(pkg, "build_zig")) {
23 std.debug.panic("standalone test case '{s}' is missing a 'build.zig' file", .{dep_name});
24 }
25 const requires_ios_sdk = @hasDecl(pkg.build_zig, "requires_ios_sdk") and
26 pkg.build_zig.requires_ios_sdk;
27 const requires_macos_sdk = @hasDecl(pkg.build_zig, "requires_macos_sdk") and
28 pkg.build_zig.requires_macos_sdk;
29 const requires_symlinks = @hasDecl(pkg.build_zig, "requires_symlinks") and
30 pkg.build_zig.requires_symlinks;
31 if ((requires_symlinks and omit_symlinks) or
32 (requires_macos_sdk and !enable_macos_sdk) or
33 (requires_ios_sdk and !enable_ios_sdk))
34 {
35 continue :add_dep_steps;
36 }
37 break;
38 }
39 } else unreachable;
40
41 const dep = b.dependency(dep_name, .{});
42 const dep_step = dep.builder.default_step;
43 dep_step.name = b.fmt("standalone_test_cases.{s}", .{dep_name});
44 step.dependOn(dep_step);
45 }
46}
test/standalone/build.zig.zon created+160
...@@ -0,0 +1,160 @@
1.{
2 .name = "standalone_test_cases",
3 .version = "0.0.0",
4 .dependencies = .{
5 .test_runner_path = .{
6 .path = "test_runner_path",
7 },
8 .test_runner_module_imports = .{
9 .path = "test_runner_module_imports",
10 },
11 // https://github.com/ziglang/zig/issues/17483
12 //.issue_13970 = .{
13 // .path = "issue_13970",
14 //},
15 .shared_library = .{
16 .path = "shared_library",
17 },
18 .mix_o_files = .{
19 .path = "mix_o_files",
20 },
21 .mix_c_files = .{
22 .path = "mix_c_files",
23 },
24 .global_linkage = .{
25 .path = "global_linkage",
26 },
27 .static_c_lib = .{
28 .path = "static_c_lib",
29 },
30 .issue_339 = .{
31 .path = "issue_339",
32 },
33 .issue_8550 = .{
34 .path = "issue_8550",
35 },
36 .issue_794 = .{
37 .path = "issue_794",
38 },
39 .issue_5825 = .{
40 .path = "issue_5825",
41 },
42 .pkg_import = .{
43 .path = "pkg_import",
44 },
45 .use_alias = .{
46 .path = "use_alias",
47 },
48 .install_raw_hex = .{
49 .path = "install_raw_hex",
50 },
51 // https://github.com/ziglang/zig/issues/17484
52 //.emit_asm_and_bin = .{
53 // .path = "emit_asm_and_bin",
54 //},
55 // https://github.com/ziglang/zig/issues/17484
56 //.issue_12588 = .{
57 // .path = "issue_12588",
58 //},
59 .child_process = .{
60 .path = "child_process",
61 },
62 .embed_generated_file = .{
63 .path = "embed_generated_file",
64 },
65 .@"extern" = .{
66 .path = "extern",
67 },
68 .dep_diamond = .{
69 .path = "dep_diamond",
70 },
71 .dep_triangle = .{
72 .path = "dep_triangle",
73 },
74 .dep_recursive = .{
75 .path = "dep_recursive",
76 },
77 .dep_mutually_recursive = .{
78 .path = "dep_mutually_recursive",
79 },
80 .dep_shared_builtin = .{
81 .path = "dep_shared_builtin",
82 },
83 .dirname = .{
84 .path = "dirname",
85 },
86 .empty_env = .{
87 .path = "empty_env",
88 },
89 .issue_11595 = .{
90 .path = "issue_11595",
91 },
92 .load_dynamic_library = .{
93 .path = "load_dynamic_library",
94 },
95 .windows_resources = .{
96 .path = "windows_resources",
97 },
98 .windows_entry_points = .{
99 .path = "windows_entry_points",
100 },
101 .windows_spawn = .{
102 .path = "windows_spawn",
103 },
104 .self_exe_symlink = .{
105 .path = "self_exe_symlink",
106 },
107 .c_compiler = .{
108 .path = "c_compiler",
109 },
110 .pie = .{
111 .path = "pie",
112 },
113 .issue_12706 = .{
114 .path = "issue_12706",
115 },
116 // TODO This test is disabled for doing naughty things in the build script.
117 // The logic needs to get moved to a child process instead of build.zig.
118 //.sigpipe = .{
119 // .path = "sigpipe",
120 //},
121 // TODO restore this test
122 //.options = .{
123 // .path = "options",
124 //},
125 .strip_empty_loop = .{
126 .path = "strip_empty_loop",
127 },
128 .strip_struct_init = .{
129 .path = "strip_struct_init",
130 },
131 .cmakedefine = .{
132 .path = "cmakedefine",
133 },
134 .zerolength_check = .{
135 .path = "zerolength_check",
136 },
137 .stack_iterator = .{
138 .path = "stack_iterator",
139 },
140 .coff_dwarf = .{
141 .path = "coff_dwarf",
142 },
143 .compiler_rt_panic = .{
144 .path = "compiler_rt_panic",
145 },
146 .ios = .{
147 .path = "ios",
148 },
149 .depend_on_main_mod = .{
150 .path = "depend_on_main_mod",
151 },
152 .install_headers = .{
153 .path = "install_headers",
154 },
155 },
156 .paths = .{
157 "build.zig",
158 "build.zig.zon",
159 },
160}
test/tests.zig+9-25
...@@ -668,11 +668,9 @@ pub fn addStandaloneTests(...@@ -668,11 +668,9 @@ pub fn addStandaloneTests(
668 optimize_modes: []const OptimizeMode,668 optimize_modes: []const OptimizeMode,
669 enable_macos_sdk: bool,669 enable_macos_sdk: bool,
670 enable_ios_sdk: bool,670 enable_ios_sdk: bool,
671 omit_stage2: bool,
672 enable_symlinks_windows: bool,671 enable_symlinks_windows: bool,
673) *Step {672) *Step {
674 const step = b.step("test-standalone", "Run the standalone tests");673 const step = b.step("test-standalone", "Run the standalone tests");
675 const omit_symlinks = builtin.os.tag == .windows and !enable_symlinks_windows;
676674
677 for (standalone.simple_cases) |case| {675 for (standalone.simple_cases) |case| {
678 for (optimize_modes) |optimize| {676 for (optimize_modes) |optimize| {
...@@ -712,29 +710,15 @@ pub fn addStandaloneTests(...@@ -712,29 +710,15 @@ pub fn addStandaloneTests(
712 }710 }
713 }711 }
714712
715 inline for (standalone.build_cases) |case| {713 const test_cases_dep_name = "standalone_test_cases";
716 const requires_stage2 = @hasDecl(case.import, "requires_stage2") and714 const test_cases_dep = b.dependency(test_cases_dep_name, .{
717 case.import.requires_stage2;715 .@"enable-ios-sdk" = enable_ios_sdk,
718 const requires_symlinks = @hasDecl(case.import, "requires_symlinks") and716 .@"enable-macos-sdk" = enable_macos_sdk,
719 case.import.requires_symlinks;717 .@"enable-symlinks-windows" = enable_symlinks_windows,
720 const requires_macos_sdk = @hasDecl(case.import, "requires_macos_sdk") and718 });
721 case.import.requires_macos_sdk;719 const test_cases_dep_step = test_cases_dep.builder.default_step;
722 const requires_ios_sdk = @hasDecl(case.import, "requires_ios_sdk") and720 test_cases_dep_step.name = b.dupe(test_cases_dep_name);
723 case.import.requires_ios_sdk;721 step.dependOn(test_cases_dep.builder.default_step);
724 const bad =
725 (requires_stage2 and omit_stage2) or
726 (requires_symlinks and omit_symlinks) or
727 (requires_macos_sdk and !enable_macos_sdk) or
728 (requires_ios_sdk and !enable_ios_sdk);
729 if (!bad) {
730 const dep = b.anonymousDependency(case.build_root, case.import, .{});
731 const dep_step = dep.builder.default_step;
732 assert(mem.startsWith(u8, dep.builder.dep_prefix, "test."));
733 const dep_prefix_adjusted = dep.builder.dep_prefix["test.".len..];
734 dep_step.name = b.fmt("{s}{s}", .{ dep_prefix_adjusted, dep_step.name });
735 step.dependOn(dep_step);
736 }
737 }
738722
739 return step;723 return step;
740}724}