Skip to content

Commit 35b06e9

Browse files
authored
Merge pull request #9 from allyourcodebase/fix-0.14.0
Fixes for Zig 0.14.0 stable release
2 parents 974d4f9 + 4e279d6 commit 35b06e9

File tree

4 files changed

+72
-74
lines changed

4 files changed

+72
-74
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
strategy:
1919
fail-fast: false
2020
matrix:
21-
zig-version: ["master", "0.13.0"]
21+
zig-version: ["master", "0.14.0"]
2222
os: [ubuntu-latest, macos-latest, windows-latest]
2323
optimize: [ReleaseSafe, ReleaseFast]
2424
build-options: ["-Dlto"]
@@ -45,7 +45,7 @@ jobs:
4545
strategy:
4646
fail-fast: false
4747
matrix:
48-
zig-version: ["master", "0.13.0"]
48+
zig-version: ["master", "0.14.0"]
4949
os: [ubuntu-latest]
5050

5151
runs-on: ${{ matrix.os }}
@@ -71,7 +71,7 @@ jobs:
7171
strategy:
7272
fail-fast: false
7373
matrix:
74-
zig-version: ["master", "0.13.0"]
74+
zig-version: ["master", "0.14.0"]
7575
os: [ubuntu-latest, macos-latest, windows-latest]
7676

