Skip to content

build: fix build for latest zig version #200

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 29 additions & 46 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -532,31 +532,30 @@ pub fn build(b: *Builder) void {
std.os.exit(0);
}

use_color_escapes = false;
switch (b.color) {
.on => use_color_escapes = true,
.off => use_color_escapes = false,
.auto => {
if (std.io.getStdErr().supportsAnsiEscapeCodes()) {
use_color_escapes = true;
} else if (builtin.os.tag == .windows) {
const w32 = struct {
const WINAPI = std.os.windows.WINAPI;
const DWORD = std.os.windows.DWORD;
const ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004;
const STD_ERROR_HANDLE = @bitCast(DWORD, @as(i32, -12));
extern "kernel32" fn GetStdHandle(id: DWORD) callconv(WINAPI) ?*anyopaque;
extern "kernel32" fn GetConsoleMode(console: ?*anyopaque, out_mode: *DWORD) callconv(WINAPI) u32;
extern "kernel32" fn SetConsoleMode(console: ?*anyopaque, mode: DWORD) callconv(WINAPI) u32;
};
const handle = w32.GetStdHandle(w32.STD_ERROR_HANDLE);
var mode: w32.DWORD = 0;
if (w32.GetConsoleMode(handle, &mode) != 0) {
mode |= w32.ENABLE_VIRTUAL_TERMINAL_PROCESSING;
use_color_escapes = w32.SetConsoleMode(handle, mode) != 0;
}
if (b.env_map.get("NO_COLOR") != null) {
use_color_escapes = false;
} else if (b.env_map.get("ZIG_DEBUG_COLOR") != null) {
use_color_escapes = true;
} else {
if (std.io.getStdErr().supportsAnsiEscapeCodes()) {
use_color_escapes = true;
} else if (builtin.os.tag == .windows) {
const w32 = struct {
const WINAPI = std.os.windows.WINAPI;
const DWORD = std.os.windows.DWORD;
const ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004;
const STD_ERROR_HANDLE = @bitCast(DWORD, @as(i32, -12));
extern "kernel32" fn GetStdHandle(id: DWORD) callconv(WINAPI) ?*anyopaque;
extern "kernel32" fn GetConsoleMode(console: ?*anyopaque, out_mode: *DWORD) callconv(WINAPI) u32;
extern "kernel32" fn SetConsoleMode(console: ?*anyopaque, mode: DWORD) callconv(WINAPI) u32;
};
const handle = w32.GetStdHandle(w32.STD_ERROR_HANDLE);
var mode: w32.DWORD = 0;
if (w32.GetConsoleMode(handle, &mode) != 0) {
mode |= w32.ENABLE_VIRTUAL_TERMINAL_PROCESSING;
use_color_escapes = w32.SetConsoleMode(handle, mode) != 0;
}
},
}
}

if (use_color_escapes) {
Expand All @@ -566,20 +565,7 @@ pub fn build(b: *Builder) void {
reset_text = "\x1b[0m";
}

const header_step = b.addLog(
\\
\\ _ _ _
\\ ___(_) __ _| (_)_ __ __ _ ___
\\ |_ | |/ _' | | | '_ \ / _' / __|
\\ / /| | (_| | | | | | | (_| \__ \
\\ /___|_|\__, |_|_|_| |_|\__, |___/
\\ |___/ |___/
\\
\\
, .{});

const verify_all = b.step("ziglings", "Check all ziglings");
verify_all.dependOn(&header_step.step);
b.default_step = verify_all;

var prev_chain_verify = verify_all;
Expand Down Expand Up @@ -610,11 +596,11 @@ pub fn build(b: *Builder) void {
named_verify.dependOn(&verify_step.step);

const chain_verify = b.allocator.create(Step) catch unreachable;
chain_verify.* = Step.initNoOp(.custom, b.fmt("chain {s}", .{key}), b.allocator);
const step_options = Step.Options{ .id = .custom, .name = b.fmt("chain {s}", .{key}), .owner = b };
chain_verify.* = Step.init(step_options);
chain_verify.dependOn(&verify_step.step);

const named_chain = b.step(b.fmt("{s}_start", .{key}), b.fmt("Check all solutions starting at {s}", .{ex.main_file}));
named_chain.dependOn(&header_step.step);
named_chain.dependOn(chain_verify);

prev_chain_verify.dependOn(chain_verify);
Expand All @@ -636,16 +622,18 @@ const ZiglingStep = struct {

pub fn create(builder: *Builder, exercise: Exercise, use_healed: bool) *@This() {
const self = builder.allocator.create(@This()) catch unreachable;
const step_options = Step.Options{ .id = .custom, .name = exercise.main_file, .owner = builder, .makeFn = make };
self.* = .{
.step = Step.init(.custom, exercise.main_file, builder.allocator, make),
.step = Step.init(step_options),
.exercise = exercise,
.builder = builder,
.use_healed = use_healed,
};
return self;
}

fn make(step: *Step) anyerror!void {
fn make(step: *Step, prog_node: *std.Progress.Node) anyerror!void {
_ = prog_node;
const self = @fieldParentPtr(@This(), "step", step);
self.makeInternal() catch {
if (self.exercise.hint.len > 0) {
Expand Down Expand Up @@ -756,11 +744,6 @@ const ZiglingStep = struct {
zig_args.append("-lc") catch unreachable;
}

if (builder.color != .auto) {
zig_args.append("--color") catch unreachable;
zig_args.append(@tagName(builder.color)) catch unreachable;
}

const zig_file = std.fs.path.join(builder.allocator, &[_][]const u8{ if (self.use_healed) "patches/healed" else "exercises", self.exercise.main_file }) catch unreachable;
zig_args.append(builder.pathFromRoot(zig_file)) catch unreachable;

Expand Down