Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Set up Zig
uses: goto-bus-stop/setup-zig@v2
with:
version: '0.14.1'
version: '0.12.1'
- name: Lint
run: ./tools/fmt-check.sh
- name: Test
Expand All @@ -25,9 +25,7 @@ jobs:
# sudo apt-get install -y libsdl2-dev
# zig build -Ddriver=sdl2
- name: Build X11
run: |
sudo apt-get install -y libx11-dev
zig build -Ddriver=x11
run: zig build -Ddriver=x11
- name: Build Aarch64
run: |
zig build -Ddriver=fbev -Dtarget=aarch64-linux-musl -Doptimize=ReleaseSafe -Dstrip
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.DS_Store
.ccls-cache
.zig-cache
zig-cache
zig-out
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ with `zig build`. otherwise, for macOS or non-X11 platforms use SDL2:

## local development

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

note that compiling the daemon on macOS is currently unsupported since
Expand Down
121 changes: 52 additions & 69 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -31,37 +31,34 @@ pub fn build(b: *std.Build) void {
};

// gui build
const ngui = b.createModule(.{
const ngui = b.addExecutable(.{
.name = "ngui",
.root_source_file = b.path("src/ngui.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
.strip = strip,
});
const ngui_exe = b.addExecutable(.{
.name = "ngui",
.root_module = ngui,
});
ngui_exe.pie = true;
ngui_exe.root_module.addImport("build_options", buildopts_mod);
ngui_exe.addIncludePath(b.path("lib"));
ngui_exe.addIncludePath(b.path("src/ui/c"));
ngui.pie = true;
ngui.root_module.addImport("build_options", buildopts_mod);
ngui.addIncludePath(b.path("lib"));
ngui.addIncludePath(b.path("src/ui/c"));

const lvgl_flags = .{
"-std=c11",
"-fstack-protector",
"-Wformat",
"-Wformat-security",
} ++ common_cflags;
ngui_exe.addCSourceFiles(.{ .files = lvgl_generic_src, .flags = &lvgl_flags });
ngui.addCSourceFiles(.{ .files = lvgl_generic_src, .flags = &lvgl_flags });

const ngui_cflags = .{
"-std=c11",
"-Wshadow",
"-Wunused-parameter",
"-Werror",
} ++ common_cflags;
ngui_exe.addCSourceFiles(.{
ngui.addCSourceFiles(.{
.root = b.path("src/ui/c"),
.files = &.{
"ui.c",
Expand All @@ -72,77 +69,69 @@ pub fn build(b: *std.Build) void {
.flags = &ngui_cflags,
});

ngui_exe.root_module.addCMacro("NM_DISP_HOR", b.fmt("{d}", .{disp_horiz}));
ngui_exe.root_module.addCMacro("NM_DISP_VER", b.fmt("{d}", .{disp_vert}));
ngui_exe.root_module.addCMacro("LV_CONF_INCLUDE_SIMPLE", "1");
ngui_exe.root_module.addCMacro("LV_LOG_LEVEL", lvgl_loglevel.text());
ngui_exe.root_module.addCMacro("LV_TICK_CUSTOM", "1");
ngui_exe.root_module.addCMacro("LV_TICK_CUSTOM_INCLUDE", "\"lv_custom_tick.h\"");
ngui_exe.root_module.addCMacro("LV_TICK_CUSTOM_SYS_TIME_EXPR", "(nm_get_curr_tick())");
ngui.root_module.addCMacro("NM_DISP_HOR", b.fmt("{d}", .{disp_horiz}));
ngui.root_module.addCMacro("NM_DISP_VER", b.fmt("{d}", .{disp_vert}));
ngui.defineCMacro("LV_CONF_INCLUDE_SIMPLE", "1");
ngui.defineCMacro("LV_LOG_LEVEL", lvgl_loglevel.text());
ngui.defineCMacro("LV_TICK_CUSTOM", "1");
ngui.defineCMacro("LV_TICK_CUSTOM_INCLUDE", "\"lv_custom_tick.h\"");
ngui.defineCMacro("LV_TICK_CUSTOM_SYS_TIME_EXPR", "(nm_get_curr_tick())");
switch (drv) {
.sdl2 => {
ngui_exe.addCSourceFiles(.{ .files = lvgl_sdl2_src, .flags = &lvgl_flags });
ngui_exe.addCSourceFile(.{ .file = b.path("src/ui/c/drv_sdl2.c"), .flags = &ngui_cflags });
ngui_exe.root_module.addCMacro("USE_SDL", "1");
ngui_exe.linkSystemLibrary("SDL2");
ngui.addCSourceFiles(.{ .files = lvgl_sdl2_src, .flags = &lvgl_flags });
ngui.addCSourceFile(.{ .file = b.path("src/ui/c/drv_sdl2.c"), .flags = &ngui_cflags });
ngui.defineCMacro("USE_SDL", "1");
ngui.linkSystemLibrary("SDL2");
},
.x11 => {
ngui_exe.addCSourceFiles(.{ .files = lvgl_x11_src, .flags = &lvgl_flags });
ngui_exe.addCSourceFiles(.{
ngui.addCSourceFiles(.{ .files = lvgl_x11_src, .flags = &lvgl_flags });
ngui.addCSourceFiles(.{
.files = &.{
"src/ui/c/drv_x11.c",
"src/ui/c/mouse_cursor_icon.c",
},
.flags = &ngui_cflags,
});
ngui_exe.root_module.addCMacro("USE_X11", "1");
ngui_exe.linkSystemLibrary("X11");
ngui.defineCMacro("USE_X11", "1");
ngui.linkSystemLibrary("X11");
},
.fbev => {
ngui_exe.addCSourceFiles(.{ .files = lvgl_fbev_src, .flags = &lvgl_flags });
ngui_exe.addCSourceFile(.{ .file = b.path("src/ui/c/drv_fbev.c"), .flags = &ngui_cflags });
ngui_exe.root_module.addCMacro("USE_FBDEV", "1");
ngui_exe.root_module.addCMacro("USE_EVDEV", "1");
ngui.addCSourceFiles(.{ .files = lvgl_fbev_src, .flags = &lvgl_flags });
ngui.addCSourceFile(.{ .file = b.path("src/ui/c/drv_fbev.c"), .flags = &ngui_cflags });
ngui.defineCMacro("USE_FBDEV", "1");
ngui.defineCMacro("USE_EVDEV", "1");
},
}

const ngui_build_step = b.step("ngui", "build ngui (nakamochi gui)");
ngui_build_step.dependOn(&b.addInstallArtifact(ngui_exe, .{}).step);
ngui_build_step.dependOn(&b.addInstallArtifact(ngui, .{}).step);

// daemon build
const nd = b.createModule(.{
const nd = b.addExecutable(.{
.name = "nd",
.root_source_file = b.path("src/nd.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
.strip = strip,
});
const nd_exe = b.addExecutable(.{
.name = "nd",
.root_module = nd,
});
nd_exe.pie = true;
nd_exe.root_module.addImport("build_options", buildopts_mod);
nd_exe.root_module.addImport("nif", libnif_dep.module("nif"));
nd_exe.root_module.addImport("ini", libini_dep.module("ini"));
nd_exe.linkLibrary(libnif);
nd.pie = true;
nd.root_module.addImport("build_options", buildopts_mod);
nd.root_module.addImport("nif", libnif_dep.module("nif"));
nd.root_module.addImport("ini", libini_dep.module("ini"));
nd.linkLibrary(libnif);

const nd_build_step = b.step("nd", "build nd (nakamochi daemon)");
nd_build_step.dependOn(&b.addInstallArtifact(nd_exe, .{}).step);
nd_build_step.dependOn(&b.addInstallArtifact(nd, .{}).step);

// automated tests
{
const mod_tests = b.createModule(.{
const tests = b.addTest(.{
.root_source_file = b.path("src/test.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
.filter = b.option([]const u8, "test-filter", "run tests matching the filter"),
});
const tests = b.addTest(.{
.root_module = mod_tests,
.filters = &.{b.option([]const u8, "test-filter", "run tests matching the filter") orelse ""},
});

tests.root_module.addImport("build_options", buildopts_mod);
tests.root_module.addImport("nif", libnif_dep.module("nif"));
tests.root_module.addImport("ini", libini_dep.module("ini"));
Expand All @@ -155,53 +144,47 @@ pub fn build(b: *std.Build) void {

// GUI playground
{
const guiplay = b.createModule(.{
const guiplay = b.addExecutable(.{
.name = "guiplay",
.root_source_file = b.path("src/test/guiplay.zig"),
.target = target,
.optimize = optimize,
});
const guiplay_exe = b.addExecutable(.{
.name = "guiplay",
.root_module = guiplay,
});
guiplay_exe.root_module.addImport("comm", b.createModule(.{ .root_source_file = b.path("src/comm.zig") }));
guiplay.root_module.addImport("comm", b.createModule(.{ .root_source_file = b.path("src/comm.zig") }));

const guiplay_build_step = b.step("guiplay", "build GUI playground");
guiplay_build_step.dependOn(&b.addInstallArtifact(guiplay_exe, .{}).step);
guiplay_build_step.dependOn(&b.addInstallArtifact(guiplay, .{}).step);
guiplay_build_step.dependOn(ngui_build_step);
}

// bitcoind RPC client playground
{
const btcrpc = b.createModule(.{
const btcrpc = b.addExecutable(.{
.name = "btcrpc",
.root_source_file = b.path("src/test/btcrpc.zig"),
.target = target,
.optimize = optimize,
.strip = strip,
});
const btcrpc_exe = b.addExecutable(.{
.name = "btcrpc",
.root_module = btcrpc,
});
btcrpc_exe.root_module.addImport("bitcoindrpc", b.createModule(.{ .root_source_file = b.path("src/bitcoindrpc.zig") }));
btcrpc.root_module.addImport("bitcoindrpc", b.createModule(.{ .root_source_file = b.path("src/bitcoindrpc.zig") }));

const btcrpc_build_step = b.step("btcrpc", "bitcoind RPC client playground");
btcrpc_build_step.dependOn(&b.addInstallArtifact(btcrpc_exe, .{}).step);
btcrpc_build_step.dependOn(&b.addInstallArtifact(btcrpc, .{}).step);
}

// lnd HTTP API client playground
{
const lndhc = b.createModule(.{
const lndhc = b.addExecutable(.{
.name = "lndhc",
.root_source_file = b.path("src/test/lndhc.zig"),
.target = target,
.optimize = optimize,
.strip = strip,
});
const lndhc_exe = b.addExecutable(.{ .name = "lndhc", .root_module = lndhc });
lndhc_exe.root_module.addImport("lightning", b.createModule(.{ .root_source_file = b.path("src/lightning.zig") }));
lndhc.root_module.addImport("lightning", b.createModule(.{ .root_source_file = b.path("src/lightning.zig") }));

const lndhc_build_step = b.step("lndhc", "lnd HTTP API client playground");
lndhc_build_step.dependOn(&b.addInstallArtifact(lndhc_exe, .{}).step);
lndhc_build_step.dependOn(&b.addInstallArtifact(lndhc, .{}).step);
}

// default build step
Expand Down Expand Up @@ -393,7 +376,7 @@ const LVGLLogLevel = enum {
none,

/// returns default mode based on the compiler optimization flags.
fn default(mode: std.builtin.OptimizeMode) @This() {
fn default(mode: std.builtin.Mode) @This() {
return switch (mode) {
.Debug => .warn,
.ReleaseSafe => .warn,
Expand Down Expand Up @@ -444,7 +427,7 @@ const VersionStep = struct {
return &vstep.step;
}

fn make(step: *std.Build.Step, _: std.Build.Step.MakeOptions) anyerror!void {
fn make(step: *std.Build.Step, _: *std.Progress.Node) anyerror!void {
const self: *@This() = @fieldParentPtr("step", step);
const semver = try self.eval();
std.log.info("build version: {any}", .{semver});
Expand Down
3 changes: 1 addition & 2 deletions build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
.{
.name = .ndg,
.fingerprint = 0x6f4f65601db92599,
.name = "ndg",
.version = "0.8.1",
.dependencies = .{
.nif = .{
Expand Down
2 changes: 1 addition & 1 deletion lib/ini
Submodule ini updated 2 files
+1 −1 .gitignore
+13 −9 build.zig
12 changes: 4 additions & 8 deletions lib/nif/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,15 @@ pub fn build(b: *std.Build) void {

const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const lib_mod = b.createModule(.{
const lib = b.addStaticLibrary(.{
.name = "nif",
.root_source_file = b.path("nif.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
const lib = b.addLibrary(.{
.linkage = .static,
.name = "nif",
.root_module = lib_mod,
});
lib.root_module.addCMacro("CONFIG_CTRL_IFACE", "");
lib.root_module.addCMacro("CONFIG_CTRL_IFACE_UNIX", "");
lib.defineCMacro("CONFIG_CTRL_IFACE", null);
lib.defineCMacro("CONFIG_CTRL_IFACE_UNIX", null);
lib.addIncludePath(b.path("wpa_supplicant"));
lib.addCSourceFiles(.{
.files = &.{
Expand Down
4 changes: 2 additions & 2 deletions src/lightning/LndConf.zig
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ test "lnd: conf load dump" {

var tmp = try tt.TempDir.create();
defer tmp.cleanup();
try tmp.dir.writeFile(.{ .sub_path = "conf.ini", .data =
try tmp.dir.writeFile("conf.ini",
\\; top comment
\\[application options]
\\foo = bar
Expand All @@ -239,7 +239,7 @@ test "lnd: conf load dump" {
\\
\\[AutopiloT]
\\autopilot.active=false
});
);
const clean_conf =
\\[application options]
\\foo=bar
Expand Down
6 changes: 3 additions & 3 deletions src/nd.zig
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ pub fn main() !void {
if (conf.data.slock != null) {
try ngui_args.append("-slock");
}
var ngui = std.process.Child.init(ngui_args.items, gpa);
var ngui = std.ChildProcess.init(ngui_args.items, gpa);
ngui.stdin_behavior = .Pipe;
ngui.stdout_behavior = .Pipe;
ngui.stderr_behavior = .Inherit;
Expand Down Expand Up @@ -224,8 +224,8 @@ pub fn main() !void {
.mask = posix.empty_sigset,
.flags = 0,
};
posix.sigaction(posix.SIG.INT, &sa, null);
posix.sigaction(posix.SIG.TERM, &sa, null);
try posix.sigaction(posix.SIG.INT, &sa, null);
try posix.sigaction(posix.SIG.TERM, &sa, null);
sigquit.wait();
logger.info("sigquit: terminating ...", .{});

Expand Down
Loading
Loading