This repository has been archived by the owner on Dec 5, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
build.zig
70 lines (62 loc) · 1.83 KB
/
build.zig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const std = @import("std");
const zt = @import("deps/ZT/build.zig");
pub fn build(b: *std.build.Builder) !void {
const mode = b.standardReleaseOptions();
var target = b.standardTargetOptions(.{});
// needed by sqlite but breaks zt
//target.setGnuLibCVersion(2, 28, 0);
const run = addBin(
b,
b.addExecutable("run", "./bin/run.zig"),
"run",
"Evaluate an imp file",
);
commonSetup(run.bin, mode, target);
run.run.addArgs(b.args orelse &.{});
const test_unit = addBin(
b,
b.addTestExe("test_unit", "./bin/run.zig"),
"test_unit",
"Run unit tests",
);
commonSetup(test_unit.bin, mode, target);
const test_step = b.step("test", "Run all tests");
test_step.dependOn(test_unit.step);
}
fn addBin(
b: *std.build.Builder,
bin: *std.build.LibExeObjStep,
name: []const u8,
description: []const u8,
) struct {
bin: *std.build.LibExeObjStep,
run: *std.build.RunStep,
step: *std.build.Step,
} {
const run = bin.run();
const step = b.step(name, description);
step.dependOn(&run.step);
return .{ .bin = bin, .run = run, .step = step };
}
fn commonSetup(
bin: *std.build.LibExeObjStep,
mode: std.builtin.Mode,
target: std.zig.CrossTarget,
) void {
bin.setMainPkgPath("./");
addDeps(bin);
bin.setBuildMode(mode);
bin.setTarget(target);
zt.link(bin);
}
pub fn addDeps(
bin: *std.build.LibExeObjStep,
) void {
bin.linkLibC();
bin.addIncludeDir(getRelativePath() ++ "deps/sqlite-amalgamation-3370000/");
bin.addCSourceFile(getRelativePath() ++ "deps/sqlite-amalgamation-3370000/sqlite3.c", &[_][]const u8{"-std=c99"});
}
fn getRelativePath() []const u8 {
comptime var src: std.builtin.SourceLocation = @src();
return std.fs.path.dirname(src.file).? ++ std.fs.path.sep_str;
}