Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
strategy:
fail-fast: false
matrix:
zig-version: ["master", "0.13.0"]
zig-version: ["master", "0.14.0"]
os: [ubuntu-latest, macos-latest, windows-latest]
optimize: [ReleaseSafe, ReleaseFast]
build-options: ["-Dlto"]
Expand All @@ -45,7 +45,7 @@ jobs:
strategy:
fail-fast: false
matrix:
zig-version: ["master", "0.13.0"]
zig-version: ["master", "0.14.0"]
os: [ubuntu-latest]

runs-on: ${{ matrix.os }}
Expand All @@ -71,7 +71,7 @@ jobs:
strategy:
fail-fast: false
matrix:
zig-version: ["master", "0.13.0"]
zig-version: ["master", "0.14.0"]
os: [ubuntu-latest, macos-latest, windows-latest]

runs-on: ${{ matrix.os }}
Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@ First, update your `build.zig.zon`:
# Initialize a `zig build` project if you haven't already
zig init
# Support for `lmdb` starts with v0.9.31 and future releases
zig fetch --save https://github.com/allyourcodebase/lmdb/archive/refs/tags/0.9.31+1.tar.gz
# For latest main commit
zig fetch --save https://github.com/allyourcodebase/lmdb/archive/refs/tags/0.9.31+2.tar.gz
# For latest git commit
zig fetch --save https://github.com/allyourcodebase/lmdb/archive/refs/heads/main.tar.gz
```

Import `lmdb` dependency into build `build.zig` as follows:
Import `lmdb` dependency into `build.zig` as follows:

```zig
const lmdb_dep = b.dependency("lmdb", .{
.target = target,
.optimize = optimize,
.strip = true,
.lto = true,
.linkage = .static,
});
```

Expand All @@ -43,5 +45,5 @@ Using `lmdb` artifacts and module in your project
```

## Supported on Linux, macOS and Windows
- Zig 0.14.0-dev
- Zig 0.13.0
- Zig 0.15.0-dev
- Zig 0.14.0
117 changes: 56 additions & 61 deletions build.zig
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
const std = @import("std");
const builtin = @import("builtin");
const mem = std.mem;
const Build = std.Build;
const Step = Build.Step;
const Compile = Step.Compile;
const builtin = @import("builtin");

const MakeOptions = if (@hasDecl(Step, "MakeOptions"))
Step.MakeOptions
else
std.Progress.Node;
const LinkMode = std.builtin.LinkMode;
const OptimizeMode = std.builtin.OptimizeMode;

const lmdb_root = "libraries/liblmdb";

