Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into stage2-whole-file-a…
Browse files Browse the repository at this point in the history
…stgen

Conflicts:
 * build.zig
 * src/Compilation.zig
 * src/codegen/spirv/spec.zig
 * src/link/SpirV.zig
 * test/stage2/darwin.zig
   - this one might be problematic; start.zig looks for `main` in the
     root source file, not `_main`. Not sure why there is an underscore
     there in master branch.
  • Loading branch information
andrewrk committed May 16, 2021
2 parents 07606d1 + d98e39f commit 597082a
Show file tree
Hide file tree
Showing 48 changed files with 3,668 additions and 907 deletions.
92 changes: 70 additions & 22 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ pub fn build(b: *Builder) !void {
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 glibc_multi_dir = b.option([]const u8, "enable-foreign-glibc", "Provide directory with glibc installations to run cross compiled tests that link glibc");

test_stage2.addBuildOption(bool, "skip_non_native", skip_non_native);
Expand All @@ -238,6 +239,7 @@ pub fn build(b: *Builder) !void {
test_stage2.addBuildOption(bool, "enable_wine", is_wine_enabled);
test_stage2.addBuildOption(bool, "enable_wasmtime", is_wasmtime_enabled);
test_stage2.addBuildOption(u32, "mem_leak_frames", mem_leak_frames * 2);
test_stage2.addBuildOption(bool, "enable_darling", is_darling_enabled);
test_stage2.addBuildOption(?[]const u8, "glibc_multi_install_dir", glibc_multi_dir);
test_stage2.addBuildOption([]const u8, "version", version);

Expand Down Expand Up @@ -272,11 +274,56 @@ pub fn build(b: *Builder) !void {
const fmt_step = b.step("test-fmt", "Run zig fmt against build.zig to make sure it works");
fmt_step.dependOn(&fmt_build_zig.step);

// TODO for the moment, skip wasm32-wasi until bugs are sorted out.
toolchain_step.dependOn(tests.addPkgTests(b, test_filter, "test/behavior.zig", "behavior", "Run the behavior tests", modes, false, skip_non_native, skip_libc, is_wine_enabled, is_qemu_enabled, is_wasmtime_enabled, glibc_multi_dir));

toolchain_step.dependOn(tests.addPkgTests(b, test_filter, "lib/std/special/compiler_rt.zig", "compiler-rt", "Run the compiler_rt tests", modes, true, skip_non_native, true, is_wine_enabled, is_qemu_enabled, is_wasmtime_enabled, glibc_multi_dir));
toolchain_step.dependOn(tests.addPkgTests(b, test_filter, "lib/std/special/c.zig", "minilibc", "Run the mini libc tests", modes, true, skip_non_native, true, is_wine_enabled, is_qemu_enabled, is_wasmtime_enabled, glibc_multi_dir));
toolchain_step.dependOn(tests.addPkgTests(
b,
test_filter,
"test/behavior.zig",
"behavior",
"Run the behavior tests",
modes,
false,
skip_non_native,
skip_libc,
is_wine_enabled,
is_qemu_enabled,
is_wasmtime_enabled,
is_darling_enabled,
glibc_multi_dir,
));

toolchain_step.dependOn(tests.addPkgTests(
b,
test_filter,
"lib/std/special/compiler_rt.zig",
"compiler-rt",
"Run the compiler_rt tests",
modes,
true,
skip_non_native,
true,
is_wine_enabled,
is_qemu_enabled,
is_wasmtime_enabled,
is_darling_enabled,
glibc_multi_dir,
));

toolchain_step.dependOn(tests.addPkgTests(
b,
test_filter,
"lib/std/special/c.zig",
"minilibc",
"Run the mini libc tests",
modes,
true,
skip_non_native,
true,
is_wine_enabled,
is_qemu_enabled,
is_wasmtime_enabled,
is_darling_enabled,
glibc_multi_dir,
));

toolchain_step.dependOn(tests.addCompareOutputTests(b, test_filter, modes));
toolchain_step.dependOn(tests.addStandaloneTests(b, test_filter, modes));
Expand All @@ -294,7 +341,22 @@ pub fn build(b: *Builder) !void {
toolchain_step.dependOn(tests.addCompileErrorTests(b, test_filter, modes));
}

const std_step = tests.addPkgTests(b, test_filter, "lib/std/std.zig", "std", "Run the standard library tests", modes, false, skip_non_native, skip_libc, is_wine_enabled, is_qemu_enabled, is_wasmtime_enabled, glibc_multi_dir);
const std_step = tests.addPkgTests(
b,
test_filter,
"lib/std/std.zig",
"std",
"Run the standard library tests",
modes,
false,
skip_non_native,
skip_libc,
is_wine_enabled,
is_qemu_enabled,
is_wasmtime_enabled,
is_darling_enabled,
glibc_multi_dir,
);

const test_step = b.step("test", "Run all the tests");
test_step.dependOn(toolchain_step);
Expand Down Expand Up @@ -346,29 +408,15 @@ fn addCmakeCfgOptionsToExe(
},
else => |e| return e,
};

exe.linkSystemLibrary("pthread");
exe.linkSystemLibrary("unwind");
} else if (exe.target.isFreeBSD()) {
try addCxxKnownPath(b, cfg, exe, "libc++.a", null, need_cpp_includes);
exe.linkSystemLibrary("pthread");
} else if (exe.target.getOsTag() == .openbsd) {
try addCxxKnownPath(b, cfg, exe, "libc++.a", null, need_cpp_includes);
try addCxxKnownPath(b, cfg, exe, "libc++abi.a", null, need_cpp_includes);
} else if (exe.target.isDarwin()) {
if (addCxxKnownPath(b, cfg, exe, "libgcc_eh.a", "", need_cpp_includes)) {
// Compiler is GCC.
try addCxxKnownPath(b, cfg, exe, "libstdc++.a", null, need_cpp_includes);
exe.linkSystemLibrary("pthread");
// TODO LLD cannot perform this link.
// Set ZIG_SYSTEM_LINKER_HACK env var to use system linker ld instead.
// See https://github.com/ziglang/zig/issues/1535
} else |err| switch (err) {
error.RequiredLibraryNotFound => {
// System compiler, not gcc.
exe.linkSystemLibrary("c++");
},
else => |e| return e,
}
exe.linkSystemLibrary("c++");
}

if (cfg.dia_guids_lib.len != 0) {
Expand Down
81 changes: 0 additions & 81 deletions lib/libc/glibc/sysdeps/sparc/nptl/bits/pthreadtypes-arch.h

This file was deleted.

8 changes: 8 additions & 0 deletions lib/std/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1398,6 +1398,9 @@ pub const LibExeObjStep = struct {
/// Uses system Wasmtime installation to run cross compiled wasm/wasi build artifacts.
enable_wasmtime: bool = false,

/// Experimental. Uses system Darling installation to run cross compiled macOS build artifacts.
enable_darling: bool = false,

/// After following the steps in https://github.com/ziglang/zig/wiki/Updating-libc#glibc,
/// this will be the directory $glibc-build-dir/install/glibcs
/// Given the example of the aarch64 target, this is the directory
Expand Down Expand Up @@ -2514,6 +2517,11 @@ pub const LibExeObjStep = struct {
try zig_args.append("--dir=.");
try zig_args.append("--test-cmd-bin");
},
.darling => |bin_name| if (self.enable_darling) {
try zig_args.append("--test-cmd");
try zig_args.append(bin_name);
try zig_args.append("--test-cmd-bin");
},
}

for (self.packages.items) |pkg| {
Expand Down
6 changes: 4 additions & 2 deletions lib/std/debug.zig
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ const RED = "\x1b[31;1m";
const GREEN = "\x1b[32;1m";
const CYAN = "\x1b[36;1m";
const WHITE = "\x1b[37;1m";
const BOLD = "\x1b[1m";
const DIM = "\x1b[2m";
const RESET = "\x1b[0m";

Expand Down Expand Up @@ -479,8 +480,9 @@ pub const TTY = struct {
.Red => out_stream.writeAll(RED) catch return,
.Green => out_stream.writeAll(GREEN) catch return,
.Cyan => out_stream.writeAll(CYAN) catch return,
.White, .Bold => out_stream.writeAll(WHITE) catch return,
.White => out_stream.writeAll(WHITE) catch return,
.Dim => out_stream.writeAll(DIM) catch return,
.Bold => out_stream.writeAll(BOLD) catch return,
.Reset => out_stream.writeAll(RESET) catch return,
},
.windows_api => if (native_os == .windows) {
Expand Down Expand Up @@ -632,7 +634,7 @@ fn printLineInfo(
comptime printLineFromFile: anytype,
) !void {
nosuspend {
tty_config.setColor(out_stream, .White);
tty_config.setColor(out_stream, .Bold);

if (line_info) |*li| {
try out_stream.print("{s}:{d}:{d}", .{ li.file_name, li.line, li.column });
Expand Down
4 changes: 3 additions & 1 deletion lib/std/fs.zig
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,9 @@ pub const Dir = struct {
},
.linux => struct {
dir: Dir,
buf: [8192]u8, // TODO align(@alignOf(os.dirent64)),
// The if guard is solely there to prevent compile errors from missing `os.linux.dirent64`
// definition when compiling for other OSes. It doesn't do anything when compiling for Linux.
buf: [8192]u8 align(if (builtin.os.tag != .linux) 1 else @alignOf(os.linux.dirent64)),
index: usize,
end_index: usize,

Expand Down
25 changes: 13 additions & 12 deletions lib/std/hash_map.zig
Original file line number Diff line number Diff line change
Expand Up @@ -303,29 +303,32 @@ pub fn HashMapUnmanaged(
/// Metadata for a slot. It can be in three states: empty, used or
/// tombstone. Tombstones indicate that an entry was previously used,
/// they are a simple way to handle removal.
/// To this state, we add 6 bits from the slot's key hash. These are
/// To this state, we add 7 bits from the slot's key hash. These are
/// used as a fast way to disambiguate between entries without
/// having to use the equality function. If two fingerprints are
/// different, we know that we don't have to compare the keys at all.
/// The 6 bits are the highest ones from a 64 bit hash. This way, not
/// The 7 bits are the highest ones from a 64 bit hash. This way, not
/// only we use the `log2(capacity)` lowest bits from the hash to determine
/// a slot index, but we use 6 more bits to quickly resolve collisions
/// when multiple elements with different hashes end up wanting to be in / the same slot.
/// a slot index, but we use 7 more bits to quickly resolve collisions
/// when multiple elements with different hashes end up wanting to be in the same slot.
/// Not using the equality function means we don't have to read into
/// the entries array, avoiding a likely cache miss.
/// the entries array, likely avoiding a cache miss and a potentially
/// costly function call.
const Metadata = packed struct {
const FingerPrint = u6;
const FingerPrint = u7;

const free: FingerPrint = 0;
const tombstone: FingerPrint = 1;

fingerprint: FingerPrint = free,
used: u1 = 0,
tombstone: u1 = 0,
fingerprint: FingerPrint = 0,

pub fn isUsed(self: Metadata) bool {
return self.used == 1;
}

pub fn isTombstone(self: Metadata) bool {
return self.tombstone == 1;
return !self.isUsed() and self.fingerprint == tombstone;
}

pub fn takeFingerprint(hash: Hash) FingerPrint {
Expand All @@ -336,14 +339,12 @@ pub fn HashMapUnmanaged(

pub fn fill(self: *Metadata, fp: FingerPrint) void {
self.used = 1;
self.tombstone = 0;
self.fingerprint = fp;
}

pub fn remove(self: *Metadata) void {
self.used = 0;
self.tombstone = 1;
self.fingerprint = 0;
self.fingerprint = tombstone;
}
};

Expand Down
Loading

0 comments on commit 597082a

Please sign in to comment.