7777
runs-on: ${{ matrix.os }}

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,20 @@ First, update your `build.zig.zon`:
99
# Initialize a `zig build` project if you haven't already
1010
zig init
1111
# Support for `lmdb` starts with v0.9.31 and future releases
12-
zig fetch --save https://github.com/allyourcodebase/lmdb/archive/refs/tags/0.9.31+1.tar.gz
13-
# For latest main commit
12+
zig fetch --save https://github.com/allyourcodebase/lmdb/archive/refs/tags/0.9.31+2.tar.gz
13+
# For latest git commit
1414
zig fetch --save https://github.com/allyourcodebase/lmdb/archive/refs/heads/main.tar.gz
1515
```
1616

17-
Import `lmdb` dependency into build `build.zig` as follows:
17+
Import `lmdb` dependency into `build.zig` as follows:
1818

1919
```zig
2020
const lmdb_dep = b.dependency("lmdb", .{
2121
.target = target,
2222
.optimize = optimize,
23+
.strip = true,
2324
.lto = true,
25+
.linkage = .static,
2426
});
2527
```
2628

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

4547
## Supported on Linux, macOS and Windows
46-
- Zig 0.14.0-dev
47-
- Zig 0.13.0
48+
- Zig 0.15.0-dev
49+
- Zig 0.14.0

build.zig

Lines changed: 56 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
const std = @import("std");
2+
const builtin = @import("builtin");
23
const mem = std.mem;
34
const Build = std.Build;
45
const Step = Build.Step;
56
const Compile = Step.Compile;
6-
const builtin = @import("builtin");
7-
8-
const MakeOptions = if (@hasDecl(Step, "MakeOptions"))
9-
Step.MakeOptions
10-
else
11-
std.Progress.Node;
7+
const LinkMode = std.builtin.LinkMode;
8+
const OptimizeMode = std.builtin.OptimizeMode;
129

1310
const lmdb_root = "libraries/liblmdb";
1411

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

2724
const strip = b.option(bool, "strip", "Strip debug information") orelse false;
25+
const linkage = b.option(LinkMode, "linkage", "Link mode for Lmdb") orelse .static;
2826
const lto = b.option(bool, "lto", "Enable link time optimization") orelse false;
2927

3028
const lmdb_upstream = b.dependency(
@@ -33,11 +31,12 @@ pub fn build(b: *Build) void {
3331
);
3432

3533
const build_opt: BuildOpt = .{
36-
.lmdb_upstream = lmdb_upstream,
37-
.lto_option = lto,
38-
.strip_option = strip,
34+
.upstream = lmdb_upstream,
35+
.lto = lto,
36+
.strip = strip,
3937
.target = target,
4038
.optimize = optimize,
39+
.linkage = linkage,
4140
};
4241
const lmdb: BuildLmdb = .{
4342
.b = b,
@@ -57,17 +56,20 @@ const BuildLmdb = struct {
5756
fn lib(bl: BuildLmdb) *Compile {
5857
const opt = bl.opt;
5958
const b = bl.b;
60-
const liblmdb = b.addStaticLibrary(.{
59+
const liblmdb = b.addLibrary(.{
6160
.name = "lmdb",
62-
.target = opt.target,
63-
.optimize = opt.optimize,
64-
.link_libc = true,
65-
.strip = opt.strip_option,
61+
.linkage = opt.linkage,
62+
.root_module = b.createModule(.{
63+
.target = opt.target,
64+
.optimize = opt.optimize,
65+
.link_libc = true,
66+
.strip = opt.strip,
67+
.sanitize_c = false,
68+
}),
6669
.use_llvm = opt.use_llvm(),
6770
.use_lld = opt.use_lld(),
6871
});
6972
liblmdb.want_lto = opt.use_lto();
70-
liblmdb.root_module.sanitize_c = false;
7173

7274
const lmdb_includes = .{
7375
"lmdb.h",
@@ -79,18 +81,18 @@ const BuildLmdb = struct {
7981
};
8082

8183
liblmdb.addCSourceFiles(.{
82-
.root = opt.lmdb_upstream.path(lmdb_root),
84+
.root = opt.upstream.path(lmdb_root),
8385
.files = &liblmdb_src,
8486
.flags = &cflags,
8587
});
86-
liblmdb.addIncludePath(opt.lmdb_upstream.path(lmdb_root));
88+
liblmdb.addIncludePath(opt.upstream.path(lmdb_root));
8789
liblmdb.root_module.addCMacro("_XOPEN_SOURCE", "600");
8890
if (opt.isMacos()) {
8991
liblmdb.root_module.addCMacro("_DARWIN_C_SOURCE", "");
9092
}
9193

9294
liblmdb.installHeadersDirectory(
93-
opt.lmdb_upstream.path(lmdb_root),
95+
opt.upstream.path(lmdb_root),
9496
"",
9597
.{ .include_extensions = &lmdb_includes },
9698
);
@@ -108,13 +110,7 @@ const BuildLmdb = struct {
108110
.optimize = .Debug,
109111
});
110112

111-
if (@hasDecl(Step.TranslateC, "addIncludeDir")) {
112-
const path = opt.lmdb_upstream.path(lmdb_root);
113-
const absolute_include = path.getPath2(b, null);
114-
lmdb_api.addIncludeDir(absolute_include);
115-
} else {
116-
lmdb_api.addIncludePath(opt.lmdb_upstream.path(lmdb_root));
117-
}
113+
lmdb_api.addIncludePath(opt.upstream.path(lmdb_root));
118114

119115
_ = b.addModule("lmdb", .{
120116
.root_source_file = lmdb_api.getOutput(),
@@ -135,21 +131,23 @@ const BuildLmdb = struct {
135131
const bin_name = tool_file[0..mem.indexOfScalar(u8, tool_file, '.').?];
136132
const tool = b_.addExecutable(.{
137133
.name = bin_name,
138-
.target = opt_.target,
139-
.optimize = opt_.optimize,
140-
.link_libc = true,
141-
.strip = opt_.strip_option,
134+
.root_module = b_.createModule(.{
135+
.target = opt_.target,
136+
.optimize = opt_.optimize,
137+
.link_libc = true,
138+
.strip = opt_.strip,
139+
.sanitize_c = false,
140+
}),
142141
.use_llvm = opt_.use_llvm(),
143142
.use_lld = opt_.use_lld(),
144143
});
145-
tool.root_module.sanitize_c = false;
146144

147145
tool.addCSourceFiles(.{
148-
.root = opt_.lmdb_upstream.path(lmdb_root),
146+
.root = opt_.upstream.path(lmdb_root),
149147
.files = &.{tool_file},
150148
.flags = &cflags,
151149
});
152-
tool.addIncludePath(opt_.lmdb_upstream.path(lmdb_root));
150+
tool.addIncludePath(opt_.upstream.path(lmdb_root));
153151
tool.root_module.addCMacro("_XOPEN_SOURCE", "600");
154152
if (opt_.isMacos()) {
155153
tool.root_module.addCMacro("_DARWIN_C_SOURCE", "");
@@ -186,7 +184,7 @@ const BuildLmdb = struct {
186184

187185
const install_test_subpath = "test/";
188186
install_test_step.makeFn = struct {
189-
fn makeFn(step: *Step, options: MakeOptions) !void {
187+
fn makeFn(step: *Step, options: Step.MakeOptions) !void {
190188
_ = options;
191189
const step_build = step.owner;
192190
std.fs.cwd().makeDir(step_build.fmt(
@@ -200,22 +198,12 @@ const BuildLmdb = struct {
200198
}.makeFn;
201199

202200
const create_testdb = struct {
203-
fn makeFn(step: *Step, options: MakeOptions) !void {
201+
fn makeFn(step: *Step, options: Step.MakeOptions) !void {
204202
_ = options;
205203
const test_run = Step.cast(step, Step.Run).?;
206204
const subpath = "testdb/";
207-
if (@hasDecl(Build.LazyPath, "getPath3")) {
208-
const bin_path = test_run.cwd.?.getPath3(step.owner, step);
209-
bin_path.makePath(subpath) catch unreachable;
210-
} else {
211-
const bin_path = test_run.cwd.?.getPath2(step.owner, step);
212-
const owner = test_run.step.owner;
213-
const full_path = owner.fmt("{s}/{s}", .{ bin_path, subpath });
214-
owner.cache_root.handle.makeDir(full_path) catch |err| switch (err) {
215-
error.PathAlreadyExists => {},
216-
else => unreachable,
217-
};
218-
}
205+
const bin_path = test_run.cwd.?.getPath3(step.owner, step);
206+
bin_path.makePath(subpath) catch unreachable;
219207
}
220208

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

251239
const test_exe = b.addExecutable(.{
252240
.name = test_name,
253-
.target = opt.target,
254-
.optimize = .Debug,
255-
.link_libc = true,
241+
.root_module = b.createModule(.{
242+
.target = opt.target,
243+
.optimize = .Debug,
244+
.link_libc = true,
245+
.sanitize_c = false,
246+
}),
256247
.use_lld = opt.use_lld(),
257248
});
258-
test_exe.root_module.sanitize_c = false;
259249

260250
test_exe.addCSourceFiles(.{
261-
.root = opt.lmdb_upstream.path(lmdb_root),
251+
.root = opt.upstream.path(lmdb_root),
262252
.files = &.{test_file},
263253
.flags = &cflags_test,
264254
});
265-
test_exe.addIncludePath(opt.lmdb_upstream.path(lmdb_root));
255+
test_exe.addIncludePath(opt.upstream.path(lmdb_root));
266256
test_exe.linkLibrary(liblmdb);
267257

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

270-
const install_test_exe = b.addInstallArtifact(test_exe, .{ .dest_dir = .{ .override = .{
271-
.custom = install_test_subpath,
272-
} } });
260+
const install_test_exe = b.addInstallArtifact(test_exe, .{
261+
.dest_dir = .{
262+
.override = .{
263+
.custom = install_test_subpath,
264+
},
265+
},
266+
});
273267

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

289283
const BuildOpt = struct {
290-
lmdb_upstream: *Build.Dependency,
284+
upstream: *Build.Dependency,
291285
target: Build.ResolvedTarget,
292-
optimize: std.builtin.OptimizeMode,
293-
strip_option: bool,
294-
lto_option: bool,
286+
optimize: OptimizeMode,
287+
strip: bool,
288+
lto: bool,
289+
linkage: LinkMode,
295290

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

308303
fn use_lto(opt: BuildOpt) bool {
309-
return if (opt.isMacos()) false else if (opt.use_lld()) opt.lto_option else false;
304+
return if (opt.isMacos()) false else if (opt.use_lld()) opt.lto else false;
310305
}
311306

312307
fn use_llvm(opt: BuildOpt) bool {
@@ -332,7 +327,7 @@ fn checkVersion() bool {
332327
return false;
333328
}
334329

335-
const needed_version = std.SemanticVersion{ .major = 0, .minor = 13, .patch = 0 };
330+
const needed_version = std.SemanticVersion{ .major = 0, .minor = 14, .patch = 0 };
336331
const version = builtin.zig_version;
337332
const order = version.order(needed_version);
338333
return order != .lt;

build.zig.zon

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
.{
2-
.name = "lmdb",
3-
.version = "0.9.31",
4-
.minimum_zig_version = "0.13.0",
2+
.name = .lmdb,
3+
.version = "0.9.31+2",
4+
.minimum_zig_version = "0.14.0",
5+
.fingerprint = 0xb2966103474360ca,
56
.dependencies = .{
67
.lmdb = .{
7-
.url = "https://github.com/LMDB/lmdb/archive/9c9d34558cc438f99aebd1ab58f83fd7faeabc0a.tar.gz",
8-
.hash = "12205c0f7d4ad44b671cf89a7793aafa31ba4739f01b706313e4eadc944b734bd224",
8+
.url = "https://github.com/LMDB/lmdb/archive/f20e41de09d97e4461946b7e26ec831d0c24fac7.tar.gz",
9+
.hash = "N-V-__8AAC7gCADLpFI1WXLj3t-bdozmit34FAIaqT2ijeAi",
910
.lazy = false,
1011
},
1112
},

0 commit comments

Comments
 (0)