| author | |
| committer | |
| log | 45415093c655d30ec226172695248fbf28941667 |
| tree | 3c986224f6ee1c843b6f56c3c487f65809ff9a15 |
| parent | 3997828a6176203b25b541c6e450f5e4bda82ce4 |
* 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 @@ | ... | @@ -1,7 +1,6 @@ |
| 1 | const std = @import("../std.zig"); | 1 | const std = @import("../std.zig"); |
| 2 | const builtin = @import("builtin"); | 2 | const builtin = @import("builtin"); |
| 3 | const build = std.build; | 3 | const build = std.build; |
| 4 | const CrossTarget = std.zig.CrossTarget; | ||
| 5 | const Step = build.Step; | 4 | const Step = build.Step; |
| 6 | const Builder = build.Builder; | 5 | const Builder = build.Builder; |
| 7 | const LibExeObjStep = build.LibExeObjStep; | 6 | const LibExeObjStep = build.LibExeObjStep; |
| ... | @@ -143,23 +142,6 @@ pub fn expectStdErrEqual(self: *RunStep, bytes: []const u8) void { | ... | @@ -143,23 +142,6 @@ pub fn expectStdErrEqual(self: *RunStep, bytes: []const u8) void { |
| 143 | self.stderr_action = .{ .expect_exact = self.builder.dupe(bytes) }; | 142 | self.stderr_action = .{ .expect_exact = self.builder.dupe(bytes) }; |
| 144 | } | 143 | } |
| 145 | 144 | ||
| 146 | /// Returns true if the step could be run, otherwise false | ||
| 147 | pub 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 | |||
| 163 | pub fn expectStdOutEqual(self: *RunStep, bytes: []const u8) void { | 145 | pub fn expectStdOutEqual(self: *RunStep, bytes: []const u8) void { |
| 164 | self.stdout_action = .{ .expect_exact = self.builder.dupe(bytes) }; | 146 | self.stdout_action = .{ .expect_exact = self.builder.dupe(bytes) }; |
| 165 | } | 147 | } |
| ... | @@ -172,57 +154,6 @@ fn stdIoActionToBehavior(action: StdIoAction) std.ChildProcess.StdIo { | ... | @@ -172,57 +154,6 @@ fn stdIoActionToBehavior(action: StdIoAction) std.ChildProcess.StdIo { |
| 172 | }; | 154 | }; |
| 173 | } | 155 | } |
| 174 | 156 | ||
| 175 | fn 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 | |||
| 226 | fn make(step: *Step) !void { | 157 | fn make(step: *Step) !void { |
| 227 | const self = @fieldParentPtr(RunStep, "step", step); | 158 | const self = @fieldParentPtr(RunStep, "step", step); |
| 228 | 159 | ||
| ... | @@ -238,9 +169,6 @@ fn make(step: *Step) !void { | ... | @@ -238,9 +169,6 @@ fn make(step: *Step) !void { |
| 238 | // On Windows we don't have rpaths so we have to add .dll search paths to PATH | 169 | // On Windows we don't have rpaths so we have to add .dll search paths to PATH |
| 239 | self.addPathForDynLibs(artifact); | 170 | self.addPathForDynLibs(artifact); |
| 240 | } | 171 | } |
| 241 | if (try self.getExternalExecutor(artifact)) |executor| { | ||
| 242 | try argv_list.append(executor); | ||
| 243 | } | ||
| 244 | const executable_path = artifact.installed_path orelse artifact.getOutputSource().getPath(self.builder); | 172 | const executable_path = artifact.installed_path orelse artifact.getOutputSource().getPath(self.builder); |
| 245 | try argv_list.append(executable_path); | 173 | try argv_list.append(executable_path); |
| 246 | }, | 174 | }, |
src/Compilation.zig+1-1| ... | @@ -3815,7 +3815,7 @@ pub fn addCCArgs( | ... | @@ -3815,7 +3815,7 @@ pub fn addCCArgs( |
| 3815 | 3815 | ||
| 3816 | if (comp.bin_file.options.single_threaded) { | 3816 | if (comp.bin_file.options.single_threaded) { |
| 3817 | try argv.append("-D_LIBCPP_HAS_NO_THREADS"); | 3817 | try argv.append("-D_LIBCPP_HAS_NO_THREADS"); |
| 3818 | } else {} | 3818 | } |
| 3819 | } | 3819 | } |
| 3820 | 3820 | ||
| 3821 | if (comp.bin_file.options.link_libunwind) { | 3821 | if (comp.bin_file.options.link_libunwind) { |
test/standalone/c_compiler/build.zig+14-26| ... | @@ -1,21 +1,20 @@ | ... | @@ -1,21 +1,20 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const builtin = @import("builtin"); | ||
| 2 | const Builder = std.build.Builder; | 3 | const Builder = std.build.Builder; |
| 3 | const CrossTarget = std.zig.CrossTarget; | 4 | const CrossTarget = std.zig.CrossTarget; |
| 4 | 5 | ||
| 6 | // TODO integrate this with the std.build executor API | ||
| 7 | fn 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 | |||
| 5 | pub fn build(b: *Builder) void { | 14 | pub fn build(b: *Builder) void { |
| 6 | const mode = b.standardReleaseOptions(); | 15 | const mode = b.standardReleaseOptions(); |
| 7 | const target = b.standardTargetOptions(.{}); | 16 | const target = b.standardTargetOptions(.{}); |
| 8 | 17 | ||
| 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 | |||
| 19 | const test_step = b.step("test", "Test the program"); | 18 | const test_step = b.step("test", "Test the program"); |
| 20 | 19 | ||
| 21 | const exe_c = b.addExecutable("test_c", null); | 20 | const exe_c = b.addExecutable("test_c", null); |
| ... | @@ -31,15 +30,8 @@ pub fn build(b: *Builder) void { | ... | @@ -31,15 +30,8 @@ pub fn build(b: *Builder) void { |
| 31 | exe_cpp.setBuildMode(mode); | 30 | exe_cpp.setBuildMode(mode); |
| 32 | exe_cpp.setTarget(target); | 31 | exe_cpp.setTarget(target); |
| 33 | exe_cpp.linkLibCpp(); | 32 | 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 | } | ||
| 41 | 33 | ||
| 42 | switch (os_tag) { | 34 | switch (target.getOsTag()) { |
| 43 | .windows => { | 35 | .windows => { |
| 44 | // https://github.com/ziglang/zig/issues/8531 | 36 | // https://github.com/ziglang/zig/issues/8531 |
| 45 | exe_cpp.want_lto = false; | 37 | exe_cpp.want_lto = false; |
| ... | @@ -52,17 +44,13 @@ pub fn build(b: *Builder) void { | ... | @@ -52,17 +44,13 @@ pub fn build(b: *Builder) void { |
| 52 | else => {}, | 44 | else => {}, |
| 53 | } | 45 | } |
| 54 | 46 | ||
| 55 | const run_c_cmd = exe_c.run(); | 47 | if (isRunnableTarget(target)) { |
| 56 | if (run_c_cmd.isRunnable()) { | 48 | const run_c_cmd = exe_c.run(); |
| 57 | test_step.dependOn(&run_c_cmd.step); | 49 | test_step.dependOn(&run_c_cmd.step); |
| 58 | } else { | 50 | const run_cpp_cmd = exe_cpp.run(); |
| 59 | test_step.dependOn(&exe_c.step); | ||
| 60 | } | ||
| 61 | |||
| 62 | const run_cpp_cmd = exe_cpp.run(); | ||
| 63 | if (run_cpp_cmd.isRunnable()) { | ||
| 64 | test_step.dependOn(&run_cpp_cmd.step); | 51 | test_step.dependOn(&run_cpp_cmd.step); |
| 65 | } else { | 52 | } else { |
| 53 | test_step.dependOn(&exe_c.step); | ||
| 66 | test_step.dependOn(&exe_cpp.step); | 54 | test_step.dependOn(&exe_cpp.step); |
| 67 | } | 55 | } |
| 68 | } | 56 | } |
test/standalone/c_compiler/test.cpp+16-2| ... | @@ -30,13 +30,25 @@ private: | ... | @@ -30,13 +30,25 @@ private: |
| 30 | int m_val; | 30 | int m_val; |
| 31 | }; | 31 | }; |
| 32 | 32 | ||
| 33 | class GlobalConstructorTest { | ||
| 34 | public: | ||
| 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; } | ||
| 40 | private: | ||
| 41 | int m_val; | ||
| 42 | }; | ||
| 43 | |||
| 33 | 44 | ||
| 34 | volatile int runtime_val = 456; | 45 | volatile int runtime_val = 456; |
| 35 | CTest global(runtime_val);	// test if global initializers are called. | 46 | GlobalConstructorTest global(runtime_val);	// test if global initializers are called. |
| 36 | 47 | ||
| 37 | int main (int argc, char *argv[]) | 48 | int main (int argc, char *argv[]) |
| 38 | { | 49 | { |
| 39 | assert(global.getVal() == 456); | 50 | assert(global.getVal() == 456); |
| 51 | |||
| 40 | auto t = std::make_unique<CTest>(123); | 52 | auto t = std::make_unique<CTest>(123); |
| 41 | assert(t->getVal() != 456); | 53 | assert(t->getVal() != 456); |
| 42 | assert(tls_counter == 2); | 54 | assert(tls_counter == 2); |
| ... | @@ -53,7 +65,9 @@ int main (int argc, char *argv[]) | ... | @@ -53,7 +65,9 @@ int main (int argc, char *argv[]) |
| 53 | assert(ret); | 65 | assert(ret); |
| 54 | #endif | 66 | #endif |
| 55 | 67 | ||
| 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. | ||
| 57 | try { | 71 | try { |
| 58 | throw 20; | 72 | throw 20; |
| 59 | } catch (int e) { | 73 | } catch (int e) { |