Skip to content

Commit df0dc96

Browse files
committed
Upgrade from Zig 0.12 to 0.14
1 parent 8d133b2 commit df0dc96

29 files changed

+284
-144
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
- name: Set up Zig
1313
uses: goto-bus-stop/setup-zig@v2
1414
with:
15-
version: '0.12.1'
15+
version: '0.14.0'
1616
- name: Lint
1717
run: ./tools/fmt-check.sh
1818
- name: Test

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.DS_Store
22
.ccls-cache
3+
.zig-cache
34
zig-cache
45
zig-out

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ with `zig build`. otherwise, for macOS or non-X11 platforms use SDL2:
1111

1212
## local development
1313

14-
you'll need [zig v0.12.x](https://ziglang.org/download/).
14+
you'll need [zig v0.14.x](https://ziglang.org/download/).
1515
if working on the gui using sdl2 driver, also [SDL2](https://www.libsdl.org/).
1616

1717
note that compiling the daemon on macOS is currently unsupported since

build.zig

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,16 @@ pub fn build(b: *std.Build) void {
7171

7272
ngui.root_module.addCMacro("NM_DISP_HOR", b.fmt("{d}", .{disp_horiz}));
7373
ngui.root_module.addCMacro("NM_DISP_VER", b.fmt("{d}", .{disp_vert}));
74-
ngui.defineCMacro("LV_CONF_INCLUDE_SIMPLE", "1");
75-
ngui.defineCMacro("LV_LOG_LEVEL", lvgl_loglevel.text());
76-
ngui.defineCMacro("LV_TICK_CUSTOM", "1");
77-
ngui.defineCMacro("LV_TICK_CUSTOM_INCLUDE", "\"lv_custom_tick.h\"");
78-
ngui.defineCMacro("LV_TICK_CUSTOM_SYS_TIME_EXPR", "(nm_get_curr_tick())");
74+
ngui.root_module.addCMacro("LV_CONF_INCLUDE_SIMPLE", "1");
75+
ngui.root_module.addCMacro("LV_LOG_LEVEL", lvgl_loglevel.text());
76+
ngui.root_module.addCMacro("LV_TICK_CUSTOM", "1");
77+
ngui.root_module.addCMacro("LV_TICK_CUSTOM_INCLUDE", "\"lv_custom_tick.h\"");
78+
ngui.root_module.addCMacro("LV_TICK_CUSTOM_SYS_TIME_EXPR", "(nm_get_curr_tick())");
7979
switch (drv) {
8080
.sdl2 => {
8181
ngui.addCSourceFiles(.{ .files = lvgl_sdl2_src, .flags = &lvgl_flags });
8282
ngui.addCSourceFile(.{ .file = b.path("src/ui/c/drv_sdl2.c"), .flags = &ngui_cflags });
83-
ngui.defineCMacro("USE_SDL", "1");
83+
ngui.root_module.addCMacro("USE_SDL", "1");
8484
ngui.linkSystemLibrary("SDL2");
8585
},
8686
.x11 => {
@@ -92,14 +92,14 @@ pub fn build(b: *std.Build) void {
9292
},
9393
.flags = &ngui_cflags,
9494
});
95-
ngui.defineCMacro("USE_X11", "1");
95+
ngui.root_module.addCMacro("USE_X11", "1");
9696
ngui.linkSystemLibrary("X11");
9797
},
9898
.fbev => {
9999
ngui.addCSourceFiles(.{ .files = lvgl_fbev_src, .flags = &lvgl_flags });
100100
ngui.addCSourceFile(.{ .file = b.path("src/ui/c/drv_fbev.c"), .flags = &ngui_cflags });
101-
ngui.defineCMacro("USE_FBDEV", "1");
102-
ngui.defineCMacro("USE_EVDEV", "1");
101+
ngui.root_module.addCMacro("USE_FBDEV", "1");
102+
ngui.root_module.addCMacro("USE_EVDEV", "1");
103103
},
104104
}
105105

@@ -427,7 +427,7 @@ const VersionStep = struct {
427427
return &vstep.step;
428428
}
429429

