authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-07-23 23:45:31-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-07-23 23:48:19-04:00
logc610cde1eb460ddf80910f34e19c8a68d1bc86a9
tree7ddba1eab424cc3c6c26d30d4d73cbb570e7d666
parent06af9cc101d0e688f7c6a1c2cc009b917f0a7bdf

test: test for issues starting codegen on many targets

Specifically this is to make sure llvm data layout generation doesn't regress. The no emit bin is to allow testing targets that can't currently be linked. The commented out targets are ones that fail in the linker anyway when no emit bin is passed.

7 files changed, 144 insertions(+), 6 deletions(-)

lib/std/Build/Step.zig+3-1
......@@ -294,7 +294,7 @@ pub fn evalZigProcess(
294294 s: *Step,
295295 argv: []const []const u8,
296296 prog_node: *std.Progress.Node,
297) ![]const u8 {
297) !?[]const u8 {
298298 assert(argv.len != 0);
299299 const b = s.owner;
300300 const arena = b.allocator;
......@@ -423,6 +423,8 @@ pub fn evalZigProcess(
423423 });
424424 }
425425
426 if (s.cast(Compile)) |compile| if (compile.emit_bin == .no_emit) return result;
427
426428 return result orelse return s.fail(
427429 "the following command failed to communicate the compilation result:\n{s}",
428430 .{try allocPrintCmd(arena, null, argv)},
lib/std/Build/Step/Compile.zig+4-3
......@@ -1997,7 +1997,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
19971997 try zig_args.append(resolved_args_file);
19981998 }
19991999
2000 const output_bin_path = step.evalZigProcess(zig_args.items, prog_node) catch |err| switch (err) {
2000 const maybe_output_bin_path = step.evalZigProcess(zig_args.items, prog_node) catch |err| switch (err) {
20012001 error.NeedCompileErrorCheck => {
20022002 assert(self.expect_errors.len != 0);
20032003 try checkCompileErrors(self);
......@@ -2005,10 +2005,11 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
20052005 },
20062006 else => |e| return e,
20072007 };
2008 const output_dir = fs.path.dirname(output_bin_path).?;
20092008
20102009 // Update generated files
2011 {
2010 if (maybe_output_bin_path) |output_bin_path| {
2011 const output_dir = fs.path.dirname(output_bin_path).?;
2012
20122013 self.output_dirname_source.path = output_dir;
20132014
20142015 self.output_path_source.path = b.pathJoin(
lib/std/Build/Step/TranslateC.zig+2-2
......@@ -148,8 +148,8 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
148148
149149 const output_path = try step.evalZigProcess(argv_list.items, prog_node);
150150
151 self.out_basename = fs.path.basename(output_path);
152 const output_dir = fs.path.dirname(output_path).?;
151 self.out_basename = fs.path.basename(output_path.?);
152 const output_dir = fs.path.dirname(output_path.?).?;
153153
154154 self.output_file.path = try fs.path.join(
155155 b.allocator,
src/Compilation.zig+1
......@@ -1053,6 +1053,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
10531053 buf.appendSliceAssumeCapacity(",");
10541054 }
10551055 }
1056 if (buf.items.len == 0) break :blk "";
10561057 assert(mem.endsWith(u8, buf.items, ","));
10571058 buf.items[buf.items.len - 1] = 0;
10581059 buf.shrinkAndFree(buf.items.len);
test/cases.zig+1
......@@ -4,5 +4,6 @@ const Cases = @import("src/Cases.zig");
44pub fn addCases(cases: *Cases) !void {
55 try @import("compile_errors.zig").addCases(cases);
66 try @import("cbe.zig").addCases(cases);
7 try @import("llvm_targets.zig").addCases(cases);
78 try @import("nvptx.zig").addCases(cases);
89}
test/llvm_targets.zig created+117
......@@ -0,0 +1,117 @@
1const std = @import("std");
2const Cases = @import("src/Cases.zig");
3
4const targets = [_]std.zig.CrossTarget{
5 .{ .cpu_arch = .aarch64, .os_tag = .freestanding, .abi = .none },
6 .{ .cpu_arch = .aarch64, .os_tag = .linux, .abi = .none },
7 .{ .cpu_arch = .aarch64, .os_tag = .macos, .abi = .none },
8 .{ .cpu_arch = .aarch64, .os_tag = .uefi, .abi = .none },
9 .{ .cpu_arch = .aarch64, .os_tag = .windows, .abi = .gnu },
10 .{ .cpu_arch = .aarch64, .os_tag = .windows, .abi = .msvc },
11 .{ .cpu_arch = .aarch64_be, .os_tag = .freestanding, .abi = .none },
12 .{ .cpu_arch = .aarch64_be, .os_tag = .linux, .abi = .none },
13 .{ .cpu_arch = .aarch64_32, .os_tag = .freestanding, .abi = .none },
14 .{ .cpu_arch = .aarch64_32, .os_tag = .linux, .abi = .none },
15 .{ .cpu_arch = .amdgcn, .os_tag = .amdhsa, .abi = .none },
16 .{ .cpu_arch = .amdgcn, .os_tag = .amdpal, .abi = .none },
17 .{ .cpu_arch = .amdgcn, .os_tag = .linux, .abi = .none },
18 //.{ .cpu_arch = .amdgcn, .os_tag = .mesa3d, .abi = .none },
19 .{ .cpu_arch = .arm, .os_tag = .freestanding, .abi = .none },
20 .{ .cpu_arch = .arm, .os_tag = .linux, .abi = .none },
21 .{ .cpu_arch = .arm, .os_tag = .uefi, .abi = .none },
22 .{ .cpu_arch = .armeb, .os_tag = .freestanding, .abi = .none },
23 .{ .cpu_arch = .armeb, .os_tag = .linux, .abi = .none },
24 .{ .cpu_arch = .avr, .os_tag = .freebsd, .abi = .none },
25 .{ .cpu_arch = .avr, .os_tag = .freestanding, .abi = .none },
26 .{ .cpu_arch = .avr, .os_tag = .linux, .abi = .none },
27 .{ .cpu_arch = .bpfel, .os_tag = .linux, .abi = .gnu },
28 .{ .cpu_arch = .bpfel, .os_tag = .linux, .abi = .none },
29 .{ .cpu_arch = .bpfeb, .os_tag = .linux, .abi = .gnu },
30 .{ .cpu_arch = .bpfeb, .os_tag = .linux, .abi = .none },
31 .{ .cpu_arch = .hexagon, .os_tag = .linux, .abi = .none },
32 .{ .cpu_arch = .mips, .os_tag = .linux, .abi = .gnueabihf },
33 .{ .cpu_arch = .mips, .os_tag = .linux, .abi = .musl },
34 .{ .cpu_arch = .mips, .os_tag = .linux, .abi = .none },
35 .{ .cpu_arch = .mipsel, .os_tag = .linux, .abi = .gnueabihf },
36 .{ .cpu_arch = .mipsel, .os_tag = .linux, .abi = .musl },
37 .{ .cpu_arch = .mipsel, .os_tag = .linux, .abi = .none },
38 .{ .cpu_arch = .mips64, .os_tag = .linux, .abi = .none },
39 .{ .cpu_arch = .mips64el, .os_tag = .linux, .abi = .none },
40 .{ .cpu_arch = .msp430, .os_tag = .freebsd, .abi = .none },
41 .{ .cpu_arch = .msp430, .os_tag = .freestanding, .abi = .none },
42 .{ .cpu_arch = .msp430, .os_tag = .linux, .abi = .none },
43 //.{ .cpu_arch = .nvptx, .os_tag = .cuda, .abi = .none },
44 //.{ .cpu_arch = .nvptx64, .os_tag = .cuda, .abi = .none },
45 .{ .cpu_arch = .powerpc, .os_tag = .freebsd, .abi = .none },
46 .{ .cpu_arch = .powerpc, .os_tag = .freestanding, .abi = .none },
47 .{ .cpu_arch = .powerpc, .os_tag = .linux, .abi = .gnueabihf },
48 .{ .cpu_arch = .powerpc, .os_tag = .linux, .abi = .musl },
49 .{ .cpu_arch = .powerpc, .os_tag = .linux, .abi = .none },
50 .{ .cpu_arch = .powerpcle, .os_tag = .freebsd, .abi = .none },
51 .{ .cpu_arch = .powerpcle, .os_tag = .freestanding, .abi = .none },
52 .{ .cpu_arch = .powerpcle, .os_tag = .linux, .abi = .gnu },
53 .{ .cpu_arch = .powerpcle, .os_tag = .linux, .abi = .musl },
54 .{ .cpu_arch = .powerpcle, .os_tag = .linux, .abi = .none },
55 .{ .cpu_arch = .powerpc64, .os_tag = .freebsd, .abi = .none },
56 .{ .cpu_arch = .powerpc64, .os_tag = .freestanding, .abi = .none },
57 .{ .cpu_arch = .powerpc64, .os_tag = .linux, .abi = .gnu },
58 .{ .cpu_arch = .powerpc64, .os_tag = .linux, .abi = .musl },
59 .{ .cpu_arch = .powerpc64, .os_tag = .linux, .abi = .none },
60 .{ .cpu_arch = .powerpc64le, .os_tag = .freebsd, .abi = .none },
61 .{ .cpu_arch = .powerpc64le, .os_tag = .freestanding, .abi = .none },
62 .{ .cpu_arch = .powerpc64le, .os_tag = .linux, .abi = .gnu },
63 .{ .cpu_arch = .powerpc64le, .os_tag = .linux, .abi = .musl },
64 .{ .cpu_arch = .powerpc64le, .os_tag = .linux, .abi = .none },
65 //.{ .cpu_arch = .r600, .os_tag = .mesa3d, .abi = .none },
66 .{ .cpu_arch = .riscv32, .os_tag = .freestanding, .abi = .none },
67 .{ .cpu_arch = .riscv32, .os_tag = .linux, .abi = .none },
68 .{ .cpu_arch = .riscv64, .os_tag = .freestanding, .abi = .none },
69 .{ .cpu_arch = .riscv64, .os_tag = .linux, .abi = .gnu },
70 .{ .cpu_arch = .riscv64, .os_tag = .linux, .abi = .musl },
71 .{ .cpu_arch = .riscv64, .os_tag = .linux, .abi = .none },
72 .{ .cpu_arch = .s390x, .os_tag = .freestanding, .abi = .none },
73 .{ .cpu_arch = .s390x, .os_tag = .linux, .abi = .gnu },
74 .{ .cpu_arch = .sparc, .os_tag = .freestanding, .abi = .none },
75 .{ .cpu_arch = .sparc, .os_tag = .linux, .abi = .gnu },
76 .{ .cpu_arch = .sparc, .os_tag = .linux, .abi = .none },
77 .{ .cpu_arch = .sparcel, .os_tag = .freestanding, .abi = .none },
78 .{ .cpu_arch = .sparcel, .os_tag = .linux, .abi = .gnu },
79 .{ .cpu_arch = .sparc64, .os_tag = .freestanding, .abi = .none },
80 .{ .cpu_arch = .sparc64, .os_tag = .linux, .abi = .gnu },
81 //.{ .cpu_arch = .spirv32, .os_tag = .opencl, .abi = .none },
82 //.{ .cpu_arch = .spirv32, .os_tag = .glsl450, .abi = .none },
83 //.{ .cpu_arch = .spirv32, .os_tag = .vulkan, .abi = .none },
84 //.{ .cpu_arch = .spirv64, .os_tag = .opencl, .abi = .none },
85 //.{ .cpu_arch = .spirv64, .os_tag = .glsl450, .abi = .none },
86 //.{ .cpu_arch = .spirv64, .os_tag = .vulkan, .abi = .none },
87 .{ .cpu_arch = .thumb, .os_tag = .freestanding, .abi = .none },
88 .{ .cpu_arch = .thumbeb, .os_tag = .freestanding, .abi = .none },
89 .{ .cpu_arch = .ve, .os_tag = .linux, .abi = .none },
90 .{ .cpu_arch = .wasm32, .os_tag = .emscripten, .abi = .none },
91 .{ .cpu_arch = .wasm32, .os_tag = .freestanding, .abi = .none },
92 .{ .cpu_arch = .wasm32, .os_tag = .linux, .abi = .none },
93 .{ .cpu_arch = .wasm32, .os_tag = .wasi, .abi = .none },
94 .{ .cpu_arch = .wasm64, .os_tag = .emscripten, .abi = .none },
95 .{ .cpu_arch = .wasm64, .os_tag = .freestanding, .abi = .none },
96 .{ .cpu_arch = .wasm64, .os_tag = .linux, .abi = .none },
97 .{ .cpu_arch = .wasm64, .os_tag = .wasi, .abi = .none },
98 .{ .cpu_arch = .x86, .os_tag = .freestanding, .abi = .none },
99 .{ .cpu_arch = .x86, .os_tag = .linux, .abi = .none },
100 .{ .cpu_arch = .x86, .os_tag = .uefi, .abi = .none },
101 .{ .cpu_arch = .x86, .os_tag = .windows, .abi = .gnu },
102 .{ .cpu_arch = .x86, .os_tag = .windows, .abi = .msvc },
103 .{ .cpu_arch = .x86_64, .os_tag = .freebsd, .abi = .none },
104 .{ .cpu_arch = .x86_64, .os_tag = .freestanding, .abi = .none },
105 .{ .cpu_arch = .x86_64, .os_tag = .linux, .abi = .none },
106 .{ .cpu_arch = .x86_64, .os_tag = .macos, .abi = .none },
107 .{ .cpu_arch = .x86_64, .os_tag = .uefi, .abi = .none },
108 .{ .cpu_arch = .x86_64, .os_tag = .windows, .abi = .gnu },
109 .{ .cpu_arch = .x86_64, .os_tag = .windows, .abi = .msvc },
110};
111
112pub fn addCases(ctx: *Cases) !void {
113 for (targets) |target| {
114 var case = ctx.noEmitUsingLlvmBackend("llvm_targets", target);
115 case.addCompile("");
116 }
117}
test/src/Cases.zig+16
......@@ -76,6 +76,7 @@ pub const Case = struct {
7676 output_mode: std.builtin.OutputMode,
7777 optimize_mode: std.builtin.Mode = .Debug,
7878 updates: std.ArrayList(Update),
79 emit_bin: bool = true,
7980 emit_h: bool = false,
8081 is_test: bool = false,
8182 expect_exact: bool = false,
......@@ -176,6 +177,19 @@ pub fn exeFromCompiledC(ctx: *Cases, name: []const u8, target: CrossTarget) *Cas
176177 return &ctx.cases.items[ctx.cases.items.len - 1];
177178}
178179
180pub fn noEmitUsingLlvmBackend(ctx: *Cases, name: []const u8, target: CrossTarget) *Case {
181 ctx.cases.append(Case{
182 .name = name,
183 .target = target,
184 .updates = std.ArrayList(Update).init(ctx.cases.allocator),
185 .output_mode = .Obj,
186 .emit_bin = false,
187 .deps = std.ArrayList(DepModule).init(ctx.arena),
188 .backend = .llvm,
189 }) catch @panic("out of memory");
190 return &ctx.cases.items[ctx.cases.items.len - 1];
191}
192
179193/// Adds a test case that uses the LLVM backend to emit an executable.
180194/// Currently this implies linking libc, because only then we can generate a testable executable.
181195pub fn exeUsingLlvmBackend(ctx: *Cases, name: []const u8, target: CrossTarget) *Case {
......@@ -537,6 +551,8 @@ pub fn lowerToBuildSteps(
537551 }),
538552 };
539553
554 artifact.emit_bin = if (case.emit_bin) .default else .no_emit;
555
540556 if (case.link_libc) artifact.linkLibC();
541557
542558 switch (case.backend) {