From dee18277f72df1943479a06a5fddb3bbf7932494 Mon Sep 17 00:00:00 2001 From: "Jeffrey C. Ollie" Date: Sun, 1 Mar 2026 14:35:41 -0600 Subject: [PATCH] updates and build docs --- build.zig | 17 ++++++++++++++++- src/Database.zig | 40 +++++++++++++++++++++------------------- 2 files changed, 37 insertions(+), 20 deletions(-) diff --git a/build.zig b/build.zig index 7481891..6db6a18 100644 --- a/build.zig +++ b/build.zig @@ -13,7 +13,8 @@ pub fn build(b: *std.Build) void { .target = target, .optimize = optimize, }); - if (b.graph.environ_map.get("NOTMUCH_INCLUDE")) |path| notmuch_c.addIncludePath(.{ .cwd_relative = path }); + if (b.graph.environ_map.get("NOTMUCH_INCLUDE")) |path| + notmuch_c.addIncludePath(.{ .cwd_relative = path }); const notmuch_zig = b.addModule("notmuch", .{ .root_source_file = b.path("src/notmuch.zig"), @@ -32,4 +33,18 @@ pub fn build(b: *std.Build) void { const test_step = b.step("test", "Run unit tests"); test_step.dependOn(&run_tests.step); + + const notmuch_lib = b.addLibrary(.{ + .name = "notmuch", + .root_module = notmuch_zig, + }); + + const install_docs = b.addInstallDirectory(.{ + .source_dir = notmuch_lib.getEmittedDocs(), + .install_dir = .prefix, + .install_subdir = "docs", + }); + + const docs_step = b.step("docs", "Build the API docs"); + docs_step.dependOn(&install_docs.step); } diff --git a/src/Database.zig b/src/Database.zig index 564ca19..092e1b3 100644 --- a/src/Database.zig +++ b/src/Database.zig @@ -12,34 +12,35 @@ const Error = @import("error.zig").Error; const wrap = @import("error.zig").wrap; const wrapMessage = @import("error.zig").wrapMessage; -const CONFIG = @import("enums.zig").CONFIG; -const DATABASE_MODE = @import("enums.zig").DATABASE_MODE; -const DECRYPT = @import("enums.zig").DECRYPT; -const QUERY_SYNTAX = @import("enums.zig").QUERY_SYNTAX; +const enums = @import("enums.zig"); +const CONFIG = enums.CONFIG; +const DATABASE_MODE = enums.DATABASE_MODE; +const DECRYPT = enums.DECRYPT; +const QUERY_SYNTAX = enums.QUERY_SYNTAX; const Message = @import("Message.zig"); const Query = @import("Query.zig"); database: *c.notmuch_database_t, -pub fn open( - database_path: ?[*:0]const u8, - mode: DATABASE_MODE, +pub const OpenOptions = struct { config_path: ?[:0]const u8, + database_path: ?[*:0]const u8, profile: ?[:0]const u8, -) Error!Database { +}; + +pub fn open(mode: DATABASE_MODE, options: OpenOptions) Error!Database { if (!c.LIBNOTMUCH_CHECK_VERSION(5, 6, 0)) { - log.err("need newer notmuch", .{}); return error.NotmuchVersion; } var error_message: [*c]u8 = null; var database: ?*c.notmuch_database_t = null; try wrapMessage(c.notmuch_database_open_with_config( - database_path orelse null, + options.database_path orelse null, @intFromEnum(mode), - config_path orelse null, - profile orelse null, + options.config_path orelse null, + options.profile orelse null, &database, &error_message, ), error_message); @@ -48,13 +49,14 @@ pub fn open( }; } -pub fn create( - database_path: ?[*:0]const u8, +pub const CreateOptions = struct { config_path: ?[:0]const u8, + database_path: ?[*:0]const u8, profile: ?[:0]const u8, -) Error!Database { +}; + +pub fn create(options: CreateOptions) Error!Database { if (!c.LIBNOTMUCH_CHECK_VERSION(5, 6, 0)) { - log.err("need newer notmuch", .{}); return error.NotmuchVersion; } @@ -62,9 +64,9 @@ pub fn create( var database: ?*c.notmuch_database_t = null; try wrapMessage( c.notmuch_database_create_with_config( - database_path orelse null, - config_path orelse null, - profile orelse null, + options.database_path orelse null, + options.config_path orelse null, + options.profile orelse null, &database, &error_message, ), -- 2.51.2