authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-05-10 16:38:37-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-05-10 17:31:54-07:00
log45415093c655d30ec226172695248fbf28941667
tree3c986224f6ee1c843b6f56c3c487f65809ff9a15
parent3997828a6176203b25b541c6e450f5e4bda82ce4

reduce the scope of this branch

* back out the changes to RunStep * move the disabled test to the .cpp code and avoid a confusing name-collision with the _LIBCPP macro prefix * fix merge conflict with the edits to the same test that ensure global initializers are called. Now this branch is only concerned with single-threaded targets and passing the correct macro defines to libc++.

4 files changed, 31 insertions(+), 101 deletions(-)

lib/std/build/RunStep.zig-72
......@@ -1,7 +1,6 @@
11const std = @import("../std.zig");
22const builtin = @import("builtin");
33const build = std.build;
4const CrossTarget = std.zig.CrossTarget;
54const Step = build.Step;
65const Builder = build.Builder;
76const LibExeObjStep = build.LibExeObjStep;
......@@ -143,23 +142,6 @@ pub fn expectStdErrEqual(self: *RunStep, bytes: []const u8) void {
143142 self.stderr_action = .{ .expect_exact = self.builder.dupe(bytes) };
144143}
145144
146/// Returns true if the step could be run, otherwise false
147pub fn isRunnable(
148 self: *RunStep,
149) bool {
150 for (self.argv.items) |arg| {
151 switch (arg) {
152 .artifact => |artifact| {
153 _ = self.getExternalExecutor(artifact) catch {
154 return false;
155 };
156 },
157 else => {},
158 }
159 }
160 return true;
161}
162
163145pub fn expectStdOutEqual(self: *RunStep, bytes: []const u8) void {
164146 self.stdout_action = .{ .expect_exact = self.builder.dupe(bytes) };
165147}
......@@ -172,57 +154,6 @@ fn stdIoActionToBehavior(action: StdIoAction) std.ChildProcess.StdIo {
172154 };
173155}
174156
175fn getExternalExecutor(self: *RunStep, artifact: *LibExeObjStep) !?[]const u8 {
176 const need_cross_glibc = artifact.target.isGnuLibC() and artifact.is_linking_libc;
177 const executor = self.builder.host.getExternalExecutor(artifact.target_info, .{
178 .qemu_fixes_dl = need_cross_glibc and self.builder.glibc_runtimes_dir != null,
179 .link_libc = artifact.is_linking_libc,
180 });
181 switch (executor) {
182 .bad_dl, .bad_os_or_cpu => {
183 return error.NoExecutable;
184 },
185 .native => {
186 return null;
187 },
188 .rosetta => {
189 if (self.builder.enable_rosetta) {
190 return null;
191 } else {
192 return error.RosettaNotEnabled;
193 }
194 },
195 .qemu => |bin_name| {
196 if (self.builder.enable_qemu) {
197 return bin_name;
198 } else {
199 return error.QemuNotEnabled;
200 }
201 },
202 .wine => |bin_name| {
203 if (self.builder.enable_wine) {
204 return bin_name;
205 } else {
206 return error.WineNotEnabled;
207 }
208 },
209 .wasmtime => |bin_name| {
210 if (self.builder.enable_wasmtime) {
211 return bin_name;
212 } else {
213 return error.WasmtimeNotEnabled;
214 }
215 },
216 .darling => |bin_name| {
217 if (self.builder.enable_darling) {
218 return bin_name;
219 } else {
220 return error.DarlingNotEnabled;
221 }
222 },
223 }
224}
225
226157fn make(step: *Step) !void {
227158 const self = @fieldParentPtr(RunStep, "step", step);
228159
......@@ -238,9 +169,6 @@ fn make(step: *Step) !void {
238169 // On Windows we don't have rpaths so we have to add .dll search paths to PATH
239170 self.addPathForDynLibs(artifact);
240171 }
241 if (try self.getExternalExecutor(artifact)) |executor| {
242 try argv_list.append(executor);
243 }
244172 const executable_path = artifact.installed_path orelse artifact.getOutputSource().getPath(self.builder);
245173 try argv_list.append(executable_path);
246174 },
src/Compilation.zig+1-1
......@@ -3815,7 +3815,7 @@ pub fn addCCArgs(
38153815
38163816 if (comp.bin_file.options.single_threaded) {
38173817 try argv.append("-D_LIBCPP_HAS_NO_THREADS");
3818 } else {}
3818 }
38193819 }
38203820
38213821 if (comp.bin_file.options.link_libunwind) {
test/standalone/c_compiler/build.zig+14-26
......@@ -1,21 +1,20 @@
11const std = @import("std");
2const builtin = @import("builtin");
23const Builder = std.build.Builder;
34const CrossTarget = std.zig.CrossTarget;
45
6// TODO integrate this with the std.build executor API
7fn isRunnableTarget(t: CrossTarget) bool {
8 if (t.isNative()) return true;
9
10 return (t.getOsTag() == builtin.os.tag and
11 t.getCpuArch() == builtin.cpu.arch);
12}
13
514pub fn build(b: *Builder) void {
615 const mode = b.standardReleaseOptions();
716 const target = b.standardTargetOptions(.{});
817
9 const is_wine_enabled = b.option(bool, "enable-wine", "Use Wine to run cross compiled Windows tests") orelse false;
10 const is_qemu_enabled = b.option(bool, "enable-qemu", "Use QEMU to run cross compiled foreign architecture tests") orelse false;
11 const is_wasmtime_enabled = b.option(bool, "enable-wasmtime", "Use Wasmtime to enable and run WASI libstd tests") orelse false;
12 const is_darling_enabled = b.option(bool, "enable-darling", "[Experimental] Use Darling to run cross compiled macOS tests") orelse false;
13 const single_threaded = b.option(bool, "single-threaded", "Test single threaded mode") orelse false;
14 b.enable_wine = is_wine_enabled;
15 b.enable_qemu = is_qemu_enabled;
16 b.enable_wasmtime = is_wasmtime_enabled;
17 b.enable_darling = is_darling_enabled;
18
1918 const test_step = b.step("test", "Test the program");
2019
2120 const exe_c = b.addExecutable("test_c", null);
......@@ -31,15 +30,8 @@ pub fn build(b: *Builder) void {
3130 exe_cpp.setBuildMode(mode);
3231 exe_cpp.setTarget(target);
3332 exe_cpp.linkLibCpp();
34 exe_cpp.single_threaded = single_threaded;
35 const os_tag = target.getOsTag();
36 // macos C++ exceptions could be compiled, but not being catched,
37 // additional support is required, possibly unwind + DWARF CFI
38 if (target.getCpuArch().isWasm() or os_tag == .macos) {
39 exe_cpp.defineCMacro("_LIBCPP_NO_EXCEPTIONS", null);
40 }
4133
42 switch (os_tag) {
34 switch (target.getOsTag()) {
4335 .windows => {
4436 // https://github.com/ziglang/zig/issues/8531
4537 exe_cpp.want_lto = false;
......@@ -52,17 +44,13 @@ pub fn build(b: *Builder) void {
5244 else => {},
5345 }
5446
55 const run_c_cmd = exe_c.run();
56 if (run_c_cmd.isRunnable()) {
47 if (isRunnableTarget(target)) {
48 const run_c_cmd = exe_c.run();
5749 test_step.dependOn(&run_c_cmd.step);
58 } else {
59 test_step.dependOn(&exe_c.step);
60 }
61
62 const run_cpp_cmd = exe_cpp.run();
63 if (run_cpp_cmd.isRunnable()) {
50 const run_cpp_cmd = exe_cpp.run();
6451 test_step.dependOn(&run_cpp_cmd.step);
6552 } else {
53 test_step.dependOn(&exe_c.step);
6654 test_step.dependOn(&exe_cpp.step);
6755 }
6856}
test/standalone/c_compiler/test.cpp+16-2
......@@ -30,13 +30,25 @@ private:
3030 int m_val;
3131};
3232
33class GlobalConstructorTest {
34public:
35 GlobalConstructorTest(int val) : m_val(val) {};
36 virtual ~GlobalConstructorTest() {}
37
38 virtual int getVal() const { return m_val; }
39 virtual void printVal() { std::cout << "val=" << m_val << std::endl; }
40private:
41 int m_val;
42};
43
3344
3445volatile int runtime_val = 456;
35CTest global(runtime_val); // test if global initializers are called.
46GlobalConstructorTest global(runtime_val); // test if global initializers are called.
3647
3748int main (int argc, char *argv[])
3849{
3950 assert(global.getVal() == 456);
51
4052 auto t = std::make_unique<CTest>(123);
4153 assert(t->getVal() != 456);
4254 assert(tls_counter == 2);
......@@ -53,7 +65,9 @@ int main (int argc, char *argv[])
5365 assert(ret);
5466#endif
5567
56#ifndef _LIBCPP_NO_EXCEPTIONS
68#if !defined(__wasm__) && !defined(__APPLE__)
69 // WASM and macOS are not passing this yet.
70 // TODO file an issue for this and link it here.
5771 try {
5872 throw 20;
5973 } catch (int e) {