-
Notifications
You must be signed in to change notification settings - Fork 5
Update for 0.15 #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,3 +4,4 @@ deps/notcurses | |
| .idea | ||
| .clj-kondo | ||
| .nrepl-port | ||
| .zig-cache | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| const Builder = @import("std").build.Builder; | ||
| const std = @import("std"); | ||
|
|
||
| pub fn build(b: *Builder) void { | ||
| pub fn build(b: *std.Build) void { | ||
| // Standard target options allows the person running `zig build` to choose | ||
| // what target to build for. Here we do not override the defaults, which | ||
| // means any target is allowed, and the default is native. Other options | ||
|
|
@@ -14,85 +14,97 @@ pub fn build(b: *Builder) void { | |
|
|
||
| const notcurses_source_path = "deps/notcurses"; | ||
|
|
||
| const notcurses = b.addStaticLibrary(.{ | ||
| .name = "notcurses", | ||
| const notcurses_module = b.createModule(.{ | ||
| .target = target, | ||
| .optimize = optimize, | ||
| // notcurses has saome undefined benavior which makes the demo crash with | ||
| // illegal instruction, disabling UBSAN to make it work (-fno-sanitize-c) | ||
| .sanitize_c = std.zig.SanitizeC.off, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can add |
||
| }); | ||
| const notcurses = b.addLibrary(.{ | ||
| .name = "notcurses", | ||
| .root_module = notcurses_module, | ||
| }); | ||
| // notcurses has saome undefined benavior which makes the demo crash with | ||
| // illegal instruction, disabling UBSAN to make it work (-fno-sanitize-c) | ||
| notcurses.disable_sanitize_c = true; | ||
|
|
||
| // TODO: Reenable this | ||
| //notcurses.disable_sanitize_c = true; | ||
| notcurses.linkLibC(); | ||
|
|
||
| notcurses.linkSystemLibrary("deflate"); | ||
| notcurses.linkSystemLibrary("ncurses"); | ||
| notcurses.linkSystemLibrary("readline"); | ||
| notcurses.linkSystemLibrary("unistring"); | ||
| notcurses.linkSystemLibrary("z"); | ||
| notcurses.addIncludePath(b.path(notcurses_source_path ++ "/include")); | ||
| notcurses.addIncludePath(b.path(notcurses_source_path ++ "/build/include")); | ||
| notcurses.addIncludePath(b.path(notcurses_source_path ++ "/src")); | ||
| notcurses.addCSourceFiles(.{ | ||
| .files = &[_][]const u8{ | ||
| notcurses_source_path ++ "/src/compat/compat.c", | ||
|
|
||
| notcurses.addIncludePath(.{ .path = notcurses_source_path ++ "/include" }); | ||
| notcurses.addIncludePath(.{ .path = notcurses_source_path ++ "/build/include" }); | ||
| notcurses.addIncludePath(.{ .path = notcurses_source_path ++ "/src" }); | ||
| notcurses.addCSourceFiles(&[_][]const u8{ | ||
| notcurses_source_path ++ "/src/compat/compat.c", | ||
| notcurses_source_path ++ "/src/lib/automaton.c", | ||
| notcurses_source_path ++ "/src/lib/banner.c", | ||
| notcurses_source_path ++ "/src/lib/blit.c", | ||
| notcurses_source_path ++ "/src/lib/debug.c", | ||
| notcurses_source_path ++ "/src/lib/direct.c", | ||
| notcurses_source_path ++ "/src/lib/fade.c", | ||
| notcurses_source_path ++ "/src/lib/fd.c", | ||
| notcurses_source_path ++ "/src/lib/fill.c", | ||
| notcurses_source_path ++ "/src/lib/gpm.c", | ||
| notcurses_source_path ++ "/src/lib/in.c", | ||
| notcurses_source_path ++ "/src/lib/kitty.c", | ||
| notcurses_source_path ++ "/src/lib/layout.c", | ||
| notcurses_source_path ++ "/src/lib/linux.c", | ||
| notcurses_source_path ++ "/src/lib/menu.c", | ||
| notcurses_source_path ++ "/src/lib/metric.c", | ||
| notcurses_source_path ++ "/src/lib/mice.c", | ||
| notcurses_source_path ++ "/src/lib/notcurses.c", | ||
| notcurses_source_path ++ "/src/lib/plot.c", | ||
| notcurses_source_path ++ "/src/lib/progbar.c", | ||
| notcurses_source_path ++ "/src/lib/reader.c", | ||
| notcurses_source_path ++ "/src/lib/reel.c", | ||
| notcurses_source_path ++ "/src/lib/render.c", | ||
| notcurses_source_path ++ "/src/lib/selector.c", | ||
| notcurses_source_path ++ "/src/lib/sixel.c", | ||
| notcurses_source_path ++ "/src/lib/sprite.c", | ||
| notcurses_source_path ++ "/src/lib/stats.c", | ||
| notcurses_source_path ++ "/src/lib/tabbed.c", | ||
| notcurses_source_path ++ "/src/lib/termdesc.c", | ||
| notcurses_source_path ++ "/src/lib/tree.c", | ||
| notcurses_source_path ++ "/src/lib/unixsig.c", | ||
| notcurses_source_path ++ "/src/lib/util.c", | ||
| notcurses_source_path ++ "/src/lib/visual.c", | ||
| notcurses_source_path ++ "/src/lib/windows.c", | ||
| }, | ||
| .flags = &[_][]const u8{ | ||
| "-std=gnu11", | ||
| "-D_GNU_SOURCE", // to make memory management work, see sys/mman.h | ||
| "-DUSE_MULTIMEDIA=none", | ||
| "-DUSE_QRCODEGEN=OFF", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You'll want to drop this define, since the C files make use of it with |
||
| "-DPOLLRDHUP=0x2000", | ||
| }, | ||
| }); | ||
|
|
||
| notcurses_source_path ++ "/src/lib/automaton.c", | ||
| notcurses_source_path ++ "/src/lib/banner.c", | ||
| notcurses_source_path ++ "/src/lib/blit.c", | ||
| notcurses_source_path ++ "/src/lib/debug.c", | ||
| notcurses_source_path ++ "/src/lib/direct.c", | ||
| notcurses_source_path ++ "/src/lib/fade.c", | ||
| notcurses_source_path ++ "/src/lib/fd.c", | ||
| notcurses_source_path ++ "/src/lib/fill.c", | ||
| notcurses_source_path ++ "/src/lib/gpm.c", | ||
| notcurses_source_path ++ "/src/lib/in.c", | ||
| notcurses_source_path ++ "/src/lib/kitty.c", | ||
| notcurses_source_path ++ "/src/lib/layout.c", | ||
| notcurses_source_path ++ "/src/lib/linux.c", | ||
| notcurses_source_path ++ "/src/lib/menu.c", | ||
| notcurses_source_path ++ "/src/lib/metric.c", | ||
| notcurses_source_path ++ "/src/lib/mice.c", | ||
| notcurses_source_path ++ "/src/lib/notcurses.c", | ||
| notcurses_source_path ++ "/src/lib/plot.c", | ||
| notcurses_source_path ++ "/src/lib/progbar.c", | ||
| notcurses_source_path ++ "/src/lib/reader.c", | ||
| notcurses_source_path ++ "/src/lib/reel.c", | ||
| notcurses_source_path ++ "/src/lib/render.c", | ||
| notcurses_source_path ++ "/src/lib/selector.c", | ||
| notcurses_source_path ++ "/src/lib/sixel.c", | ||
| notcurses_source_path ++ "/src/lib/sprite.c", | ||
| notcurses_source_path ++ "/src/lib/stats.c", | ||
| notcurses_source_path ++ "/src/lib/tabbed.c", | ||
| notcurses_source_path ++ "/src/lib/termdesc.c", | ||
| notcurses_source_path ++ "/src/lib/tree.c", | ||
| notcurses_source_path ++ "/src/lib/unixsig.c", | ||
| notcurses_source_path ++ "/src/lib/util.c", | ||
| notcurses_source_path ++ "/src/lib/visual.c", | ||
| notcurses_source_path ++ "/src/lib/windows.c", | ||
| }, &[_][]const u8{ | ||
| "-std=gnu11", | ||
| "-D_GNU_SOURCE", // to make memory management work, see sys/mman.h | ||
| "-DUSE_MULTIMEDIA=none", | ||
| "-DUSE_QRCODEGEN=OFF", | ||
| "-DPOLLRDHUP=0x2000", | ||
| const exe_module = b.createModule(.{ | ||
| .root_source_file = b.path("src/main.zig"), | ||
| .target = target, | ||
| .optimize = optimize, | ||
| }); | ||
| exe_module.linkLibrary(notcurses); | ||
| exe_module.linkSystemLibrary("qrcodegen", .{}); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Drop this link as well if the previously mentioned define is removed |
||
| exe_module.linkSystemLibrary("deflate", .{}); | ||
| exe_module.linkSystemLibrary("tinfo", .{}); | ||
| exe_module.linkSystemLibrary("ncurses", .{}); | ||
| exe_module.linkSystemLibrary("readline", .{}); | ||
| exe_module.linkSystemLibrary("unistring", .{}); | ||
| exe_module.linkSystemLibrary("z", .{}); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These should be attached to the |
||
|
|
||
| const exe = b.addExecutable(.{ | ||
| .name = "demo", | ||
| .root_source_file = .{ .path = "src/main.zig" }, | ||
| .target = target, | ||
| .optimize = optimize, | ||
| .root_module = exe_module, | ||
| }); | ||
| b.installArtifact(exe); | ||
| exe.linkLibC(); | ||
|
|
||
| // exe.linkSystemLibrary("notcurses-core"); | ||
| // exe.addObjectFile(notcurses_source_path ++ "/build/libnotcurses-core.a"); | ||
|
|
||
| exe.addIncludePath(.{ .path = notcurses_source_path ++ "/include" }); | ||
| exe.linkLibrary(notcurses); | ||
| exe.linkSystemLibrary("notcurses-core"); | ||
| exe.addObjectFile(b.path(notcurses_source_path ++ "/build/libnotcurses-core.a")); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Neither of seem to be needed as we are compiling the code into a Zig module, not building it externally into a static lib. |
||
|
|
||
| exe.linkSystemLibrary("qrcodegen"); | ||
| exe.addIncludePath(b.path(notcurses_source_path ++ "/include")); | ||
|
|
||
| const run_cmd = b.addRunArtifact(exe); | ||
| run_cmd.step.dependOn(b.getInstallStep()); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,50 @@ | ||
| const c = @cImport({ | ||
| @cInclude("notcurses/notcurses.h"); | ||
| }); | ||
| pub usingnamespace c; | ||
|
|
||
| // Re-export the C symbols we need | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the re-export necessary now?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not have requisite experience or knowledge to answer this question There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm currently taking the baton here for making this work on 0.15 (and 0.16 to release soon). This does not need to be re-exported. While pub const nc = @cImport({
@cInclude("notcurses/notcurses.h");
});Then using the lib is just a matter of: const nc = @import("notcurses.zig").nc;When 0.16 or 0.17 rolls around (depending on the issue status), |
||
| pub const notcurses = c.notcurses; | ||
| pub const ncplane = c.ncplane; | ||
| pub const notcurses_options = c.notcurses_options; | ||
| pub const ncplane_options = c.ncplane_options; | ||
| pub const ncselector_options = c.ncselector_options; | ||
|
|
||
| // Re-export functions | ||
| pub const notcurses_core_init = c.notcurses_core_init; | ||
| pub const notcurses_stop = c.notcurses_stop; | ||
| pub const notcurses_stddim_yx = c.notcurses_stddim_yx; | ||
| pub const notcurses_render = c.notcurses_render; | ||
| pub const notcurses_get_nblock = c.notcurses_get_nblock; | ||
|
|
||
| pub const ncplane_create = c.ncplane_create; | ||
| pub const ncplane_set_base = c.ncplane_set_base; | ||
| pub const ncplane_erase = c.ncplane_erase; | ||
| pub const ncplane_move_yx = c.ncplane_move_yx; | ||
| pub const ncplane_resize_simple = c.ncplane_resize_simple; | ||
| pub const ncplane_gradient2x1 = c.ncplane_gradient2x1; | ||
| pub const ncplane_rounded_box = c.ncplane_rounded_box; | ||
| pub const ncplane_cursor_move_yx = c.ncplane_cursor_move_yx; | ||
| pub const ncplane_putstr_yx = c.ncplane_putstr_yx; | ||
| pub const ncplane_dim_y = c.ncplane_dim_y; | ||
| pub const ncplane_dim_x = c.ncplane_dim_x; | ||
| pub const ncplane_x = c.ncplane_x; | ||
| pub const ncplane_y = c.ncplane_y; | ||
|
|
||
| pub const ncchannels_set_bg_rgb = c.ncchannels_set_bg_rgb; | ||
| pub const ncchannels_set_bg_alpha = c.ncchannels_set_bg_alpha; | ||
| pub const ncchannels_set_fg_rgb = c.ncchannels_set_fg_rgb; | ||
| pub const ncchannels_set_bchannel = c.ncchannels_set_bchannel; | ||
| pub const ncchannels_set_fchannel = c.ncchannels_set_fchannel; | ||
|
|
||
| pub const ncchannel_r = c.ncchannel_r; | ||
| pub const ncchannel_g = c.ncchannel_g; | ||
| pub const ncchannel_b = c.ncchannel_b; | ||
| pub const ncchannel_set_rgb8_clipped = c.ncchannel_set_rgb8_clipped; | ||
|
|
||
| // Re-export constants | ||
| pub const NCLOGLEVEL_SILENT = c.NCLOGLEVEL_SILENT; | ||
| pub const NCALPHA_BLEND = c.NCALPHA_BLEND; | ||
| pub const NC_BGDEFAULT_MASK = c.NC_BGDEFAULT_MASK; | ||
| pub const default_notcurses_options = c.notcurses_options{ | ||
| .termtype = null, | ||
| .loglevel = c.NCLOGLEVEL_SILENT, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't exactly true, if we're required to have an externally built static lib then sure, but since we are compiling the code into a zig module this is not necessary.