-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.zig
83 lines (69 loc) · 2.94 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
71
72
73
74
75
76
77
78
79
80
81
82
83
const std = @import("std");
pub const min_zig_version = std.SemanticVersion{ .major = 0, .minor = 12, .patch = 0 };
pub fn build(b: *std.Build) void {
ensureZigVersion() catch return;
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const lib = b.addSharedLibrary(.{
.name = "zsmooth",
.root_source_file = .{ .path = "src/zsmooth.zig" },
.target = target,
.optimize = optimize,
// Improve build times by giving an upper bound to memory,
// thus enabling multi-threaded builds.
.max_rss = 1024 * 1024 * 1024 * 2, // 2GB
// This application is single threaded (as VapourSynth handles the threading for us)
// so might as well mark it so in case we ever import data
// structures that *might* have thread safety built in,
// in which case setting this value will optimize out any threading
// or locking constructs.
.single_threaded = true,
});
const vapoursynth_dep = b.dependency("vapoursynth", .{
.target = target,
.optimize = optimize,
});
lib.root_module.addImport("vapoursynth", vapoursynth_dep.module("vapoursynth"));
lib.linkLibC(); // Necessary to use the C memory allocator.
if (lib.root_module.optimize == .ReleaseFast) {
lib.root_module.strip = true;
}
b.installArtifact(lib);
// Test setup
// Creates a step for unit testing. This only builds the test executable
// but does not run it.
const lib_unit_tests = b.addTest(.{
.root_source_file = .{ .path = "src/zsmooth.zig" },
.target = target,
.optimize = optimize,
});
lib_unit_tests.root_module.addImport("vapoursynth", vapoursynth_dep.module("vapoursynth"));
lib_unit_tests.linkLibC();
const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);
// Similar to creating the run step earlier, this exposes a `test` step to
// the `zig build --help` menu, providing a way for the user to request
// running the unit tests.
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_lib_unit_tests.step);
}
fn ensureZigVersion() !void {
var installed_ver = @import("builtin").zig_version;
installed_ver.build = null;
if (installed_ver.order(min_zig_version) == .lt) {
std.log.err("\n" ++
\\---------------------------------------------------------------------------
\\
\\Installed Zig compiler version is too old.
\\
\\Min. required version: {any}
\\Installed version: {any}
\\
\\Please install newer version and try again.
\\Latest version can be found here: https://ziglang.org/download/
\\
\\---------------------------------------------------------------------------
\\
, .{ min_zig_version, installed_ver });
return error.ZigIsTooOld;
}
}