| 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 | 1 | const std = @import("../std.zig"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | 3 | const build = std.build; |
| 4 | const CrossTarget = std.zig.CrossTarget; | |
| 5 | 4 | const Step = build.Step; |
| 6 | 5 | const Builder = build.Builder; |
| 7 | 6 | const LibExeObjStep = build.LibExeObjStep; |
| ... | ... | @@ -143,23 +142,6 @@ pub fn expectStdErrEqual(self: *RunStep, bytes: []const u8) void { |
| 143 | 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 | 145 | pub fn expectStdOutEqual(self: *RunStep, bytes: []const u8) void { |
| 164 | 146 | self.stdout_action = .{ .expect_exact = self.builder.dupe(bytes) }; |
| 165 | 147 | } |
| ... | ... | @@ -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 | 157 | fn make(step: *Step) !void { |
| 227 | 158 | const self = @fieldParentPtr(RunStep, "step", step); |
| 228 | 159 | |
| ... | ... | @@ -238,9 +169,6 @@ fn make(step: *Step) !void { |
| 238 | 169 | // On Windows we don't have rpaths so we have to add .dll search paths to PATH |
| 239 | 170 | self.addPathForDynLibs(artifact); |
| 240 | 171 | } |
| 241 | if (try self.getExternalExecutor(artifact)) |executor| { | |
| 242 | try argv_list.append(executor); | |
| 243 | } | |
| 244 | 172 | const executable_path = artifact.installed_path orelse artifact.getOutputSource().getPath(self.builder); |
| 245 | 173 | try argv_list.append(executable_path); |
| 246 | 174 | }, |
src/Compilation.zig+1-1| ... | ... | @@ -3815,7 +3815,7 @@ pub fn addCCArgs( |
| 3815 | 3815 | |
| 3816 | 3816 | if (comp.bin_file.options.single_threaded) { |
| 3817 | 3817 | try argv.append("-D_LIBCPP_HAS_NO_THREADS"); |
| 3818 | } else {} | |
| 3818 | } | |
| 3819 | 3819 | } |
| 3820 | 3820 | |
| 3821 | 3821 | if (comp.bin_file.options.link_libunwind) { |
test/standalone/c_compiler/build.zig+14-26| ... | ... | @@ -1,21 +1,20 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | const builtin = @import("builtin"); | |
| 2 | 3 | const Builder = std.build.Builder; |
| 3 | 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 | 14 | pub fn build(b: *Builder) void { |
| 6 | 15 | const mode = b.standardReleaseOptions(); |
| 7 | 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 | 18 | const test_step = b.step("test", "Test the program"); |
| 20 | 19 | |
| 21 | 20 | const exe_c = b.addExecutable("test_c", null); |
| ... | ... | @@ -31,15 +30,8 @@ pub fn build(b: *Builder) void { |
| 31 | 30 | exe_cpp.setBuildMode(mode); |
| 32 | 31 | exe_cpp.setTarget(target); |
| 33 | 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 | 35 | .windows => { |
| 44 | 36 | // https://github.com/ziglang/zig/issues/8531 |
| 45 | 37 | exe_cpp.want_lto = false; |
| ... | ... | @@ -52,17 +44,13 @@ pub fn build(b: *Builder) void { |
| 52 | 44 | else => {}, |
| 53 | 45 | } |
| 54 | 46 | |
| 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(); | |
| 57 | 49 | 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(); | |
| 64 | 51 | test_step.dependOn(&run_cpp_cmd.step); |
| 65 | 52 | } else { |
| 53 | test_step.dependOn(&exe_c.step); | |
| 66 | 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 | 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 | 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 | 48 | int main (int argc, char *argv[]) |
| 38 | 49 | { |
| 39 | 50 | assert(global.getVal() == 456); |
| 51 | ||
| 40 | 52 | auto t = std::make_unique<CTest>(123); |
| 41 | 53 | assert(t->getVal() != 456); |
| 42 | 54 | assert(tls_counter == 2); |
| ... | ... | @@ -53,7 +65,9 @@ int main (int argc, char *argv[]) |
| 53 | 65 | assert(ret); |
| 54 | 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 | 71 | try { |
| 58 | 72 | throw 20; |
| 59 | 73 | } catch (int e) { |