1
1
const std = @import ("std" );
2
+ const builtin = @import ("builtin" );
2
3
const mem = std .mem ;
3
4
const Build = std .Build ;
4
5
const Step = Build .Step ;
5
6
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 ;
12
9
13
10
const lmdb_root = "libraries/liblmdb" ;
14
11
@@ -25,6 +22,7 @@ pub fn build(b: *Build) void {
25
22
const optimize = b .standardOptimizeOption (.{});
26
23
27
24
const strip = b .option (bool , "strip" , "Strip debug information" ) orelse false ;
25
+ const linkage = b .option (LinkMode , "linkage" , "Link mode for Lmdb" ) orelse .static ;
28
26
const lto = b .option (bool , "lto" , "Enable link time optimization" ) orelse false ;
29
27
30
28
const lmdb_upstream = b .dependency (
@@ -33,11 +31,12 @@ pub fn build(b: *Build) void {
33
31
);
34
32
35
33
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 ,
39
37
.target = target ,
40
38
.optimize = optimize ,
39
+ .linkage = linkage ,
41
40
};
42
41
const lmdb : BuildLmdb = .{
43
42
.b = b ,
@@ -57,17 +56,20 @@ const BuildLmdb = struct {
57
56
fn lib (bl : BuildLmdb ) * Compile {
58
57
const opt = bl .opt ;
59
58
const b = bl .b ;
60
- const liblmdb = b .addStaticLibrary (.{
59
+ const liblmdb = b .addLibrary (.{
61
60
.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
+ }),
66
69
.use_llvm = opt .use_llvm (),
67
70
.use_lld = opt .use_lld (),
68
71
});
69
72
liblmdb .want_lto = opt .use_lto ();
70
- liblmdb .root_module .sanitize_c = false ;
71
73
72
74
const lmdb_includes = .{
73
75
"lmdb.h" ,
@@ -79,18 +81,18 @@ const BuildLmdb = struct {
79
81
};
80
82
81
83
liblmdb .addCSourceFiles (.{
82
- .root = opt .lmdb_upstream .path (lmdb_root ),
84
+ .root = opt .upstream .path (lmdb_root ),
83
85
.files = & liblmdb_src ,
84
86
.flags = & cflags ,
85
87
});
86
- liblmdb .addIncludePath (opt .lmdb_upstream .path (lmdb_root ));
88
+ liblmdb .addIncludePath (opt .upstream .path (lmdb_root ));
87
89
liblmdb .root_module .addCMacro ("_XOPEN_SOURCE" , "600" );
88
90
if (opt .isMacos ()) {
89
91
liblmdb .root_module .addCMacro ("_DARWIN_C_SOURCE" , "" );
90
92
}
91
93
92
94
liblmdb .installHeadersDirectory (
93
- opt .lmdb_upstream .path (lmdb_root ),
95
+ opt .upstream .path (lmdb_root ),
94
96
"" ,
95
97
.{ .include_extensions = & lmdb_includes },
96
98
);
@@ -108,13 +110,7 @@ const BuildLmdb = struct {
108
110
.optimize = .Debug ,
109
111
});
110
112
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 ));
118
114
119
115
_ = b .addModule ("lmdb" , .{
120
116
.root_source_file = lmdb_api .getOutput (),
@@ -135,21 +131,23 @@ const BuildLmdb = struct {
135
131
const bin_name = tool_file [0.. mem .indexOfScalar (u8 , tool_file , '.' ).? ];
136
132
const tool = b_ .addExecutable (.{
137
133
.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
+ }),
142
141
.use_llvm = opt_ .use_llvm (),
143
142
.use_lld = opt_ .use_lld (),
144
143
});
145
- tool .root_module .sanitize_c = false ;
146
144
147
145
tool .addCSourceFiles (.{
148
- .root = opt_ .lmdb_upstream .path (lmdb_root ),
146
+ .root = opt_ .upstream .path (lmdb_root ),
149
147
.files = &.{tool_file },
150
148
.flags = & cflags ,
151
149
});
152
- tool .addIncludePath (opt_ .lmdb_upstream .path (lmdb_root ));
150
+ tool .addIncludePath (opt_ .upstream .path (lmdb_root ));
153
151
tool .root_module .addCMacro ("_XOPEN_SOURCE" , "600" );
154
152
if (opt_ .isMacos ()) {
155
153
tool .root_module .addCMacro ("_DARWIN_C_SOURCE" , "" );
@@ -186,7 +184,7 @@ const BuildLmdb = struct {
186
184
187
185
const install_test_subpath = "test/" ;
188
186
install_test_step .makeFn = struct {
189
- fn makeFn (step : * Step , options : MakeOptions ) ! void {
187
+ fn makeFn (step : * Step , options : Step. MakeOptions ) ! void {
190
188
_ = options ;
191
189
const step_build = step .owner ;
192
190
std .fs .cwd ().makeDir (step_build .fmt (
@@ -200,22 +198,12 @@ const BuildLmdb = struct {
200
198
}.makeFn ;
201
199
202
200
const create_testdb = struct {
203
- fn makeFn (step : * Step , options : MakeOptions ) ! void {
201
+ fn makeFn (step : * Step , options : Step. MakeOptions ) ! void {
204
202
_ = options ;
205
203
const test_run = Step .cast (step , Step .Run ).? ;
206
204
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 ;
219
207
}
220
208
221
209
fn create_testdb (owner : * Build , test_dirname : Build.LazyPath ) * Step {
@@ -250,26 +238,32 @@ const BuildLmdb = struct {
250
238
251
239
const test_exe = b .addExecutable (.{
252
240
.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
+ }),
256
247
.use_lld = opt .use_lld (),
257
248
});
258
- test_exe .root_module .sanitize_c = false ;
259
249
260
250
test_exe .addCSourceFiles (.{
261
- .root = opt .lmdb_upstream .path (lmdb_root ),
251
+ .root = opt .upstream .path (lmdb_root ),
262
252
.files = &.{test_file },
263
253
.flags = & cflags_test ,
264
254
});
265
- test_exe .addIncludePath (opt .lmdb_upstream .path (lmdb_root ));
255
+ test_exe .addIncludePath (opt .upstream .path (lmdb_root ));
266
256
test_exe .linkLibrary (liblmdb );
267
257
268
258
const test_dirname = test_exe .getEmittedBin ().dirname ();
269
259
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
+ });
273
267
274
268
const run = b .addRunArtifact (test_exe );
275
269
run .setCwd (test_dirname );
@@ -287,11 +281,12 @@ const BuildLmdb = struct {
287
281
};
288
282
289
283
const BuildOpt = struct {
290
- lmdb_upstream : * Build.Dependency ,
284
+ upstream : * Build.Dependency ,
291
285
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 ,
295
290
296
291
fn isOs (os : std.Target.Os.Tag , target : Build.ResolvedTarget ) bool {
297
292
return builtin .os .tag == os or target .result .os .tag == os ;
@@ -306,7 +301,7 @@ const BuildOpt = struct {
306
301
}
307
302
308
303
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 ;
310
305
}
311
306
312
307
fn use_llvm (opt : BuildOpt ) bool {
@@ -332,7 +327,7 @@ fn checkVersion() bool {
332
327
return false ;
333
328
}
334
329
335
- const needed_version = std.SemanticVersion { .major = 0 , .minor = 13 , .patch = 0 };
330
+ const needed_version = std.SemanticVersion { .major = 0 , .minor = 14 , .patch = 0 };
336
331
const version = builtin .zig_version ;
337
332
const order = version .order (needed_version );
338
333
return order != .lt ;
0 commit comments