Commit 45415093c6
Changed files (4)
lib/std/build/RunStep.zig
@@ -1,7 +1,6 @@
const std = @import("../std.zig");
const builtin = @import("builtin");
const build = std.build;
-const CrossTarget = std.zig.CrossTarget;
const Step = build.Step;
const Builder = build.Builder;
const LibExeObjStep = build.LibExeObjStep;
@@ -143,23 +142,6 @@ pub fn expectStdErrEqual(self: *RunStep, bytes: []const u8) void {
self.stderr_action = .{ .expect_exact = self.builder.dupe(bytes) };
}
-/// Returns true if the step could be run, otherwise false
-pub fn isRunnable(
- self: *RunStep,
-) bool {
- for (self.argv.items) |arg| {
- switch (arg) {
- .artifact => |artifact| {
- _ = self.getExternalExecutor(artifact) catch {
- return false;
- };
- },
- else => {},
- }
- }
- return true;
-}
-
pub fn expectStdOutEqual(self: *RunStep, bytes: []const u8) void {
self.stdout_action = .{ .expect_exact = self.builder.dupe(bytes) };
}
@@ -172,57 +154,6 @@ fn stdIoActionToBehavior(action: StdIoAction) std.ChildProcess.StdIo {
};
}
-fn getExternalExecutor(self: *RunStep, artifact: *LibExeObjStep) !?[]const u8 {
- const need_cross_glibc = artifact.target.isGnuLibC() and artifact.is_linking_libc;
- const executor = self.builder.host.getExternalExecutor(artifact.target_info, .{
- .qemu_fixes_dl = need_cross_glibc and self.builder.glibc_runtimes_dir != null,
- .link_libc = artifact.is_linking_libc,
- });
- switch (executor) {
- .bad_dl, .bad_os_or_cpu => {
- return error.NoExecutable;
- },
- .native => {
- return null;
- },
- .rosetta => {
- if (self.builder.enable_rosetta) {
- return null;
- } else {
- return error.RosettaNotEnabled;
- }
- },
- .qemu => |bin_name| {
- if (self.builder.enable_qemu) {
- return bin_name;
- } else {
- return error.QemuNotEnabled;
- }
- },
- .wine => |bin_name| {
- if (self.builder.enable_wine) {
- return bin_name;
- } else {
- return error.WineNotEnabled;
- }
- },
- .wasmtime => |bin_name| {
- if (self.builder.enable_wasmtime) {
- return bin_name;
- } else {
- return error.WasmtimeNotEnabled;
- }
- },
- .darling => |bin_name| {
- if (self.builder.enable_darling) {
- return bin_name;
- } else {
- return error.DarlingNotEnabled;
- }
- },
- }
-}
-
fn make(step: *Step) !void {
const self = @fieldParentPtr(RunStep, "step", step);
@@ -238,9 +169,6 @@ fn make(step: *Step) !void {
// On Windows we don't have rpaths so we have to add .dll search paths to PATH
self.addPathForDynLibs(artifact);
}
- if (try self.getExternalExecutor(artifact)) |executor| {
- try argv_list.append(executor);
- }
const executable_path = artifact.installed_path orelse artifact.getOutputSource().getPath(self.builder);
try argv_list.append(executable_path);
},
src/Compilation.zig
@@ -3815,7 +3815,7 @@ pub fn addCCArgs(
if (comp.bin_file.options.single_threaded) {
try argv.append("-D_LIBCPP_HAS_NO_THREADS");
- } else {}
+ }
}
if (comp.bin_file.options.link_libunwind) {
test/standalone/c_compiler/build.zig
@@ -1,21 +1,20 @@
const std = @import("std");
+const builtin = @import("builtin");
const Builder = std.build.Builder;
const CrossTarget = std.zig.CrossTarget;
+// TODO integrate this with the std.build executor API
+fn isRunnableTarget(t: CrossTarget) bool {
+ if (t.isNative()) return true;
+
+ return (t.getOsTag() == builtin.os.tag and
+ t.getCpuArch() == builtin.cpu.arch);
+}
+
pub fn build(b: *Builder) void {
const mode = b.standardReleaseOptions();
const target = b.standardTargetOptions(.{});
- const is_wine_enabled = b.option(bool, "enable-wine", "Use Wine to run cross compiled Windows tests") orelse false;
- const is_qemu_enabled = b.option(bool, "enable-qemu", "Use QEMU to run cross compiled foreign architecture tests") orelse false;
- const is_wasmtime_enabled = b.option(bool, "enable-wasmtime", "Use Wasmtime to enable and run WASI libstd tests") orelse false;
- const is_darling_enabled = b.option(bool, "enable-darling", "[Experimental] Use Darling to run cross compiled macOS tests") orelse false;
- const single_threaded = b.option(bool, "single-threaded", "Test single threaded mode") orelse false;
- b.enable_wine = is_wine_enabled;
- b.enable_qemu = is_qemu_enabled;
- b.enable_wasmtime = is_wasmtime_enabled;
- b.enable_darling = is_darling_enabled;
-
const test_step = b.step("test", "Test the program");
const exe_c = b.addExecutable("test_c", null);
@@ -31,15 +30,8 @@ pub fn build(b: *Builder) void {
exe_cpp.setBuildMode(mode);
exe_cpp.setTarget(target);
exe_cpp.linkLibCpp();
- exe_cpp.single_threaded = single_threaded;
- const os_tag = target.getOsTag();
- // macos C++ exceptions could be compiled, but not being catched,
- // additional support is required, possibly unwind + DWARF CFI
- if (target.getCpuArch().isWasm() or os_tag == .macos) {
- exe_cpp.defineCMacro("_LIBCPP_NO_EXCEPTIONS", null);
- }
- switch (os_tag) {
+ switch (target.getOsTag()) {
.windows => {
// https://github.com/ziglang/zig/issues/8531
exe_cpp.want_lto = false;
@@ -52,17 +44,13 @@ pub fn build(b: *Builder) void {
else => {},
}
- const run_c_cmd = exe_c.run();
- if (run_c_cmd.isRunnable()) {
+ if (isRunnableTarget(target)) {
+ const run_c_cmd = exe_c.run();
test_step.dependOn(&run_c_cmd.step);
- } else {
- test_step.dependOn(&exe_c.step);
- }
-
- const run_cpp_cmd = exe_cpp.run();
- if (run_cpp_cmd.isRunnable()) {
+ const run_cpp_cmd = exe_cpp.run();
test_step.dependOn(&run_cpp_cmd.step);
} else {
+ test_step.dependOn(&exe_c.step);
test_step.dependOn(&exe_cpp.step);
}
}
test/standalone/c_compiler/test.cpp
@@ -30,13 +30,25 @@ private:
int m_val;
};
+class GlobalConstructorTest {
+public:
+ GlobalConstructorTest(int val) : m_val(val) {};
+ virtual ~GlobalConstructorTest() {}
+
+ virtual int getVal() const { return m_val; }
+ virtual void printVal() { std::cout << "val=" << m_val << std::endl; }
+private:
+ int m_val;
+};
+
volatile int runtime_val = 456;
-CTest global(runtime_val); // test if global initializers are called.
+GlobalConstructorTest global(runtime_val); // test if global initializers are called.
int main (int argc, char *argv[])
{
assert(global.getVal() == 456);
+
auto t = std::make_unique<CTest>(123);
assert(t->getVal() != 456);
assert(tls_counter == 2);
@@ -53,7 +65,9 @@ int main (int argc, char *argv[])
assert(ret);
#endif
-#ifndef _LIBCPP_NO_EXCEPTIONS
+#if !defined(__wasm__) && !defined(__APPLE__)
+ // WASM and macOS are not passing this yet.
+ // TODO file an issue for this and link it here.
try {
throw 20;
} catch (int e) {