Skip to content

Commit 0769128

Browse files
committed
Revert "Move to Zig 0.14"
This reverts commit 83cb38d. Upgrade to Zig 0.14 has caused random GUI crashes. This is not a proper solution to a problem, but let's revert for now and then work on a proper fix.
1 parent 7085614 commit 0769128

File tree

19 files changed

+124
-155
lines changed

19 files changed

+124
-155
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,17 @@ jobs:
1515
- name: Set up Zig
1616
uses: goto-bus-stop/setup-zig@v2
1717
with:
18-
version: '0.14.1'
18+
version: '0.12.1'
1919
- name: Lint
2020
run: ./tools/fmt-check.sh
2121
- name: Test
2222
run: zig build test
23-
# - name: Build SDL2
24-
# run: |
25-
# sudo apt-get install -y libsdl2-dev
26-
# zig build -Ddriver=sdl2
27-
- name: Build X11
23+
- name: Build SDL2
2824
run: |
29-
sudo apt-get install -y libx11-dev
30-
zig build -Ddriver=x11
25+
sudo apt-get install -y libsdl2-dev
26+
zig build -Ddriver=sdl2
27+
- name: Build X11
28+
run: zig build -Ddriver=x11
3129
- name: Build Aarch64
3230
run: |
3331
zig build -Ddriver=fbev -Dtarget=aarch64-linux-musl -Doptimize=ReleaseSafe -Dstrip

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
.DS_Store
22
.ccls-cache
3-
.zig-cache
43
zig-cache
54
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.14.x](https://ziglang.org/download/).
15+
you'll need [zig v0.12.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: 52 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -31,37 +31,34 @@ pub fn build(b: *std.Build) void {
3131
};
3232

