Skip to content
Open
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
zig-cache/
deps.zig
zig-out/
deps.zig
.zigmod/
zigmod.lock
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "lmdb"]
path = lmdb
url = https://github.com/LMDB/lmdb
22 changes: 10 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Refer to the 12 extensive unit tests provided [here](lmdb.zig#L874) for usage in

Built and tested against Zig's master branch over all possible optimization modes.

For Zig 0.11, see the branch `0.11`.

## Motivation

Expand All @@ -24,19 +25,16 @@ As a result, extensive effort was put into exposing and testing as many differen

## Setup

These bindings were built with first-class support for the [zigmod](https://github.com/nektro/zigmod) package manager.
1. Add this repo as git submodule
2. Add the following code to your `build.zig`

To incorporate these bindings into your project, include the following into your project's `zig.mod`:

```yml
- type: git
path: https://github.com/lithdew/lmdb-zig
```

Afterwards, run:

```shell
zigmod fetch
```zig
pub fn build(b: *std.Build) void {
...
const dep_lmdb = b.anonymousDependency("lib/lmdb-zig", @import("lib/lmdb-zig/build.zig"), .{});
exe.linkLibrary(dep_lmdb.artifact("lmdb"));
exe.addModule("lmdb", dep_lmdb.module("lmdb"));
}
```

## Status
Expand Down
37 changes: 27 additions & 10 deletions build.zig
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
const std = @import("std");
const deps = @import("deps.zig");

const Builder = std.build.Builder;

pub fn build(b: *Builder) void {
pub fn build(b: *std.Build) void {
var target = b.standardTargetOptions(.{});
if (target.isGnuLibC()) target.abi = .musl;

const mode = b.standardReleaseOptions();
const optimize = b.standardOptimizeOption(.{});

const lib = b.addStaticLibrary(.{
.name = "lmdb",
.target = target,
.optimize = optimize,
});
lib.linkLibC();
lib.addCSourceFiles(.{ .files = &.{ "lmdb/libraries/liblmdb/mdb.c", "lmdb/libraries/liblmdb/midl.c" }, .flags = &.{"-fno-sanitize=undefined"} });

b.installArtifact(lib);

const pkg = b.addModule("lmdb", .{
.source_file = .{ .path = "lmdb.zig" },
});

const tests = b.addTest(.{
.name = "test",
.root_source_file = pkg.source_file,
.target = target,
.optimize = optimize,
});
tests.addIncludePath(.{ .path = "lmdb/libraries/liblmdb" });
tests.linkLibrary(lib);

const tests = b.addTest("lmdb.zig");
tests.setTarget(target);
tests.setBuildMode(mode);
deps.addAllTo(tests);
b.installArtifact(tests);

const test_step = b.step("test", "Run libary tests");
test_step.dependOn(&tests.step);
test_step.dependOn(&b.addRunArtifact(tests).step);
}
1 change: 1 addition & 0 deletions lmdb
Submodule lmdb added at 30288c
Loading