Skip to content

Commit 8519fa8

Browse files
committed
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.
1 parent f335370 commit 8519fa8

File tree

6 files changed

+221
-224
lines changed

6 files changed

+221
-224
lines changed

build.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,6 @@ pub fn build(b: *std.Build) !void {
508508
optimization_modes,
509509
enable_macos_sdk,
510510
enable_ios_sdk,
511-
false,
512511
enable_symlinks_windows,
513512
));
514513
test_step.dependOn(tests.addCAbiTests(b, skip_non_native, skip_release));

build.zig.zon

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 0 additions & 198 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ pub const SimpleCase = struct {
99
os_filter: ?std.Target.Os.Tag = null,
1010
};
1111

12-
pub const BuildCase = struct {
13-
build_root: []const u8,
14-
import: type,
15-
};
16-
1712
pub const simple_cases = [_]SimpleCase{
1813
.{
1914
.src_path = "test/standalone/hello_world/hello.zig",
@@ -74,197 +69,4 @@ pub const simple_cases = [_]SimpleCase{
7469
.{ .src_path = "tools/update_spirv_features.zig" },
7570
};
7671

77-
pub const build_cases = [_]BuildCase{
78-
.{
79-
.build_root = "test/standalone/test_runner_path",
80-
.import = @import("standalone/test_runner_path/build.zig"),
81-
},
82-
.{
83-
.build_root = "test/standalone/test_runner_module_imports",
84-
.import = @import("standalone/test_runner_module_imports/build.zig"),
85-
},
86-
// https://github.com/ziglang/zig/issues/17483
87-
//.{
88-
// .build_root = "test/standalone/issue_13970",
89-
// .import = @import("standalone/issue_13970/build.zig"),
90-
//},
91-
.{
92-
.build_root = "test/standalone/shared_library",
93-
.import = @import("standalone/shared_library/build.zig"),
94-
},
95-
.{
96-
.build_root = "test/standalone/mix_o_files",
97-
.import = @import("standalone/mix_o_files/build.zig"),
98-
},
99-
.{
100-
.build_root = "test/standalone/mix_c_files",
101-
.import = @import("standalone/mix_c_files/build.zig"),
102-
},
103-
.{
104-
.build_root = "test/standalone/global_linkage",
105-
.import = @import("standalone/global_linkage/build.zig"),
106-
},
107-
.{
108-
.build_root = "test/standalone/static_c_lib",
109-
.import = @import("standalone/static_c_lib/build.zig"),
110-
},
111-
.{
112-
.build_root = "test/standalone/issue_339",
113-
.import = @import("standalone/issue_339/build.zig"),
114-
},
115-
.{
116-
.build_root = "test/standalone/issue_8550",
117-
.import = @import("standalone/issue_8550/build.zig"),
118-
},
119-
.{
120-
.build_root = "test/standalone/issue_794",
121-
.import = @import("standalone/issue_794/build.zig"),
122-
},
123-
.{
124-
.build_root = "test/standalone/issue_5825",
125-
.import = @import("standalone/issue_5825/build.zig"),
126-
},
127-
.{
128-
.build_root = "test/standalone/pkg_import",
129-
.import = @import("standalone/pkg_import/build.zig"),
130-
},
131-
.{
132-
.build_root = "test/standalone/use_alias",
133-
.import = @import("standalone/use_alias/build.zig"),
134-
},
135-
.{
136-
.build_root = "test/standalone/install_raw_hex",
137-
.import = @import("standalone/install_raw_hex/build.zig"),
138-
},
139-
// https://github.com/ziglang/zig/issues/17484
140-
//.{
141-
// .build_root = "test/standalone/emit_asm_and_bin",
142-
// .import = @import("standalone/emit_asm_and_bin/build.zig"),
143-
//},
144-
// https://github.com/ziglang/zig/issues/17484
145-
//.{
146-
// .build_root = "test/standalone/issue_12588",
147-
// .import = @import("standalone/issue_12588/build.zig"),
148-
//},
149-
.{
150-
.build_root = "test/standalone/child_process",
151-
.import = @import("standalone/child_process/build.zig"),
152-
},
153-
.{
154-
.build_root = "test/standalone/embed_generated_file",
155-
.import = @import("standalone/embed_generated_file/build.zig"),
156-
},
157-
.{
158-
.build_root = "test/standalone/extern",
159-
.import = @import("standalone/extern/build.zig"),
160-
},
161-
.{
162-
.build_root = "test/standalone/dep_diamond",
163-
.import = @import("standalone/dep_diamond/build.zig"),
164-
},
165-
.{
166-
.build_root = "test/standalone/dep_triangle",
167-
.import = @import("standalone/dep_triangle/build.zig"),
168-
},
169-
.{
170-
.build_root = "test/standalone/dep_recursive",
171-
.import = @import("standalone/dep_recursive/build.zig"),
172-
},
173-
.{
174-
.build_root = "test/standalone/dep_mutually_recursive",
175-
.import = @import("standalone/dep_mutually_recursive/build.zig"),
176-
},
177-
.{
178-
.build_root = "test/standalone/dep_shared_builtin",
179-
.import = @import("standalone/dep_shared_builtin/build.zig"),
180-
},
181-
.{
182-
.build_root = "test/standalone/dirname",
183-
.import = @import("standalone/dirname/build.zig"),
184-
},
185-
.{
186-
.build_root = "test/standalone/empty_env",
187-
.import = @import("standalone/empty_env/build.zig"),
188-
},
189-
.{
190-
.build_root = "test/standalone/issue_11595",
191-
.import = @import("standalone/issue_11595/build.zig"),
192-
},
193-
.{
194-
.build_root = "test/standalone/load_dynamic_library",
195-
.import = @import("standalone/load_dynamic_library/build.zig"),
196-
},
197-
.{
198-
.build_root = "test/standalone/windows_resources",
199-
.import = @import("standalone/windows_resources/build.zig"),
200-
},
201-
.{
202-
.build_root = "test/standalone/windows_spawn",
203-
.import = @import("standalone/windows_spawn/build.zig"),
204-
},
205-
.{
206-
.build_root = "test/standalone/self_exe_symlink",
207-
.import = @import("standalone/self_exe_symlink/build.zig"),
208-
},
209-
.{
210-
.build_root = "test/standalone/c_compiler",
211-
.import = @import("standalone/c_compiler/build.zig"),
212-
},
213-
.{
214-
.build_root = "test/standalone/pie",
215-
.import = @import("standalone/pie/build.zig"),
216-
},
217-
.{
218-
.build_root = "test/standalone/issue_12706",
219-
.import = @import("standalone/issue_12706/build.zig"),
220-
},
221-
// TODO This test is disabled for doing naughty things in the build script.
222-
// The logic needs to get moved to a child process instead of build.zig.
223-
//.{
224-
// .build_root = "test/standalone/sigpipe",
225-
// .import = @import("standalone/sigpipe/build.zig"),
226-
//},
227-
// TODO restore this test
228-
//.{
229-
// .build_root = "test/standalone/options",
230-
// .import = @import("standalone/options/build.zig"),
231-
//},
232-
.{
233-
.build_root = "test/standalone/strip_empty_loop",
234-
.import = @import("standalone/strip_empty_loop/build.zig"),
235-
},
236-
.{
237-
.build_root = "test/standalone/strip_struct_init",
238-
.import = @import("standalone/strip_struct_init/build.zig"),
239-
},
240-
.{
241-
.build_root = "test/standalone/cmakedefine",
242-
.import = @import("standalone/cmakedefine/build.zig"),
243-
},
244-
.{
245-
.build_root = "test/standalone/zerolength_check",
246-
.import = @import("standalone/zerolength_check/build.zig"),
247-
},
248-
.{
249-
.build_root = "test/standalone/stack_iterator",
250-
.import = @import("standalone/stack_iterator/build.zig"),
251-
},
252-
.{
253-
.build_root = "test/standalone/coff_dwarf",
254-
.import = @import("standalone/coff_dwarf/build.zig"),
255-
},
256-
.{
257-
.build_root = "test/standalone/compiler_rt_panic",
258-
.import = @import("standalone/compiler_rt_panic/build.zig"),
259-
},
260-
.{
261-
.build_root = "test/standalone/ios",
262-
.import = @import("standalone/ios/build.zig"),
263-
},
264-
.{
265-
.build_root = "test/standalone/depend_on_main_mod",
266-
.import = @import("standalone/depend_on_main_mod/build.zig"),
267-
},
268-
};
269-
27072
const std = @import("std");

test/standalone/build.zig

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
const std = @import("std");
2+
const builtin = @import("builtin");
3+
4+
pub 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+
}

0 commit comments

Comments
 (0)