Skip to content

Commit 65540b8

Browse files
committed
Move to Zig 0.14
1 parent 1eba487 commit 65540b8

File tree

19 files changed

+148
-119
lines changed

19 files changed

+148
-119
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- name: Set up Zig
1616
uses: goto-bus-stop/setup-zig@v2
1717
with:
18-
version: '0.12.1'
18+
version: '0.14.1'
1919
- name: Lint
2020
run: ./tools/fmt-check.sh
2121
- 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
@@ -12,7 +12,7 @@ with `zig build`. otherwise, for macOS or non-X11 platforms use SDL2:
1212

1313
## local development
1414

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

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

build.zig

Lines changed: 69 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -31,34 +31,37 @@ pub fn build(b: *std.Build) void {
3131
};
3232

3333
// gui build
34-
const ngui = b.addExecutable(.{
35-
.name = "ngui",
34+
const ngui = b.createModule(.{
3635
.root_source_file = b.path("src/ngui.zig"),
3736
.target = target,
3837
.optimize = optimize,
3938
.link_libc = true,
4039
.strip = strip,
4140
});
42-
ngui.pie = true;
43-
ngui.root_module.addImport("build_options", buildopts_mod);
44-
ngui.addIncludePath(b.path("lib"));
45-
ngui.addIncludePath(b.path("src/ui/c"));
41+
const ngui_exe = b.addExecutable(.{
42+
.name = "ngui",
43+
.root_module = ngui,
44+
});
45+
ngui_exe.pie = true;
46+
ngui_exe.root_module.addImport("build_options", buildopts_mod);
47+
ngui_exe.addIncludePath(b.path("lib"));
48+
ngui_exe.addIncludePath(b.path("src/ui/c"));
4649

4750
const lvgl_flags = .{
4851
"-std=c11",
4952
"-fstack-protector",
5053
"-Wformat",
5154
"-Wformat-security",
5255
} ++ common_cflags;
53-
ngui.addCSourceFiles(.{ .files = lvgl_generic_src, .flags = &lvgl_flags });
56+
ngui_exe.addCSourceFiles(.{ .files = lvgl_generic_src, .flags = &lvgl_flags });
5457

5558
const ngui_cflags = .{
5659
"-std=c11",
5760
"-Wshadow",
5861
"-Wunused-parameter",
5962
"-Werror",
6063
} ++ common_cflags;
61-
ngui.addCSourceFiles(.{
64+
ngui_exe.addCSourceFiles(.{
6265
.root = b.path("src/ui/c"),
6366
.files = &.{
6467
"ui.c",
@@ -69,69 +72,77 @@ pub fn build(b: *std.Build) void {
6972
.flags = &ngui_cflags,
7073
});
7174

72-
ngui.root_module.addCMacro("NM_DISP_HOR", b.fmt("{d}", .{disp_horiz}));
73-
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())");
75+
ngui_exe.root_module.addCMacro("NM_DISP_HOR", b.fmt("{d}", .{disp_horiz}));
76+
ngui_exe.root_module.addCMacro("NM_DISP_VER", b.fmt("{d}", .{disp_vert}));
77+
ngui_exe.root_module.addCMacro("LV_CONF_INCLUDE_SIMPLE", "1");
78+
ngui_exe.root_module.addCMacro("LV_LOG_LEVEL", lvgl_loglevel.text());
79+
ngui_exe.root_module.addCMacro("LV_TICK_CUSTOM", "1");
80+
ngui_exe.root_module.addCMacro("LV_TICK_CUSTOM_INCLUDE", "\"lv_custom_tick.h\"");
81+
ngui_exe.root_module.addCMacro("LV_TICK_CUSTOM_SYS_TIME_EXPR", "(nm_get_curr_tick())");
7982
switch (drv) {
8083
.sdl2 => {
81-
ngui.addCSourceFiles(.{ .files = lvgl_sdl2_src, .flags = &lvgl_flags });
82-
ngui.addCSourceFile(.{ .file = b.path("src/ui/c/drv_sdl2.c"), .flags = &ngui_cflags });
83-
ngui.defineCMacro("USE_SDL", "1");
84-
ngui.linkSystemLibrary("SDL2");
84+
ngui_exe.addCSourceFiles(.{ .files = lvgl_sdl2_src, .flags = &lvgl_flags });
85+
ngui_exe.addCSourceFile(.{ .file = b.path("src/ui/c/drv_sdl2.c"), .flags = &ngui_cflags });
86+
ngui_exe.root_module.addCMacro("USE_SDL", "1");
87+
ngui_exe.linkSystemLibrary("SDL2");
8588
},
8689
.x11 => {
87-
ngui.addCSourceFiles(.{ .files = lvgl_x11_src, .flags = &lvgl_flags });
88-
ngui.addCSourceFiles(.{
90+
ngui_exe.addCSourceFiles(.{ .files = lvgl_x11_src, .flags = &lvgl_flags });
91+
ngui_exe.addCSourceFiles(.{
8992
.files = &.{
9093
"src/ui/c/drv_x11.c",
9194
"src/ui/c/mouse_cursor_icon.c",
9295
},
9396
.flags = &ngui_cflags,
9497
});
95-
ngui.defineCMacro("USE_X11", "1");
96-
ngui.linkSystemLibrary("X11");
98+
ngui_exe.root_module.addCMacro("USE_X11", "1");
99+
ngui_exe.linkSystemLibrary("X11");
97100
},
98101
.fbev => {
99-
ngui.addCSourceFiles(.{ .files = lvgl_fbev_src, .flags = &lvgl_flags });
100-
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");
102+
ngui_exe.addCSourceFiles(.{ .files = lvgl_fbev_src, .flags = &lvgl_flags });
103+
ngui_exe.addCSourceFile(.{ .file = b.path("src/ui/c/drv_fbev.c"), .flags = &ngui_cflags });
104+
ngui_exe.root_module.addCMacro("USE_FBDEV", "1");
105+
ngui_exe.root_module.addCMacro("USE_EVDEV", "1");
103106
},
104107
}
105108

106109
const ngui_build_step = b.step("ngui", "build ngui (nakamochi gui)");
107-
ngui_build_step.dependOn(&b.addInstallArtifact(ngui, .{}).step);
110+
ngui_build_step.dependOn(&b.addInstallArtifact(ngui_exe, .{}).step);
108111

109112
// daemon build
110-
const nd = b.addExecutable(.{
111-
.name = "nd",
113+
const nd = b.createModule(.{
112114
.root_source_file = b.path("src/nd.zig"),
113115
.target = target,
114116
.optimize = optimize,
117+
.link_libc = true,
115118
.strip = strip,
116119
});
117-
nd.pie = true;
118-
nd.root_module.addImport("build_options", buildopts_mod);
119-
nd.root_module.addImport("nif", libnif_dep.module("nif"));
120-
nd.root_module.addImport("ini", libini_dep.module("ini"));
121-
nd.linkLibrary(libnif);
120+
const nd_exe = b.addExecutable(.{
121+
.name = "nd",
122+
.root_module = nd,
123+
});
124+
nd_exe.pie = true;
125+
nd_exe.root_module.addImport("build_options", buildopts_mod);
126+
nd_exe.root_module.addImport("nif", libnif_dep.module("nif"));
127+
nd_exe.root_module.addImport("ini", libini_dep.module("ini"));
128+
nd_exe.linkLibrary(libnif);
122129

123130
const nd_build_step = b.step("nd", "build nd (nakamochi daemon)");
124-
nd_build_step.dependOn(&b.addInstallArtifact(nd, .{}).step);
131+
nd_build_step.dependOn(&b.addInstallArtifact(nd_exe, .{}).step);
125132

126133
// automated tests
127134
{
128-
const tests = b.addTest(.{
135+
const mod_tests = b.createModule(.{
129136
.root_source_file = b.path("src/test.zig"),
130137
.target = target,
131138
.optimize = optimize,
132139
.link_libc = true,
133-
.filter = b.option([]const u8, "test-filter", "run tests matching the filter"),
134140
});
141+
const tests = b.addTest(.{
142+
.root_module = mod_tests,
143+
.filters = &.{b.option([]const u8, "test-filter", "run tests matching the filter") orelse ""},
144+
});
145+
135146
tests.root_module.addImport("build_options", buildopts_mod);
136147
tests.root_module.addImport("nif", libnif_dep.module("nif"));
137148
tests.root_module.addImport("ini", libini_dep.module("ini"));
@@ -144,47 +155,53 @@ pub fn build(b: *std.Build) void {
144155

145156
// GUI playground
146157
{
147-
const guiplay = b.addExecutable(.{
148-
.name = "guiplay",
158+
const guiplay = b.createModule(.{
149159
.root_source_file = b.path("src/test/guiplay.zig"),
150160
.target = target,
151161
.optimize = optimize,
152162
});
153-
guiplay.root_module.addImport("comm", b.createModule(.{ .root_source_file = b.path("src/comm.zig") }));
163+
const guiplay_exe = b.addExecutable(.{
164+
.name = "guiplay",
165+
.root_module = guiplay,
166+
});
167+
guiplay_exe.root_module.addImport("comm", b.createModule(.{ .root_source_file = b.path("src/comm.zig") }));
154168

155169
const guiplay_build_step = b.step("guiplay", "build GUI playground");
156-
guiplay_build_step.dependOn(&b.addInstallArtifact(guiplay, .{}).step);
170+
guiplay_build_step.dependOn(&b.addInstallArtifact(guiplay_exe, .{}).step);
157171
guiplay_build_step.dependOn(ngui_build_step);
158172
}
159173

160174
// bitcoind RPC client playground
161175
{
162-
const btcrpc = b.addExecutable(.{
163-
.name = "btcrpc",
176+
const btcrpc = b.createModule(.{
164177
.root_source_file = b.path("src/test/btcrpc.zig"),
165178
.target = target,
166179
.optimize = optimize,
167180
.strip = strip,
168181
});
169-
btcrpc.root_module.addImport("bitcoindrpc", b.createModule(.{ .root_source_file = b.path("src/bitcoindrpc.zig") }));
182+
const btcrpc_exe = b.addExecutable(.{
183+
.name = "btcrpc",
184+
.root_module = btcrpc,
185+
});
186+
btcrpc_exe.root_module.addImport("bitcoindrpc", b.createModule(.{ .root_source_file = b.path("src/bitcoindrpc.zig") }));
170187

171188
const btcrpc_build_step = b.step("btcrpc", "bitcoind RPC client playground");
172-
btcrpc_build_step.dependOn(&b.addInstallArtifact(btcrpc, .{}).step);
189+
btcrpc_build_step.dependOn(&b.addInstallArtifact(btcrpc_exe, .{}).step);
173190
}
174191

175192
// lnd HTTP API client playground
176193
{
177-
const lndhc = b.addExecutable(.{
178-
.name = "lndhc",
194+
const lndhc = b.createModule(.{
179195
.root_source_file = b.path("src/test/lndhc.zig"),
180196
.target = target,
181197
.optimize = optimize,
182198
.strip = strip,
183199
});
184-
lndhc.root_module.addImport("lightning", b.createModule(.{ .root_source_file = b.path("src/lightning.zig") }));
200+
const lndhc_exe = b.addExecutable(.{ .name = "lndhc", .root_module = lndhc });
201+
lndhc_exe.root_module.addImport("lightning", b.createModule(.{ .root_source_file = b.path("src/lightning.zig") }));
185202

186203
const lndhc_build_step = b.step("lndhc", "lnd HTTP API client playground");
187-
lndhc_build_step.dependOn(&b.addInstallArtifact(lndhc, .{}).step);
204+
lndhc_build_step.dependOn(&b.addInstallArtifact(lndhc_exe, .{}).step);
188205
}
189206

190207
// default build step
@@ -376,7 +393,7 @@ const LVGLLogLevel = enum {
376393
none,
377394

378395
/// returns default mode based on the compiler optimization flags.
379-
fn default(mode: std.builtin.Mode) @This() {
396+
fn default(mode: std.builtin.OptimizeMode) @This() {
380397
return switch (mode) {
381398
.Debug => .warn,
382399
.ReleaseSafe => .warn,
@@ -427,7 +444,7 @@ const VersionStep = struct {
427444
return &vstep.step;
428445
}
429446

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

build.zig.zon

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.{
2-
.name = "ndg",
2+
.name = .ndg,
3+
.fingerprint = 0x6f4f65601db92599,
34
.version = "0.8.1",
45
.dependencies = .{
56
.nif = .{

lib/ini

lib/nif/build.zig

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@ pub fn build(b: *std.Build) void {
55

66
const target = b.standardTargetOptions(.{});
77
const optimize = b.standardOptimizeOption(.{});
8-
const lib = b.addStaticLibrary(.{
9-
.name = "nif",
8+
const lib_mod = b.createModule(.{
109
.root_source_file = b.path("nif.zig"),
1110
.target = target,
1211
.optimize = optimize,
1312
.link_libc = true,
1413
});
15-
lib.defineCMacro("CONFIG_CTRL_IFACE", null);
16-
lib.defineCMacro("CONFIG_CTRL_IFACE_UNIX", null);
14+
const lib = b.addLibrary(.{
15+
.linkage = .static,
16+
.name = "nif",
17+
.root_module = lib_mod,
18+
});
19+
lib.root_module.addCMacro("CONFIG_CTRL_IFACE", "");
20+
lib.root_module.addCMacro("CONFIG_CTRL_IFACE_UNIX", "");
1721
lib.addIncludePath(b.path("wpa_supplicant"));
1822
lib.addCSourceFiles(.{
1923
.files = &.{

src/lightning/LndConf.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ test "lnd: conf load dump" {
229229

230230
var tmp = try tt.TempDir.create();
231231
defer tmp.cleanup();
232-
try tmp.dir.writeFile("conf.ini",
232+
try tmp.dir.writeFile(.{ .sub_path = "conf.ini", .data =
233233
\\; top comment
234234
\\[application options]
235235
\\foo = bar
@@ -239,7 +239,7 @@ test "lnd: conf load dump" {
239239
\\
240240
\\[AutopiloT]
241241
\\autopilot.active=false
242-
);
242+
});
243243
const clean_conf =
244244
\\[application options]
245245
\\foo=bar

src/nd.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ pub fn main() !void {
170170
if (conf.data.slock != null) {
171171
try ngui_args.append("-slock");
172172
}
173-
var ngui = std.ChildProcess.init(ngui_args.items, gpa);
173+
var ngui = std.process.Child.init(ngui_args.items, gpa);
174174
ngui.stdin_behavior = .Pipe;
175175
ngui.stdout_behavior = .Pipe;
176176
ngui.stderr_behavior = .Inherit;
@@ -224,8 +224,8 @@ pub fn main() !void {
224224
.mask = posix.empty_sigset,
225225
.flags = 0,
226226
};
227-
try posix.sigaction(posix.SIG.INT, &sa, null);
228-
try posix.sigaction(posix.SIG.TERM, &sa, null);
227+
posix.sigaction(posix.SIG.INT, &sa, null);
228+
posix.sigaction(posix.SIG.TERM, &sa, null);
229229
sigquit.wait();
230230
logger.info("sigquit: terminating ...", .{});
231231

0 commit comments

Comments
 (0)