Skip to content

Commit

Permalink
zig update to 0.11.0-dev.2157+f56f3c582
Browse files Browse the repository at this point in the history
  • Loading branch information
marler8997 committed Mar 20, 2023
1 parent c790806 commit 86585be
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v2
- uses: goto-bus-stop/setup-zig@v1
with:
version: 0.11.0-dev.1862+e7f128c20
version: 0.11.0-dev.2157+f56f3c582
- run: |
zig build test -Dfetch -Dis_ci
zig build all -Dis_ci
Expand Down
29 changes: 18 additions & 11 deletions GitRepoStep.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Publish Date: 2023_03_05
//! Publish Date: 2023_03_19
//! This file is hosted at github.com/marler8997/zig-build-repos and is meant to be copied
//! to projects that use it.
const std = @import("std");
Expand All @@ -22,7 +22,6 @@ pub const ShaCheck = enum {
};

step: std.build.Step,
builder: *std.build.Builder,
url: []const u8,
name: []const u8,
branch: ?[]const u8 = null,
Expand All @@ -46,12 +45,19 @@ pub fn create(b: *std.build.Builder, opt: struct {
path: ?[]const u8 = null,
sha_check: ShaCheck = .warn,
fetch_enabled: ?bool = null,
first_ret_addr: ?usize = null,
}) *GitRepoStep {
var result = b.allocator.create(GitRepoStep) catch @panic("memory");
const name = std.fs.path.basename(opt.url);
result.* = GitRepoStep{
.step = std.build.Step.init(.custom, "clone a git repository", b.allocator, make),
.builder = b,
.step = std.build.Step.init(.{
.id = .custom,
.name = b.fmt("clone git repository '{s}'", .{name}),
.owner = b,
.makeFn = make,
.first_ret_addr = opt.first_ret_addr orelse @returnAddress(),
.max_rss = 0,
}),
.url = opt.url,
.name = name,
.branch = opt.branch,
Expand All @@ -76,7 +82,8 @@ fn hasDependency(step: *const std.build.Step, dep_candidate: *const std.build.St
return false;
}

fn make(step: *std.build.Step) !void {
fn make(step: *std.Build.Step, prog_node: *std.Progress.Node) !void {
_ = prog_node;
const self = @fieldParentPtr(GitRepoStep, "step", step);

std.fs.accessAbsolute(self.path, .{}) catch {
Expand All @@ -95,7 +102,7 @@ fn make(step: *std.build.Step) !void {
}

{
var args = std.ArrayList([]const u8).init(self.builder.allocator);
var args = std.ArrayList([]const u8).init(self.step.owner.allocator);
defer args.deinit();
try args.append("git");
try args.append("clone");
Expand All @@ -107,9 +114,9 @@ fn make(step: *std.build.Step) !void {
try args.append("-b");
try args.append(branch);
}
try run(self.builder, args.items);
try run(self.step.owner, args.items);
}
try run(self.builder, &[_][]const u8{
try run(self.step.owner, &[_][]const u8{
"git",
"-C",
self.path,
Expand All @@ -129,16 +136,16 @@ fn checkSha(self: GitRepoStep) !void {

const result: union(enum) { failed: anyerror, output: []const u8 } = blk: {
const result = std.ChildProcess.exec(.{
.allocator = self.builder.allocator,
.allocator = self.step.owner.allocator,
.argv = &[_][]const u8{
"git",
"-C",
self.path,
"rev-parse",
"HEAD",
},
.cwd = self.builder.build_root.path,
.env_map = self.builder.env_map,
.cwd = self.step.owner.build_root.path,
.env_map = self.step.owner.env_map,
}) catch |e| break :blk .{ .failed = e };
try std.io.getStdErr().writer().writeAll(result.stderr);
switch (result.term) {
Expand Down
12 changes: 6 additions & 6 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ pub fn addZigetModule(
optional_ssl_backend: ?SslBackend,
ziget_repo: []const u8,
) void {
const b = compile.builder;
const b = compile.step.owner;
const ziget_index = std.fs.path.join(b.allocator, &[_][]const u8 { ziget_repo, "ziget.zig" }) catch unreachable;
const ssl_module = if (optional_ssl_backend) |backend| addSslBackend(compile, backend, ziget_repo)
else b.createModule(.{ .source_file = .{ .path = "nossl/ssl.zig" } });
Expand All @@ -164,7 +164,7 @@ pub fn addZigetModule(
}

fn addSslBackend(compile: *std.build.CompileStep, backend: SslBackend, ziget_repo: []const u8) *Module {
const b = compile.builder;
const b = compile.step.owner;
switch (backend) {
.std => return b.createModule(.{
.source_file = .{ .path = std.fs.path.join(b.allocator, &[_][]const u8 { ziget_repo, "stdssl.zig" }) catch unreachable },
Expand Down Expand Up @@ -226,9 +226,9 @@ fn addSslBackend(compile: *std.build.CompileStep, backend: SslBackend, ziget_rep
"no-sm3",
"no-sm4",
});
configure_openssl.stdout_action = .{
.expect_matches = &[_][]const u8 { "OpenSSL has been successfully configured" },
};
configure_openssl.addCheck(.{
.expect_stdout_match = "OpenSSL has been successfully configured",
});
const make_openssl = std.build.RunStep.create(b, "configure openssl");
make_openssl.cwd = configure_openssl.cwd;
make_openssl.addArgs(&[_][]const u8 {
Expand Down Expand Up @@ -327,7 +327,7 @@ const OpensslPathOption = struct {
var global_openssl_path_option = OpensslPathOption { };

pub fn setupOpensslWindows(compile: *std.build.CompileStep) void {
const b = compile.builder;
const b = compile.step.owner;

const openssl_path = global_openssl_path_option.get(b) orelse {
compile.step.dependOn(&FailStep.create(b, "missing openssl-path",
Expand Down
17 changes: 9 additions & 8 deletions loggyrunstep.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const print = std.debug.print;

// This saves the RunStep.make function pointer because it is private
var global_run_step_make: switch (builtin.zig_backend) {
.stage1 => ?fn(step: *std.build.Step) anyerror!void,
else => ?*const fn(step: *std.build.Step) anyerror!void,
.stage1 => ?fn(step: *std.build.Step, prog_node: *std.Progress.Node) anyerror!void,
else => ?*const fn(step: *std.build.Step, prog_node: *std.Progress.Node) anyerror!void,
} = null;

pub fn enable(run_step: *RunStep) void {
Expand All @@ -27,18 +27,19 @@ fn printCmd(cwd: ?[]const u8, argv: []const []const u8) void {
print("\n", .{});
}

fn loggyRunStepMake(step: *std.build.Step) !void {
fn loggyRunStepMake(step: *std.build.Step, prog_node: *std.Progress.Node) !void {
const self = @fieldParentPtr(RunStep, "step", step);

const cwd = if (self.cwd) |cwd| self.builder.pathFromRoot(cwd) else self.builder.build_root.path.?;
const cwd = if (self.cwd) |cwd| self.step.owner.pathFromRoot(cwd) else self.step.owner.build_root.path.?;

var argv_list = std.ArrayList([]const u8).init(self.builder.allocator);
var argv_list = std.ArrayList([]const u8).init(self.step.owner.allocator);
for (self.argv.items) |arg| {
switch (arg) {
.bytes => |bytes| try argv_list.append(bytes),
.file_source => |file| try argv_list.append(file.getPath(self.builder)),
.file_source => |file| try argv_list.append(file.getPath(self.step.owner)),
.directory_source => @panic("todo"),
.artifact => |artifact| {
const executable_path = artifact.installed_path orelse artifact.getOutputSource().getPath(self.builder);
const executable_path = artifact.installed_path orelse artifact.getOutputSource().getPath(self.step.owner);
try argv_list.append(executable_path);
},
.output => |output| {
Expand All @@ -47,5 +48,5 @@ fn loggyRunStepMake(step: *std.build.Step) !void {
}
}
printCmd(cwd, argv_list.items);
return global_run_step_make.?(step);
return global_run_step_make.?(step, prog_node);
}

0 comments on commit 86585be

Please sign in to comment.