430-
fn make(step: *std.Build.Step, _: *std.Progress.Node) anyerror!void {
430+
fn make(step: *std.Build.Step, _: std.Build.Step.MakeOptions) anyerror!void {
431431
const self: *@This() = @fieldParentPtr("step", step);
432432
const semver = try self.eval();
433433
std.log.info("build version: {any}", .{semver});

build.zig.zon

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,86 @@
11
.{
2-
.name = "ndg",
3-
.version = "0.8.1",
2+
// This is the default name used by packages depending on this one. For
3+
// example, when a user runs `zig fetch --save <url>`, this field is used
4+
// as the key in the `dependencies` table. Although the user can choose a
5+
// different name, most users will stick with this provided value.
6+
//
7+
// It is redundant to include "zig" in this name because it is already
8+
// within the Zig package namespace.
9+
.name = .ndg,
10+
11+
// This is a [Semantic Version](https://semver.org/).
12+
// In a future version of Zig it will be used for package deduplication.
13+
.version = "0.9.0-alpha",
14+
15+
// Together with name, this represents a globally unique package
16+
// identifier. This field is generated by the Zig toolchain when the
17+
// package is first created, and then *never changes*. This allows
18+
// unambiguous detection of one package being an updated version of
19+
// another.
20+
//
21+
// When forking a Zig project, this id should be regenerated (delete the
22+
// field and run `zig build`) if the upstream project is still maintained.
23+
// Otherwise, the fork is *hostile*, attempting to take control over the
24+
// original project's identity. Thus it is recommended to leave the comment
25+
// on the following line intact, so that it shows up in code reviews that
26+
// modify the field.
27+
.fingerprint = 0x6f4f6560e5c632bf, // Changing this has security and trust implications.
28+
29+
// Tracks the earliest Zig version that the package considers to be a
30+
// supported use case.
31+
.minimum_zig_version = "0.14.0",
32+
33+
// This field is optional.
34+
// Each dependency must either provide a `url` and `hash`, or a `path`.
35+
// `zig build --fetch` can be used to fetch all dependencies of a package, recursively.
36+
// Once all dependencies are fetched, `zig build` no longer requires
37+
// internet connectivity.
438
.dependencies = .{
539
.nif = .{
640
.path = "lib/nif",
741
},
842
.ini = .{
943
.path = "lib/ini",
1044
},
45+
// See `zig fetch --save <url>` for a command-line interface for adding dependencies.
46+
//.example = .{
47+
// // When updating this field to a new URL, be sure to delete the corresponding
48+
// // `hash`, otherwise you are communicating that you expect to find the old hash at
49+
// // the new URL. If the contents of a URL change this will result in a hash mismatch
50+
// // which will prevent zig from using it.
51+
// .url = "https://example.com/foo.tar.gz",
52+
//
53+
// // This is computed from the file contents of the directory of files that is
54+
// // obtained after fetching `url` and applying the inclusion rules given by
55+
// // `paths`.
56+
// //
57+
// // This field is the source of truth; packages do not come from a `url`; they
58+
// // come from a `hash`. `url` is just one of many possible mirrors for how to
59+
// // obtain a package matching this `hash`.
60+
// //
61+
// // Uses the [multihash](https://multiformats.io/multihash/) format.
62+
// .hash = "...",
63+
//
64+
// // When this is provided, the package is found in a directory relative to the
65+
// // build root. In this case the package's hash is irrelevant and therefore not
66+
// // computed. This field and `url` are mutually exclusive.
67+
// .path = "foo",
68+
//
69+
// // When this is set to `true`, a package is declared to be lazily
70+
// // fetched. This makes the dependency only get fetched if it is
71+
// // actually used.
72+
// .lazy = false,
73+
//},
1174
},
75+
76+
// Specifies the set of files and directories that are included in this package.
77+
// Only files and directories listed here are included in the `hash` that
78+
// is computed for this package. Only files listed here will remain on disk
79+
// when using the zig package manager. As a rule of thumb, one should list
80+
// files required for compilation plus any license(s).
81+
// Paths are relative to the build root. Use the empty string (`""`) to refer to
82+
// the build root itself.
83+
// A directory listed here means that all files within, recursively, are included.
1284
.paths = .{
1385
"build.zig",
1486
"build.zig.zon",

lib/ini/README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
This is a very simple ini-parser library that provides:
44
- Raw record reading
55
- Leading/trailing whitespace removal
6-
- comments based on `;` and `#`
6+
- Comments
77
- Zig API
88
- C API
99

@@ -19,7 +19,9 @@ pub fn main() !void {
1919
const file = try std.fs.cwd().openFile("example.ini", .{});
2020
defer file.close();
2121
22-
var parser = ini.parse(std.testing.allocator, file.reader());
22+
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
23+
defer if (gpa.deinit() != .ok) @panic("memory leaked");
24+
var parser = ini.parse(gpa.allocator(), file.reader(), ";#");
2325
defer parser.deinit();
2426
2527
var writer = std.io.getStdOut().writer();
@@ -46,17 +48,17 @@ int main() {
4648
FILE * f = fopen("example.ini", "rb");
4749
if(!f)
4850
return 1;
49-
51+
5052
struct ini_Parser parser;
51-
ini_create_file(&parser, f);
53+
ini_create_file(&parser, f, ";#", 2);
5254

5355
struct ini_Record record;
5456
while(true)
5557
{
5658
enum ini_Error error = ini_next(&parser, &record);
5759
if(error != INI_SUCCESS)
5860
goto cleanup;
59-
61+
6062
switch(record.type) {
6163
case INI_RECORD_NUL: goto done;
6264
case INI_RECORD_SECTION:
@@ -78,4 +80,4 @@ cleanup:
7880
fclose(f);
7981
return 0;
8082
}
81-
```
83+
```

lib/ini/build.zig

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,69 +5,62 @@ pub fn build(b: *std.Build) void {
55
const target = b.standardTargetOptions(.{});
66

77
_ = b.addModule("ini", .{
8-
.root_source_file = .{
9-
.path = "src/ini.zig",
10-
},
8+
.root_source_file = b.path("src/ini.zig"),
119
});
1210

1311
const lib = b.addStaticLibrary(.{
1412
.name = "ini",
15-
.root_source_file = .{ .path = "src/lib.zig" },
13+
.root_source_file = b.path("src/lib.zig"),
1614
.target = target,
1715
.optimize = optimize,
1816
});
19-
2017
lib.bundle_compiler_rt = true;
21-
lib.addIncludePath(.{ .path = "src" });
18+
lib.addIncludePath(b.path("src"));
2219
lib.linkLibC();
23-
20+
lib.installHeader(b.path("src/ini.h"), "ini.h");
2421
b.installArtifact(lib);
2522

23+
const example_step = b.step("example", "Build examples");
2624
const example_c = b.addExecutable(.{
2725
.name = "example-c",
2826
.optimize = optimize,
2927
.target = target,
3028
});
3129
example_c.addCSourceFile(.{
32-
.file = .{
33-
.path = "example/example.c",
34-
},
30+
.file = b.path("example/example.c"),
3531
.flags = &.{
3632
"-Wall",
3733
"-Wextra",
3834
"-pedantic",
3935
},
4036
});
41-
example_c.addIncludePath(.{ .path = "src" });
37+
example_c.addIncludePath(b.path("src"));
4238
example_c.linkLibrary(lib);
4339
example_c.linkLibC();
44-
45-
b.installArtifact(example_c);
40+
example_step.dependOn(&b.addInstallArtifact(example_c, .{}).step);
4641

4742
const example_zig = b.addExecutable(.{
4843
.name = "example-zig",
49-
.root_source_file = .{ .path = "example/example.zig" },
44+
.root_source_file = b.path("example/example.zig"),
5045
.optimize = optimize,
5146
.target = target,
5247
});
5348
example_zig.root_module.addImport("ini", b.modules.get("ini").?);
49+
example_step.dependOn(&b.addInstallArtifact(example_zig, .{}).step);
5450

55-
b.installArtifact(example_zig);
56-
57-
var main_tests = b.addTest(.{
58-
.root_source_file = .{ .path = "src/test.zig" },
51+
const test_step = b.step("test", "Run library tests");
52+
const main_tests = b.addTest(.{
53+
.root_source_file = b.path("src/test.zig"),
5954
.optimize = optimize,
6055
});
56+
test_step.dependOn(&b.addRunArtifact(main_tests).step);
6157

62-
var binding_tests = b.addTest(.{
63-
.root_source_file = .{ .path = "src/lib-test.zig" },
58+
const binding_tests = b.addTest(.{
59+
.root_source_file = b.path("src/lib-test.zig"),
6460
.optimize = optimize,
6561
});
66-
binding_tests.addIncludePath(.{ .path = "src" });
62+
binding_tests.addIncludePath(b.path("src"));
6763
binding_tests.linkLibrary(lib);
6864
binding_tests.linkLibC();
69-
70-
const test_step = b.step("test", "Run library tests");
71-
test_step.dependOn(&main_tests.step);
72-
test_step.dependOn(&binding_tests.step);
65+
test_step.dependOn(&b.addRunArtifact(binding_tests).step);
7366
}

lib/ini/build.zig.zon

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
.{
2-
.name = "libini",
3-
.version = "0.0.0",
4-
.dependencies = .{},
2+
.name = .ini,
3+
.fingerprint = 0x7757b668623d2460,
4+
.version = "0.1.0",
5+
.minimum_zig_version = "0.14.0",
56
.paths = .{
7+
"LICENCE",
8+
"README.md",
69
"build.zig",
710
"build.zig.zon",
8-
"src",
11+
"src/ini.zig",
912
},
1013
}

lib/ini/example/example.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ int main() {
77
FILE * f = fopen("example.ini", "rb");
88
if(!f)
99
return 1;
10-
10+
1111
struct ini_Parser parser;
12-
ini_create_file(&parser, f);
12+
ini_create_file(&parser, f, ";#", 2);
1313

1414
struct ini_Record record;
1515
while(true)
1616
{
1717
enum ini_Error error = ini_next(&parser, &record);
1818
if(error != INI_SUCCESS)
1919
goto cleanup;
20-
20+
2121
switch(record.type) {
2222
case INI_RECORD_NUL: goto done;
2323
case INI_RECORD_SECTION:
@@ -38,4 +38,4 @@ int main() {
3838
ini_destroy(&parser);
3939
fclose(f);
4040
return 0;
41-
}
41+
}

lib/ini/example/example.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub fn main() !void {
77

88
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
99
defer if (gpa.deinit() != .ok) @panic("memory leaked");
10-
var parser = ini.parse(gpa.allocator(), file.reader());
10+
var parser = ini.parse(gpa.allocator(), file.reader(), ";#");
1111
defer parser.deinit();
1212

1313
var writer = std.io.getStdOut().writer();

0 commit comments

Comments
 (0)