Skip to content

Commit

Permalink
upgrade zig to 0.12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
softprops committed Apr 26, 2024
1 parent 6c3ebcc commit 6dfcb96
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ jobs:
uses: actions/checkout@v4
- uses: goto-bus-stop/setup-zig@v2
with:
version: 0.11.0
version: 0.12.0
- name: Test
run: zig build test --summary all
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 0.1.0

initial release
44 changes: 26 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

---

[![CI](https://github.com/softprops/zig-termsize/actions/workflows/ci.yml/badge.svg)](https://github.com/softprops/zig-termsize/actions/workflows/ci.yml) ![License Info](https://img.shields.io/github/license/softprops/zig-termsize) ![Release](https://img.shields.io/github/v/release/softprops/zig-termsize) [![Zig Support](https://img.shields.io/badge/zig-0.11.0-black?logo=zig)](https://ziglang.org/documentation/0.11.0/)
[![CI](https://github.com/softprops/zig-termsize/actions/workflows/ci.yml/badge.svg)](https://github.com/softprops/zig-termsize/actions/workflows/ci.yml) ![License Info](https://img.shields.io/github/license/softprops/zig-termsize) ![Release](https://img.shields.io/github/v/release/softprops/zig-termsize) [![Zig Support](https://img.shields.io/badge/zig-0.12.0-black?logo=zig)](https://ziglang.org/documentation/0.12.0/)

## 🍬 features

Expand All @@ -33,18 +33,26 @@ Create a `build.zig.zon` file to declare a dependency

> .zon short for "zig object notation" files are essentially zig structs. `build.zig.zon` is zigs native package manager convention for where to declare dependencies
```zig
Starting in zig 0.12.0, you can use and should prefer

```sh
zig fetch --save https://github.com/softprops/zig-termsize/archive/refs/tags/v0.1.0.tar.gz
```

otherwise, to manually add it, do so as follows

```diff
.{
.name = "my-app",
.version = "0.1.0",
.dependencies = .{
// 👇 declare dep properties
.termsize = .{
// 👇 uri to download
.url = "https://github.com/softprops/zig-termsize/archive/refs/tags/v0.1.0.tar.gz",
// 👇 hash verification
.hash = "{current-hash}",
},
+ // 👇 declare dep properties
+ .termsize = .{
+ // 👇 uri to download
+ .url = "https://github.com/softprops/zig-termsize/archive/refs/tags/v0.1.0.tar.gz",
+ // 👇 hash verification
+ .hash = "{current-hash}",
+ },
},
}
```
Expand All @@ -53,26 +61,26 @@ Create a `build.zig.zon` file to declare a dependency
Add the following in your `build.zig` file

```zig
```diff
const std = @import("std");

pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});

const optimize = b.standardOptimizeOption(.{});
// 👇 de-reference termsize dep from build.zig.zon
const termsize = b.dependency("termsize", .{
.target = target,
.optimize = optimize,
});
+ // 👇 de-reference termsize dep from build.zig.zon
+ const termsize = b.dependency("termsize", .{
+ .target = target,
+ .optimize = optimize,
+ }).module("termsize");
var exe = b.addExecutable(.{
.name = "your-exe",
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});
// 👇 add the termsize module to executable
exe.addModule("termsize", termsize.module("termsize"));
+ // 👇 add the termsize module to executable
+ exe.addModule("termsize", termsize);

b.installArtifact(exe);
}
Expand All @@ -87,4 +95,4 @@ Does this look interesting but you're new to zig and feel left out? No problem,
- [ziglearn](https://ziglearn.org/)
- [ziglings exercises](https://github.com/ratfactor/ziglings)

\- softprops 2023
\- softprops 2024
10 changes: 4 additions & 6 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ pub fn build(b: *std.Build) !void {

// create a module to be used internally.
const termsize_module = b.createModule(.{
// fixme(0.12): .source_file -> root_source_file
.source_file = .{ .path = "src/main.zig" },
.root_source_file = b.path("src/main.zig"),
});

// register the module so it can be referenced
Expand All @@ -28,7 +27,7 @@ pub fn build(b: *std.Build) !void {
// Creates a step for unit testing. This only builds the test executable
// but does not run it.
const main_tests = b.addTest(.{
.root_source_file = .{ .path = "src/main.zig" },
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
Expand Down Expand Up @@ -70,12 +69,11 @@ pub fn build(b: *std.Build) !void {

var exe = b.addExecutable(.{
.name = example.name,
.root_source_file = .{ .path = example.src },
.root_source_file = b.path(example.src),
.target = target,
.optimize = optimize,
});
// fixme(0.12): addModule -> root_module.addImport(name, mod)
exe.addModule("termsize", termsize_module);
exe.root_module.addImport("termsize", termsize_module);

// run the artifact - depending on the example exe
const example_run = b.addRunArtifact(exe);
Expand Down
2 changes: 1 addition & 1 deletion build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.{
.name = "termsize",
.version = "0.1.0",
.minimum_zig_version = "0.11.0",
.minimum_zig_version = "0.12.0",
.paths = .{""},
}
5 changes: 4 additions & 1 deletion examples/demo/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@ const std = @import("std");
const termsize = @import("termsize");

pub fn main() !void {
std.debug.print("{any}", .{termsize.termSize(std.io.getStdOut())});
std.debug.print(
"{any}",
.{termsize.termSize(std.io.getStdOut())},
);
}
10 changes: 5 additions & 5 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ pub fn termSize(file: std.fs.File) !?TermSize {
};
},
.linux, .macos => blk: {
var buf: os.system.winsize = undefined;
break :blk switch (os.system.getErrno(
os.system.ioctl(
var buf: std.posix.system.winsize = undefined;
break :blk switch (std.posix.errno(
std.posix.system.ioctl(
file.handle,
os.system.T.IOCGWINSZ,
std.posix.T.IOCGWINSZ,
@intFromPtr(&buf),
),
)) {
Expand All @@ -65,5 +65,5 @@ pub fn termSize(file: std.fs.File) !?TermSize {
}

test "termSize" {
std.debug.print("{any}", .{termSize(std.io.getStdOut())});
std.debug.print("termsize {any}", .{termSize(std.io.getStdOut())});
}

0 comments on commit 6dfcb96

Please sign in to comment.