3333
// gui build
34-
const ngui = b.createModule(.{
34+
const ngui = b.addExecutable(.{
35+
.name = "ngui",
3536
.root_source_file = b.path("src/ngui.zig"),
3637
.target = target,
3738
.optimize = optimize,
3839
.link_libc = true,
3940
.strip = strip,
4041
});
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"));
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"));
4946

5047
const lvgl_flags = .{
5148
"-std=c11",
5249
"-fstack-protector",
5350
"-Wformat",
5451
"-Wformat-security",
5552
} ++ common_cflags;
56-
ngui_exe.addCSourceFiles(.{ .files = lvgl_generic_src, .flags = &lvgl_flags });
53+
ngui.addCSourceFiles(.{ .files = lvgl_generic_src, .flags = &lvgl_flags });
5754

5855
const ngui_cflags = .{
5956
"-std=c11",
6057
"-Wshadow",
6158
"-Wunused-parameter",
6259
"-Werror",
6360
} ++ common_cflags;
64-
ngui_exe.addCSourceFiles(.{
61+
ngui.addCSourceFiles(.{
6562
.root = b.path("src/ui/c"),
6663
.files = &.{
6764
"ui.c",
@@ -72,77 +69,69 @@ pub fn build(b: *std.Build) void {
7269
.flags = &ngui_cflags,
7370
});
7471

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())");
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())");
8279
switch (drv) {
8380
.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");
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");
8885
},
8986
.x11 => {
90-
ngui_exe.addCSourceFiles(.{ .files = lvgl_x11_src, .flags = &lvgl_flags });
91-
ngui_exe.addCSourceFiles(.{
87+
ngui.addCSourceFiles(.{ .files = lvgl_x11_src, .flags = &lvgl_flags });
88+
ngui.addCSourceFiles(.{
9289
.files = &.{
9390
"src/ui/c/drv_x11.c",
9491
"src/ui/c/mouse_cursor_icon.c",
9592
},
9693
.flags = &ngui_cflags,
9794
});
98-
ngui_exe.root_module.addCMacro("USE_X11", "1");
99-
ngui_exe.linkSystemLibrary("X11");
95+
ngui.defineCMacro("USE_X11", "1");
96+
ngui.linkSystemLibrary("X11");
10097
},
10198
.fbev => {
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");
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");
106103
},
107104
}
108105

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

112109
// daemon build
113-
const nd = b.createModule(.{
110+
const nd = b.addExecutable(.{
111+
.name = "nd",
114112
.root_source_file = b.path("src/nd.zig"),
115113
.target = target,
116114
.optimize = optimize,
117-
.link_libc = true,
118115
.strip = strip,
119116
});
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);
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);
129122

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

133126
// automated tests
134127
{
135-
const mod_tests = b.createModule(.{
128+
const tests = b.addTest(.{
136129
.root_source_file = b.path("src/test.zig"),
137130
.target = target,
138131
.optimize = optimize,
139132
.link_libc = true,
133+
.filter = b.option([]const u8, "test-filter", "run tests matching the filter"),
140134
});
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-
146135
tests.root_module.addImport("build_options", buildopts_mod);
147136
tests.root_module.addImport("nif", libnif_dep.module("nif"));
148137
tests.root_module.addImport("ini", libini_dep.module("ini"));
@@ -155,53 +144,47 @@ pub fn build(b: *std.Build) void {
155144

156145
// GUI playground
157146
{
158-
const guiplay = b.createModule(.{
147+
const guiplay = b.addExecutable(.{
148+
.name = "guiplay",
159149
.root_source_file = b.path("src/test/guiplay.zig"),
160150
.target = target,
161151
.optimize = optimize,
162152
});
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") }));
153+
guiplay.root_module.addImport("comm", b.createModule(.{ .root_source_file = b.path("src/comm.zig") }));
168154

169155
const guiplay_build_step = b.step("guiplay", "build GUI playground");
170-
guiplay_build_step.dependOn(&b.addInstallArtifact(guiplay_exe, .{}).step);
156+
guiplay_build_step.dependOn(&b.addInstallArtifact(guiplay, .{}).step);
171157
guiplay_build_step.dependOn(ngui_build_step);
172158
}
173159

174160
// bitcoind RPC client playground
175161
{
176-
const btcrpc = b.createModule(.{
162+
const btcrpc = b.addExecutable(.{
163+
.name = "btcrpc",
177164
.root_source_file = b.path("src/test/btcrpc.zig"),
178165
.target = target,
179166
.optimize = optimize,
180167
.strip = strip,
181168
});
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") }));
169+
btcrpc.root_module.addImport("bitcoindrpc", b.createModule(.{ .root_source_file = b.path("src/bitcoindrpc.zig") }));
187170

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

192175
// lnd HTTP API client playground
193176
{
194-
const lndhc = b.createModule(.{
177+
const lndhc = b.addExecutable(.{
178+
.name = "lndhc",
195179
.root_source_file = b.path("src/test/lndhc.zig"),
196180
.target = target,
197181
.optimize = optimize,
198182
.strip = strip,
199183
});
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") }));
184+
lndhc.root_module.addImport("lightning", b.createModule(.{ .root_source_file = b.path("src/lightning.zig") }));
202185

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

207190
// default build step
@@ -393,7 +376,7 @@ const LVGLLogLevel = enum {
393376
none,
394377

395378
/// returns default mode based on the compiler optimization flags.
396-
fn default(mode: std.builtin.OptimizeMode) @This() {
379+
fn default(mode: std.builtin.Mode) @This() {
397380
return switch (mode) {
398381
.Debug => .warn,
399382
.ReleaseSafe => .warn,
@@ -444,7 +427,7 @@ const VersionStep = struct {
444427
return &vstep.step;
445428
}
446429

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

build.zig.zon

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
.{
2-
.name = .ndg,
3-
.fingerprint = 0x6f4f65601db92599,
2+
.name = "ndg",
43
.version = "0.8.1",
54
.dependencies = .{
65
.nif = .{

lib/ini

lib/nif/build.zig

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

66
const target = b.standardTargetOptions(.{});
77
const optimize = b.standardOptimizeOption(.{});
8-
const lib_mod = b.createModule(.{
8+
const lib = b.addStaticLibrary(.{
9+
.name = "nif",
910
.root_source_file = b.path("nif.zig"),
1011
.target = target,
1112
.optimize = optimize,
1213
.link_libc = true,
1314
});
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", "");
15+
lib.defineCMacro("CONFIG_CTRL_IFACE", null);
16+
lib.defineCMacro("CONFIG_CTRL_IFACE_UNIX", null);
2117
lib.addIncludePath(b.path("wpa_supplicant"));
2218
lib.addCSourceFiles(.{
2319
.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(.{ .sub_path = "conf.ini", .data =
232+
try tmp.dir.writeFile("conf.ini",
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.process.Child.init(ngui_args.items, gpa);
173+
var ngui = std.ChildProcess.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-
posix.sigaction(posix.SIG.INT, &sa, null);
228-
posix.sigaction(posix.SIG.TERM, &sa, null);
227+
try posix.sigaction(posix.SIG.INT, &sa, null);
228+
try posix.sigaction(posix.SIG.TERM, &sa, null);
229229
sigquit.wait();
230230
logger.info("sigquit: terminating ...", .{});
231231

0 commit comments

Comments
 (0)