Expand All @@ -25,6 +22,7 @@ pub fn build(b: *Build) void {
const optimize = b.standardOptimizeOption(.{});

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 lmdb_upstream = b.dependency(
Expand All @@ -33,11 +31,12 @@ pub fn build(b: *Build) void {
);

const build_opt: BuildOpt = .{
.lmdb_upstream = lmdb_upstream,
.lto_option = lto,
.strip_option = strip,
.upstream = lmdb_upstream,
.lto = lto,
.strip = strip,
.target = target,
.optimize = optimize,
.linkage = linkage,
};
const lmdb: BuildLmdb = .{
.b = b,
Expand All @@ -57,17 +56,20 @@ const BuildLmdb = struct {
fn lib(bl: BuildLmdb) *Compile {
const opt = bl.opt;
const b = bl.b;
const liblmdb = b.addStaticLibrary(.{
const liblmdb = b.addLibrary(.{
.name = "lmdb",
.target = opt.target,
.optimize = opt.optimize,
.link_libc = true,
.strip = opt.strip_option,
.linkage = opt.linkage,
.root_module = b.createModule(.{
.target = opt.target,
.optimize = opt.optimize,
.link_libc = true,
.strip = opt.strip,
.sanitize_c = false,
}),
.use_llvm = opt.use_llvm(),
.use_lld = opt.use_lld(),
});
liblmdb.want_lto = opt.use_lto();
liblmdb.root_module.sanitize_c = false;

const lmdb_includes = .{
"lmdb.h",
Expand All @@ -79,18 +81,18 @@ const BuildLmdb = struct {
};

liblmdb.addCSourceFiles(.{
.root = opt.lmdb_upstream.path(lmdb_root),
.root = opt.upstream.path(lmdb_root),
.files = &liblmdb_src,
.flags = &cflags,
});
liblmdb.addIncludePath(opt.lmdb_upstream.path(lmdb_root));
liblmdb.addIncludePath(opt.upstream.path(lmdb_root));
liblmdb.root_module.addCMacro("_XOPEN_SOURCE", "600");
if (opt.isMacos()) {
liblmdb.root_module.addCMacro("_DARWIN_C_SOURCE", "");
}

liblmdb.installHeadersDirectory(
opt.lmdb_upstream.path(lmdb_root),
opt.upstream.path(lmdb_root),
"",
.{ .include_extensions = &lmdb_includes },
);
Expand All @@ -108,13 +110,7 @@ const BuildLmdb = struct {
.optimize = .Debug,
});

if (@hasDecl(Step.TranslateC, "addIncludeDir")) {
const path = opt.lmdb_upstream.path(lmdb_root);
const absolute_include = path.getPath2(b, null);
lmdb_api.addIncludeDir(absolute_include);
} else {
lmdb_api.addIncludePath(opt.lmdb_upstream.path(lmdb_root));
}
lmdb_api.addIncludePath(opt.upstream.path(lmdb_root));

_ = b.addModule("lmdb", .{
.root_source_file = lmdb_api.getOutput(),
Expand All @@ -135,21 +131,23 @@ const BuildLmdb = struct {
const bin_name = tool_file[0..mem.indexOfScalar(u8, tool_file, '.').?];
const tool = b_.addExecutable(.{
.name = bin_name,
.target = opt_.target,
.optimize = opt_.optimize,
.link_libc = true,
.strip = opt_.strip_option,
.root_module = b_.createModule(.{
.target = opt_.target,
.optimize = opt_.optimize,
.link_libc = true,
.strip = opt_.strip,
.sanitize_c = false,
}),
.use_llvm = opt_.use_llvm(),
.use_lld = opt_.use_lld(),
});
tool.root_module.sanitize_c = false;

tool.addCSourceFiles(.{
.root = opt_.lmdb_upstream.path(lmdb_root),
.root = opt_.upstream.path(lmdb_root),
.files = &.{tool_file},
.flags = &cflags,
});
tool.addIncludePath(opt_.lmdb_upstream.path(lmdb_root));
tool.addIncludePath(opt_.upstream.path(lmdb_root));
tool.root_module.addCMacro("_XOPEN_SOURCE", "600");
if (opt_.isMacos()) {
tool.root_module.addCMacro("_DARWIN_C_SOURCE", "");
Expand Down Expand Up @@ -186,7 +184,7 @@ const BuildLmdb = struct {

const install_test_subpath = "test/";
install_test_step.makeFn = struct {
fn makeFn(step: *Step, options: MakeOptions) !void {
fn makeFn(step: *Step, options: Step.MakeOptions) !void {
_ = options;
const step_build = step.owner;
std.fs.cwd().makeDir(step_build.fmt(
Expand All @@ -200,22 +198,12 @@ const BuildLmdb = struct {
}.makeFn;

const create_testdb = struct {
fn makeFn(step: *Step, options: MakeOptions) !void {
fn makeFn(step: *Step, options: Step.MakeOptions) !void {
_ = options;
const test_run = Step.cast(step, Step.Run).?;
const subpath = "testdb/";
if (@hasDecl(Build.LazyPath, "getPath3")) {
const bin_path = test_run.cwd.?.getPath3(step.owner, step);
bin_path.makePath(subpath) catch unreachable;
} else {
const bin_path = test_run.cwd.?.getPath2(step.owner, step);
const owner = test_run.step.owner;
const full_path = owner.fmt("{s}/{s}", .{ bin_path, subpath });
owner.cache_root.handle.makeDir(full_path) catch |err| switch (err) {
error.PathAlreadyExists => {},
else => unreachable,
};
}
const bin_path = test_run.cwd.?.getPath3(step.owner, step);
bin_path.makePath(subpath) catch unreachable;
}

fn create_testdb(owner: *Build, test_dirname: Build.LazyPath) *Step {
Expand Down Expand Up @@ -250,26 +238,32 @@ const BuildLmdb = struct {

const test_exe = b.addExecutable(.{
.name = test_name,
.target = opt.target,
.optimize = .Debug,
.link_libc = true,
.root_module = b.createModule(.{
.target = opt.target,
.optimize = .Debug,
.link_libc = true,
.sanitize_c = false,
}),
.use_lld = opt.use_lld(),
});
test_exe.root_module.sanitize_c = false;

test_exe.addCSourceFiles(.{
.root = opt.lmdb_upstream.path(lmdb_root),
.root = opt.upstream.path(lmdb_root),
.files = &.{test_file},
.flags = &cflags_test,
});
test_exe.addIncludePath(opt.lmdb_upstream.path(lmdb_root));
test_exe.addIncludePath(opt.upstream.path(lmdb_root));
test_exe.linkLibrary(liblmdb);

const test_dirname = test_exe.getEmittedBin().dirname();

const install_test_exe = b.addInstallArtifact(test_exe, .{ .dest_dir = .{ .override = .{
.custom = install_test_subpath,
} } });
const install_test_exe = b.addInstallArtifact(test_exe, .{
.dest_dir = .{
.override = .{
.custom = install_test_subpath,
},
},
});

const run = b.addRunArtifact(test_exe);
run.setCwd(test_dirname);
Expand All @@ -287,11 +281,12 @@ const BuildLmdb = struct {
};

const BuildOpt = struct {
lmdb_upstream: *Build.Dependency,
upstream: *Build.Dependency,
target: Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
strip_option: bool,
lto_option: bool,
optimize: OptimizeMode,
strip: bool,
lto: bool,
linkage: LinkMode,

fn isOs(os: std.Target.Os.Tag, target: Build.ResolvedTarget) bool {
return builtin.os.tag == os or target.result.os.tag == os;
Expand All @@ -306,7 +301,7 @@ const BuildOpt = struct {
}

fn use_lto(opt: BuildOpt) bool {
return if (opt.isMacos()) false else if (opt.use_lld()) opt.lto_option else false;
return if (opt.isMacos()) false else if (opt.use_lld()) opt.lto else false;
}

fn use_llvm(opt: BuildOpt) bool {
Expand All @@ -332,7 +327,7 @@ fn checkVersion() bool {
return false;
}

const needed_version = std.SemanticVersion{ .major = 0, .minor = 13, .patch = 0 };
const needed_version = std.SemanticVersion{ .major = 0, .minor = 14, .patch = 0 };
const version = builtin.zig_version;
const order = version.order(needed_version);
return order != .lt;
Expand Down
11 changes: 6 additions & 5 deletions build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
.{
.name = "lmdb",
.version = "0.9.31",
.minimum_zig_version = "0.13.0",
.name = .lmdb,
.version = "0.9.31+2",
.minimum_zig_version = "0.14.0",
.fingerprint = 0xb2966103474360ca,
.dependencies = .{
.lmdb = .{
.url = "https://github.com/LMDB/lmdb/archive/9c9d34558cc438f99aebd1ab58f83fd7faeabc0a.tar.gz",
.hash = "12205c0f7d4ad44b671cf89a7793aafa31ba4739f01b706313e4eadc944b734bd224",
.url = "https://github.com/LMDB/lmdb/archive/f20e41de09d97e4461946b7e26ec831d0c24fac7.tar.gz",
.hash = "N-V-__8AAC7gCADLpFI1WXLj3t-bdozmit34FAIaqT2ijeAi",
.lazy = false,
},
},
Expand Down