Skip to content

Commit 7f0bda5

Browse files
committed
Updated to Zig 0.14.1, latest bof-launcher and latest zig-yaml.
1 parent e5b3a88 commit 7f0bda5

File tree

4 files changed

+75
-45
lines changed

4 files changed

+75
-45
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
!.gitattributes
3030

3131
# Ignore some special directories
32-
zig-cache
32+
BOF-collection.yaml
33+
.zig-cache
3334
zig-out
3435
backup

build.zig

Lines changed: 52 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,10 @@
11
const std = @import("std");
22

3-
fn osTagStr(os_tag: std.Target.Os.Tag) []const u8 {
4-
return switch (os_tag) {
5-
.windows => "win",
6-
.linux => "lin",
7-
else => unreachable,
8-
};
9-
}
10-
11-
fn cpuArchStr(arch: std.Target.Cpu.Arch) []const u8 {
12-
return switch (arch) {
13-
.x86_64 => "x64",
14-
.x86 => "x86",
15-
.aarch64 => "aarch64",
16-
.arm => "arm",
17-
else => unreachable,
18-
};
19-
}
3+
pub const min_zig_version = std.SemanticVersion{ .major = 0, .minor = 14, .patch = 1 };
204

215
pub fn build(b: *std.Build) void {
6+
ensureZigVersion() catch return;
7+
228
const supported_targets: []const std.Target.Query = &.{
239
.{ .cpu_arch = .x86, .os_tag = .windows, .abi = .gnu },
2410
.{ .cpu_arch = .x86, .os_tag = .linux, .abi = .gnu },
@@ -53,22 +39,20 @@ pub fn build(b: *std.Build) void {
5339
.optimize = optimize,
5440
}).module("yaml");
5541

56-
const bof_launcher_dep = b.dependency("bof_launcher", .{ .optimize = optimize });
42+
const bof_launcher_dep = b.dependency(
43+
"bof_launcher",
44+
.{ .optimize = optimize },
45+
).builder.dependency(
46+
"bof_launcher_lib",
47+
.{ .optimize = optimize, .target = target },
48+
);
5749
const bof_launcher_lib = bof_launcher_dep.artifact(
58-
std.mem.join(
59-
b.allocator,
60-
"_",
61-
&.{ "bof_launcher", osTagStr(target.result.os.tag), cpuArchStr(target.result.cpu.arch) },
62-
) catch unreachable,
50+
b.fmt("bof_launcher_{s}_{s}", .{ osTagStr(target), cpuArchStr(target) }),
6351
);
6452
const bof_launcher_api_module = bof_launcher_dep.module("bof_launcher_api");
6553

6654
const exe = b.addExecutable(.{
67-
.name = std.mem.join(
68-
b.allocator,
69-
"_",
70-
&.{ "cli4bofs", osTagStr(target.result.os.tag), cpuArchStr(target.result.cpu.arch) },
71-
) catch unreachable,
55+
.name = b.fmt("cli4bofs_{s}_{s}", .{ osTagStr(target), cpuArchStr(target) }),
7256
.root_source_file = b.path("src/main.zig"),
7357
.target = target,
7458
.optimize = optimize,
@@ -81,3 +65,43 @@ pub fn build(b: *std.Build) void {
8165
b.installArtifact(exe);
8266
}
8367
}
68+
69+
fn osTagStr(target: std.Build.ResolvedTarget) []const u8 {
70+
return switch (target.result.os.tag) {
71+
.windows => "win",
72+
.linux => "lin",
73+
else => unreachable,
74+
};
75+
}
76+
77+
fn cpuArchStr(target: std.Build.ResolvedTarget) []const u8 {
78+
return switch (target.result.cpu.arch) {
79+
.x86_64 => "x64",
80+
.x86 => "x86",
81+
.aarch64 => "aarch64",
82+
.arm => "arm",
83+
else => unreachable,
84+
};
85+
}
86+
87+
fn ensureZigVersion() !void {
88+
var installed_ver = @import("builtin").zig_version;
89+
installed_ver.build = null;
90+
91+
if (installed_ver.order(min_zig_version) != .eq) {
92+
std.log.err("\n" ++
93+
\\---------------------------------------------------------------------------
94+
\\
95+
\\Installed Zig compiler version is not supported.
96+
\\
97+
\\Required version is: {any}
98+
\\Installed version: {any}
99+
\\
100+
\\Please install supported version and try again.
101+
\\
102+
\\---------------------------------------------------------------------------
103+
\\
104+
, .{ min_zig_version, installed_ver });
105+
return error.ZigIsTooOld;
106+
}
107+
}

build.zig.zon

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.{
2-
.name = "cli4bofs",
3-
.version = "0.1.0",
2+
.name = .cli4bofs,
3+
.version = "0.9.1",
4+
.fingerprint = 0x24054146b73f1bd0,
45
.paths = .{
56
"build.zig",
67
"build.zig.zon",
@@ -11,12 +12,12 @@
1112
},
1213
.dependencies = .{
1314
.bof_launcher = .{
14-
.url = "https://github.com/The-Z-Labs/bof-launcher/archive/4f9e9d50237b7e63079c9708a671a0d18ea1ee8f.tar.gz",
15-
.hash = "122067dfd5fdbea0d8522d60aa57003a2a63499ece9e611caca917ae0fd51f931de2",
15+
.url = "https://github.com/The-Z-Labs/bof-launcher/archive/943a456a2c9b1d4ddf5c667e2d57588275954cf5.tar.gz",
16+
.hash = "bof_launcher-1.0.0-u0w4iMtmCACvVnH0kfCHWinLLQdGUmdVdWjYa_XNo2EK",
1617
},
1718
.zig_yaml = .{
18-
.url = "https://github.com/kubkon/zig-yaml/archive/325dbdd276604dccf184c32fef9600b0ac48343d.tar.gz",
19-
.hash = "1220e8870ca83e47b98807e89b5b636072413f6c09f9b26037e4c98c55e4960ac55a",
19+
.url = "https://github.com/kubkon/zig-yaml/archive/2d42183a7b49742e74f4b1eca8a245e73cb34113.tar.gz",
20+
.hash = "zig_yaml-0.1.0-C1161uaCAgBeGM34gK6grYHDxDEq92BCDbSleBDEqd-s",
2021
},
2122
},
2223
}

src/main.zig

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const std = @import("std");
22
const bofs = @import("bof-launcher");
33
const yaml = @import("yaml");
44

5-
pub const std_options = .{
5+
pub const std_options = std.Options{
66
.log_level = .info,
77
};
88

@@ -147,6 +147,10 @@ pub fn main() !u8 {
147147
defer _ = gpa.deinit();
148148
const allocator = gpa.allocator();
149149

150+
var arena = std.heap.ArenaAllocator.init(allocator);
151+
defer arena.deinit();
152+
const arena_allocator = arena.allocator();
153+
150154
///////////////////////////////////////////////////////////
151155
// 1. look for BOF-collection.yaml file in cwd
152156
// 2. parse it if available and store results in the ArrayList
@@ -160,14 +164,15 @@ pub fn main() !u8 {
160164
const source = try file.readToEndAlloc(allocator, std.math.maxInt(u32));
161165
defer allocator.free(source);
162166

163-
var yaml_file = try yaml.Yaml.load(allocator, source);
164-
errdefer yaml_file.deinit();
167+
var yaml_file: yaml.Yaml = .{ .source = source };
168+
errdefer yaml_file.deinit(allocator);
169+
try yaml_file.load(allocator);
165170

166-
const bofs_collection = try yaml_file.parse([]BofRecord);
171+
const bofs_collection = try yaml_file.parse(arena_allocator, []BofRecord);
167172

168173
break :blk .{ bofs_collection, yaml_file };
169174
};
170-
defer if (yaml_file) |yf| @constCast(&yf).*.deinit();
175+
defer if (yaml_file) |yf| @constCast(&yf).*.deinit(allocator);
171176

172177
///////////////////////////////////////////////////////////
173178
// commands processing:
@@ -196,7 +201,7 @@ pub fn main() !u8 {
196201

197202
var cmd: Cmd = undefined;
198203
var bof_name: [:0]const u8 = undefined;
199-
var bof_path_buffer: [std.fs.MAX_PATH_BYTES:0]u8 = undefined;
204+
var bof_path_buffer: [std.fs.max_path_bytes:0]u8 = undefined;
200205

201206
var list_tag: []u8 = undefined;
202207
var list_by_tag: bool = false;
@@ -304,7 +309,7 @@ pub fn main() !u8 {
304309
for (cmd_args[3..]) |arg| {
305310
// handle case when file:<filepath> argument is provided
306311
if (mem.indexOf(u8, arg, "file:") != null) {
307-
var iter = mem.tokenize(u8, arg, ":");
312+
var iter = mem.tokenizeScalar(u8, arg, ':');
308313

309314
_ = iter.next() orelse return error.BadData;
310315
const file_path = iter.next() orelse return error.BadData;
@@ -340,7 +345,6 @@ pub fn main() !u8 {
340345
.info => {
341346
for (bofs_collection) |bof| {
342347
if (std.mem.eql(u8, bof_name, bof.name)) {
343-
344348
try stdout.print("Name: {s}\n", .{bof.name});
345349
try stdout.print("Description: {s}\n", .{bof.description});
346350
try stdout.print("BOF authors(s): {s}\n", .{bof.author});
@@ -399,7 +403,7 @@ pub fn main() !u8 {
399403
if (bof.errors) |errors| for (errors) |err| {
400404
try stdout.print("{s} ({x}) : {s}\n", .{ err.name, err.code, err.message });
401405
};
402-
406+
403407
try stdout.print("\nEXAMPLES: {s}\n", .{bof.examples});
404408
}
405409
}
@@ -436,7 +440,7 @@ pub fn main() !u8 {
436440
try stdout.print("info <BOF> - Display BOF description and usage examples\n", .{});
437441
} else if (std.mem.eql(u8, cmd_help, "list")) {
438442
try stdout.print("list [TAG] - List BOFs (all or based on TAG) from BOF-collection.yaml file\n", .{});
439-
} else if (std.mem.eql(u8, cmd_help, "help")) {
443+
} else if (std.mem.eql(u8, cmd_help, "help")) {
440444
try stdout.print("help <COMMAND> - Display help about given command\n", .{});
441445
} else {
442446
try stderr.writeAll("Fatal: unrecognized command provided. Aborting.\n");

0 commit comments

Comments
 (0)