Skip to content

Commit dfcf391

Browse files
authored
Upgrade to Zig version 0.16.0 (#14)
1 parent 32a256e commit dfcf391

19 files changed

Lines changed: 440 additions & 163 deletions

.github/workflows/docs.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Publish API Documentation
1+
name: Publish API documentation
22

33
on:
44
workflow_dispatch:
@@ -17,23 +17,23 @@ jobs:
1717
deploy-docs:
1818
runs-on: ubuntu-latest
1919
steps:
20-
- name: Checkout Repository
20+
- name: Checkout repository
2121
uses: actions/checkout@v4
2222

23-
- name: Install Zig
24-
uses: goto-bus-stop/setup-zig@v2
25-
with:
26-
version: '0.15.2'
23+
- name: Install Zig 0.16.0
24+
run: |
25+
curl -sSfL https://ziglang.org/download/0.16.0/zig-x86_64-linux-0.16.0.tar.xz | tar -xJ
26+
echo "$PWD/zig-x86_64-linux-0.16.0" >> "$GITHUB_PATH"
2727
28-
- name: Install System Dependencies
28+
- name: Install dependencies
2929
run: |
3030
sudo apt-get update
3131
sudo apt-get install -y make
3232
33-
- name: Generate Documentation
33+
- name: Generate documentation
3434
run: make docs
3535

36-
- name: Deploy to GitHub Pages
36+
- name: Deploy to GitHub pages
3737
uses: peaceiris/actions-gh-pages@v4
3838
with:
3939
github_token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/tests.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Run Tests
1+
name: Run tests
22

33
on:
44
workflow_dispatch:
@@ -24,18 +24,18 @@ jobs:
2424
runs-on: ubuntu-latest
2525

2626
steps:
27-
- name: Checkout Repository
27+
- name: Checkout repository
2828
uses: actions/checkout@v4
2929

30-
- name: Install Zig
31-
uses: goto-bus-stop/setup-zig@v2
32-
with:
33-
version: '0.15.2'
30+
- name: Install Zig 0.16.0
31+
run: |
32+
curl -sSfL https://ziglang.org/download/0.16.0/zig-x86_64-linux-0.16.0.tar.xz | tar -xJ
33+
echo "$PWD/zig-x86_64-linux-0.16.0" >> "$GITHUB_PATH"
3434
35-
- name: Install Dependencies
35+
- name: Install dependencies
3636
run: |
3737
sudo apt-get update
3838
sudo apt-get install -y make
3939
40-
- name: Run the Tests
40+
- name: Run the tests
4141
run: make test

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# ################################################################################
22
# # Configuration and Variables
33
# ################################################################################
4-
ZIG ?= $(shell which zig || echo ~/.local/share/zig/0.15.1/zig)
4+
ZIG_LOCAL := $(HOME)/.local/share/zig/0.16.0/zig
5+
ZIG ?= $(shell test -x $(ZIG_LOCAL) && echo $(ZIG_LOCAL) || which zig)
56
BUILD_TYPE ?= Debug
67
BUILD_OPTS = -Doptimize=$(BUILD_TYPE)
78
JOBS ?= $(shell nproc || echo 2)

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<h2>Chilli</h2>
88

99
[![Tests](https://img.shields.io/github/actions/workflow/status/CogitatorTech/chilli/tests.yml?label=tests&style=flat&labelColor=282c34&logo=github)](https://github.com/CogitatorTech/chilli/actions/workflows/tests.yml)
10-
[![Zig Version](https://img.shields.io/badge/Zig-0.15.2-orange?logo=zig&labelColor=282c34)](https://ziglang.org/download)
10+
[![Zig Version](https://img.shields.io/badge/Zig-0.16.0-orange?logo=zig&labelColor=282c34)](https://ziglang.org/download)
1111
[![Docs](https://img.shields.io/badge/docs-read-blue?style=flat&labelColor=282c34&logo=read-the-docs)](https://CogitatorTech.github.io/chilli)
1212
[![Examples](https://img.shields.io/badge/examples-view-green?style=flat&labelColor=282c34&logo=zig)](https://github.com/CogitatorTech/chilli/tree/main/examples)
1313
[![Release](https://img.shields.io/github/release/CogitatorTech/chilli.svg?label=release&style=flat&labelColor=282c34&logo=github)](https://github.com/CogitatorTech/chilli/releases/latest)
@@ -104,16 +104,16 @@ fn greet(ctx: chilli.CommandContext) !void {
104104
const name = try ctx.getFlag("name", []const u8);
105105
const excitement = try ctx.getFlag("excitement", u32);
106106
107-
std.print("Hello, {s}", .{name});
107+
std.debug.print("Hello, {s}", .{name});
108108
var i: u32 = 0;
109109
while (i < excitement) : (i += 1) {
110-
std.print("!", .{});
110+
std.debug.print("!", .{});
111111
}
112-
std.print("\n", .{});
112+
std.debug.print("\n", .{});
113113
}
114114
115-
pub fn main() anyerror!void {
116-
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
115+
pub fn main(init: std.process.Init.Minimal) anyerror!void {
116+
var gpa: std.heap.DebugAllocator(.{}) = .init;
117117
defer _ = gpa.deinit();
118118
const allocator = gpa.allocator();
119119
@@ -142,15 +142,15 @@ pub fn main() anyerror!void {
142142
});
143143
144144
// Hand control over to the framework
145-
try root_cmd.run(null);
145+
try root_cmd.run(init.args, null);
146146
}
147147
```
148148

149149
You can now run your CLI application with the `--help` flag to see the output below:
150150

151151
```bash
152152
$ ./your-cli-app --help
153-
your-cli-app v0.2.3
153+
your-cli-app v0.3.0
154154
A new CLI built with Chilli
155155

156156
USAGE:

build.zig

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,18 @@ pub fn build(b: *std.Build) void {
6262

6363
// --- Example Setup ---
6464
const examples_path = "examples";
65+
const io = b.graph.io;
6566
examples_blk: {
6667
// If the examples directory isn't present (common when used as a dependency),
6768
// skip setting up example artifacts instead of panicking.
68-
var examples_dir = fs.cwd().openDir(examples_path, .{ .iterate = true }) catch |err| {
69+
var examples_dir = b.build_root.handle.openDir(io, examples_path, .{ .iterate = true }) catch |err| {
6970
if (err == error.FileNotFound or err == error.NotDir) break :examples_blk;
7071
@panic("Can't open 'examples' directory");
7172
};
72-
defer examples_dir.close();
73+
defer examples_dir.close(io);
7374

7475
var dir_iter = examples_dir.iterate();
75-
while (dir_iter.next() catch @panic("Failed to iterate examples")) |entry| {
76+
while (dir_iter.next(io) catch @panic("Failed to iterate examples")) |entry| {
7677
if (!std.mem.endsWith(u8, entry.name, ".zig")) continue;
7778

7879
const exe_name = fs.path.stem(entry.name);

build.zig.zon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
.{
22
.name = .chilli,
3-
.version = "0.2.3",
3+
.version = "0.3.0",
44
.fingerprint = 0x6c259741ae4f5f73, // Changing this has security and trust implications.
5-
.minimum_zig_version = "0.15.2",
5+
.minimum_zig_version = "0.16.0",
66
.paths = .{
77
"build.zig",
88
"build.zig.zon",

examples/e1_simple_cli.zig

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ const AppContext = struct {
55
config_path: []const u8,
66
};
77

8-
pub fn main() anyerror!void {
9-
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
8+
pub fn main(init: std.process.Init.Minimal) anyerror!void {
9+
var gpa: std.heap.DebugAllocator(.{}) = .init;
1010
defer _ = gpa.deinit();
1111
const allocator = gpa.allocator();
1212

@@ -54,13 +54,17 @@ pub fn main() anyerror!void {
5454
.variadic = true,
5555
});
5656

57-
try root_command.run(&app_context);
57+
try root_command.run(init.args, &app_context);
5858
}
5959

6060
fn rootExec(ctx: chilli.CommandContext) anyerror!void {
6161
const app_ctx = ctx.getContextData(AppContext).?;
6262
const config_slice = try ctx.getFlag("config", []const u8);
63-
const stdout = std.fs.File.stdout().deprecatedWriter();
63+
const io = std.Options.debug_io;
64+
var stdout_buf: [4096]u8 = undefined;
65+
var stdout_fw = std.Io.File.stdout().writer(io, &stdout_buf);
66+
defer stdout_fw.flush() catch {};
67+
const stdout = &stdout_fw.interface;
6468

6569
if (app_ctx.config_path.len > 0) {
6670
ctx.app_allocator.free(app_ctx.config_path);
@@ -75,7 +79,11 @@ fn rootExec(ctx: chilli.CommandContext) anyerror!void {
7579
fn runExec(ctx: chilli.CommandContext) anyerror!void {
7680
const task_name = try ctx.getArg("task-name", []const u8);
7781
const files = ctx.getArgs("files");
78-
const stdout = std.fs.File.stdout().deprecatedWriter();
82+
const io = std.Options.debug_io;
83+
var stdout_buf: [4096]u8 = undefined;
84+
var stdout_fw = std.Io.File.stdout().writer(io, &stdout_buf);
85+
defer stdout_fw.flush() catch {};
86+
const stdout = &stdout_fw.interface;
7987

8088
try stdout.print("Running task '{s}'...\n", .{task_name});
8189

examples/e2_nested_commands.zig

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,26 @@ fn rootExec(ctx: chilli.CommandContext) !void {
77

88
fn dbMigrateExec(ctx: chilli.CommandContext) !void {
99
_ = ctx;
10-
const stdout = std.fs.File.stdout().deprecatedWriter();
10+
const io = std.Options.debug_io;
11+
var stdout_buf: [4096]u8 = undefined;
12+
var stdout_fw = std.Io.File.stdout().writer(io, &stdout_buf);
13+
defer stdout_fw.flush() catch {};
14+
const stdout = &stdout_fw.interface;
1115
try stdout.print("Running database migrations...\n", .{});
1216
}
1317

1418
fn dbSeedExec(ctx: chilli.CommandContext) !void {
1519
const file = try ctx.getArg("file", []const u8);
16-
const stdout = std.fs.File.stdout().deprecatedWriter();
20+
const io = std.Options.debug_io;
21+
var stdout_buf: [4096]u8 = undefined;
22+
var stdout_fw = std.Io.File.stdout().writer(io, &stdout_buf);
23+
defer stdout_fw.flush() catch {};
24+
const stdout = &stdout_fw.interface;
1725
try stdout.print("Seeding database from file: {s}\n", .{file});
1826
}
1927

20-
pub fn main() anyerror!void {
21-
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
28+
pub fn main(init: std.process.Init.Minimal) anyerror!void {
29+
var gpa: std.heap.DebugAllocator(.{}) = .init;
2230
defer _ = gpa.deinit();
2331
const allocator = gpa.allocator();
2432

@@ -56,7 +64,7 @@ pub fn main() anyerror!void {
5664
.is_required = true,
5765
});
5866

59-
try root_cmd.run(null);
67+
try root_cmd.run(init.args, null);
6068
}
6169

6270
// Example Invocations

examples/e3_help_output.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ fn dummyExec(ctx: chilli.CommandContext) !void {
66
}
77

88
pub fn main() anyerror!void {
9-
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
9+
var gpa: std.heap.DebugAllocator(.{}) = .init;
1010
defer _ = gpa.deinit();
1111
const allocator = gpa.allocator();
1212

examples/e4_custom_sections.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ fn dummyExec(ctx: chilli.CommandContext) !void {
55
try ctx.command.printHelp();
66
}
77

8-
pub fn main() anyerror!void {
9-
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
8+
pub fn main(init: std.process.Init.Minimal) anyerror!void {
9+
var gpa: std.heap.DebugAllocator(.{}) = .init;
1010
defer _ = gpa.deinit();
1111
const allocator = gpa.allocator();
1212

@@ -56,7 +56,7 @@ pub fn main() anyerror!void {
5656
});
5757
try root_cmd.addSubcommand(cmd_other);
5858

59-
try root_cmd.run(null);
59+
try root_cmd.run(init.args, null);
6060
}
6161

6262
// Example Invocation

0 commit comments

Comments
 (0)