diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 604a5a8..03d09c0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,10 +18,10 @@ jobs: strategy: fail-fast: false matrix: - zig-version: ["master", "0.15.1"] + zig-version: ["master", "0.16.0"] os: [ubuntu-latest, macos-latest, windows-latest] optimize: [ReleaseSafe, ReleaseFast] - build-options: ["-Dlto"] + build-options: ["-Dlto=full"] runs-on: ${{ matrix.os }} @@ -44,7 +44,7 @@ jobs: strategy: fail-fast: false matrix: - zig-version: ["master", "0.15.1"] + zig-version: ["master", "0.16.0"] os: [ubuntu-latest] runs-on: ${{ matrix.os }} @@ -69,7 +69,7 @@ jobs: strategy: fail-fast: false matrix: - zig-version: ["master", "0.15.1"] + zig-version: ["master", "0.16.0"] os: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.os }} diff --git a/.gitignore b/.gitignore index 3389c86..03cb27d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .zig-cache/ zig-out/ +zig-pkg/ diff --git a/README.md b/README.md index c275154..6265ba3 100644 --- a/README.md +++ b/README.md @@ -28,22 +28,25 @@ Import `lmdb` dependency into `build.zig` as follows: Using `lmdb` artifacts and module in your project ```zig + const module = b.createModule(.{ + .root_source_file = b.path("src/main.zig"), + }); const exe = b.addExecutable(.{ .name = exe_name, - .root_source_file = b.path("src/main.zig"), + .root_module = module, .target = target, .optimize = optimize, .strip = strip, }); - exe.want_lto = lto; + exe.lto = lto; const liblmdb = lmdb_dep.artifact("lmdb"); - const lmdb_module = lmdb_dep.module("lmdb"); + const lmdb = lmdb_dep.module("lmdb"); - exe.root_module.addImport("mdb", lmdb_module); - exe.linkLibrary(liblmdb); + module.addImport("mdb", lmdb); + module.linkLibrary(liblmdb); ``` ## Supported on Linux, macOS and Windows -- Zig 0.16.0-dev -- Zig 0.15.1 +- Zig 0.17.0-dev +- Zig 0.16.0 diff --git a/build.zig b/build.zig index bb9a28e..bacc7dd 100644 --- a/build.zig +++ b/build.zig @@ -9,7 +9,7 @@ const OptimizeMode = std.builtin.OptimizeMode; const lmdb_root = "libraries/liblmdb"; -const cflags = .{ +const cflags: []const []const u8 = &.{ "-pthread", "-std=c23", }; @@ -25,7 +25,7 @@ pub fn build(b: *Build) void { const strip = b.option(bool, "strip", "Strip debug information") orelse false; const linkage = b.option(LinkMode, "linkage", "Link mode for Lmdb") orelse .static; - const lto = b.option(bool, "lto", "Enable link time optimization") orelse false; + const lto = b.option(std.zig.LtoMode, "lto", "Enable link time optimization") orelse .none; const lmdb_upstream = b.dependency( "lmdb", @@ -58,46 +58,46 @@ const BuildLmdb = struct { fn lib(bl: BuildLmdb) *Compile { const opt = bl.opt; const b = bl.b; - const liblmdb = b.addLibrary(.{ - .name = "lmdb", - .linkage = opt.linkage, - .root_module = b.createModule(.{ - .target = opt.target, - .optimize = opt.optimize, - .link_libc = true, - .strip = opt.strip, - .sanitize_c = sanitize_c, - }), - .use_llvm = opt.use_llvm(), - .use_lld = opt.use_lld(), - }); - liblmdb.want_lto = opt.use_lto(); - - const lmdb_includes = .{ + const lmdb_includes: []const []const u8 = &.{ "lmdb.h", "midl.h", }; - const liblmdb_src = .{ + const liblmdb_src: []const []const u8 = &.{ "mdb.c", "midl.c", }; - - liblmdb.addCSourceFiles(.{ + const module = b.createModule(.{ + .target = opt.target, + .optimize = opt.optimize, + .link_libc = true, + .strip = opt.strip, + .sanitize_c = sanitize_c, + }); + module.addCSourceFiles(.{ .root = opt.upstream.path(lmdb_root), - .files = &liblmdb_src, - .flags = &cflags, + .files = liblmdb_src, + .flags = cflags, }); - liblmdb.addIncludePath(opt.upstream.path(lmdb_root)); - liblmdb.root_module.addCMacro("_XOPEN_SOURCE", "600"); + module.addIncludePath(opt.upstream.path(lmdb_root)); + module.addCMacro("_XOPEN_SOURCE", "800"); if (opt.isMacos()) { - liblmdb.root_module.addCMacro("_DARWIN_C_SOURCE", ""); + module.addCMacro("_DARWIN_C_SOURCE", ""); } + const liblmdb = b.addLibrary(.{ + .name = "lmdb", + .linkage = opt.linkage, + .root_module = module, + .use_llvm = opt.use_llvm(), + .use_lld = opt.use_lld(), + }); + liblmdb.lto = opt.use_lto(); liblmdb.installHeadersDirectory( opt.upstream.path(lmdb_root), "", - .{ .include_extensions = &lmdb_includes }, + .{ .include_extensions = lmdb_includes }, ); + b.installArtifact(liblmdb); return liblmdb; @@ -130,32 +130,33 @@ const BuildLmdb = struct { const b_ = bl_.b; const opt_ = bl_.opt; for (lmdb_tools) |tool_file| { - const bin_name = tool_file[0..mem.indexOfScalar(u8, tool_file, '.').?]; + const bin_name = tool_file[0..mem.findScalar(u8, tool_file, '.').?]; + const module = b_.createModule(.{ + .target = opt_.target, + .optimize = opt_.optimize, + .link_libc = true, + .strip = opt_.strip, + .sanitize_c = sanitize_c, + }); + module.addIncludePath(opt_.upstream.path(lmdb_root)); + module.addCMacro("_XOPEN_SOURCE", "800"); + if (opt_.isMacos()) { + module.addCMacro("_DARWIN_C_SOURCE", ""); + } + module.linkLibrary(liblmdb_); + module.addCSourceFiles(.{ + .root = opt_.upstream.path(lmdb_root), + .files = &.{tool_file}, + .flags = cflags, + }); + const tool = b_.addExecutable(.{ .name = bin_name, - .root_module = b_.createModule(.{ - .target = opt_.target, - .optimize = opt_.optimize, - .link_libc = true, - .strip = opt_.strip, - .sanitize_c = sanitize_c, - }), + .root_module = module, .use_llvm = opt_.use_llvm(), .use_lld = opt_.use_lld(), }); - tool.addCSourceFiles(.{ - .root = opt_.upstream.path(lmdb_root), - .files = &.{tool_file}, - .flags = &cflags, - }); - tool.addIncludePath(opt_.upstream.path(lmdb_root)); - tool.root_module.addCMacro("_XOPEN_SOURCE", "600"); - if (opt_.isMacos()) { - tool.root_module.addCMacro("_DARWIN_C_SOURCE", ""); - } - tool.linkLibrary(liblmdb_); - const install_tool = b_.addInstallArtifact(tool, .{}); tools_step_.dependOn(&install_tool.step); } @@ -189,7 +190,7 @@ const BuildLmdb = struct { fn makeFn(step: *Step, options: Step.MakeOptions) !void { _ = options; const step_build = step.owner; - std.fs.cwd().makeDir(step_build.fmt( + std.Io.Dir.cwd().createDirPath(step_build.graph.io, step_build.fmt( "{s}/{s}/testdb/", .{ step_build.install_prefix, install_test_subpath }, )) catch |err| switch (err) { @@ -203,9 +204,10 @@ const BuildLmdb = struct { fn makeFn(step: *Step, options: Step.MakeOptions) !void { _ = options; const test_run = Step.cast(step, Step.Run).?; + const step_build = test_run.step.owner; const subpath = "testdb/"; const bin_path = test_run.cwd.?.getPath3(step.owner, step); - bin_path.makePath(subpath) catch unreachable; + bin_path.createDirPath(step_build.graph.io, subpath) catch unreachable; } fn create_testdb(owner: *Build, test_dirname: Build.LazyPath) *Step { @@ -236,26 +238,27 @@ const BuildLmdb = struct { }; for (lmdb_test) |test_file| { - const test_name = test_file[0..mem.indexOfScalar(u8, test_file, '.').?]; + const test_name = test_file[0..mem.findScalar(u8, test_file, '.').?]; - const test_exe = b.addExecutable(.{ - .name = test_name, - .root_module = b.createModule(.{ - .target = opt.target, - .optimize = .Debug, - .link_libc = true, - .sanitize_c = sanitize_c, - }), - .use_lld = opt.use_lld(), + const module = b.createModule(.{ + .target = opt.target, + .optimize = .Debug, + .link_libc = true, + .sanitize_c = sanitize_c, }); - - test_exe.addCSourceFiles(.{ + module.addCSourceFiles(.{ .root = opt.upstream.path(lmdb_root), .files = &.{test_file}, .flags = &cflags_test, }); - test_exe.addIncludePath(opt.upstream.path(lmdb_root)); - test_exe.linkLibrary(liblmdb); + module.addIncludePath(opt.upstream.path(lmdb_root)); + module.linkLibrary(liblmdb); + + const test_exe = b.addExecutable(.{ + .name = test_name, + .root_module = module, + .use_lld = opt.use_lld(), + }); const test_dirname = test_exe.getEmittedBin().dirname(); @@ -270,7 +273,6 @@ const BuildLmdb = struct { const run = b.addRunArtifact(test_exe); run.setCwd(test_dirname); run.expectExitCode(0); - run.enableTestRunnerMode(); const run_create_testdb = create_testdb(run.step.owner, test_dirname); run_create_testdb.dependOn(&test_exe.step); @@ -287,7 +289,7 @@ const BuildOpt = struct { target: Build.ResolvedTarget, optimize: OptimizeMode, strip: bool, - lto: bool, + lto: std.zig.LtoMode, linkage: LinkMode, fn isOs(os: std.Target.Os.Tag, target: Build.ResolvedTarget) bool { @@ -302,8 +304,13 @@ const BuildOpt = struct { return isOs(.windows, opt.target); } - fn use_lto(opt: BuildOpt) bool { - return if (opt.isMacos()) false else if (opt.use_lld()) opt.lto else false; + fn use_lto(opt: BuildOpt) std.zig.LtoMode { + return if (opt.isMacos()) + .none + else if (opt.use_lld()) + opt.lto + else + .none; } fn use_llvm(opt: BuildOpt) bool { diff --git a/build.zig.zon b/build.zig.zon index e7d6983..fbbe6bf 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,12 +1,12 @@ .{ .name = .lmdb, - .version = "0.9.31+3", - .minimum_zig_version = "0.15.1", + .version = "0.9.35", + .minimum_zig_version = "0.16.0", .fingerprint = 0xb2966103474360ca, .dependencies = .{ .lmdb = .{ - .url = "https://github.com/LMDB/lmdb/archive/14d6629bc8a9fe40d8a6bee1bf71c45afe7576b6.tar.gz", - .hash = "N-V-__8AABzgCAC6yX-gYcngpmRFF74ZANIAhphOalO6yoyI", + .url = "https://github.com/LMDB/lmdb/archive/40d3741b7d40ba4c75cb91dd9987ce692d376d71.tar.gz", + .hash = "N-V-__8AAJnhCAB47uREmMoPc3nE2qhAxU_JOiwXhg4qIWa4", .lazy = false, }, },