forked from srmadrid/zsl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
126 lines (102 loc) · 4.01 KB
/
build.zig
File metadata and controls
126 lines (102 loc) · 4.01 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
const std = @import("std");
const IntMode = enum {
default,
wrap,
saturate,
};
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const options = b.addOptions();
const opt_int_mode = b.option(IntMode, "int_mode", "Integer operation mode") orelse IntMode.wrap;
options.addOption(IntMode, "int_mode", opt_int_mode);
const opt_max_dimensions = b.option(u32, "max_dimensions", "Maximum number of dimensions for `Array`s") orelse 8;
options.addOption(u32, "max_dimensions", opt_max_dimensions);
// Option to provide BLAS and LAPACK implementations
const opt_link_cblas = b.option([]const u8, "link_cblas", "Link CBLAS implementation");
options.addOption(?[]const u8, "link_cblas", opt_link_cblas);
const opt_link_lapacke = b.option([]const u8, "link_lapacke", "Link LAPACKE implementation");
options.addOption(?[]const u8, "link_lapacke", opt_link_lapacke);
const module = b.addModule("zsl", .{
.root_source_file = b.path("src/zsl.zig"),
.target = target,
.optimize = optimize,
});
module.addOptions("options", options);
// Executable (for testing)
const exe = b.addExecutable(.{
.name = "main",
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
}),
});
exe.root_module.addImport("zsl", module);
if (opt_link_cblas != null or opt_link_lapacke != null) {
exe.linkLibC();
}
if (opt_link_cblas != null) {
exe.root_module.linkSystemLibrary(opt_link_cblas.?, .{});
}
if (opt_link_lapacke != null) {
exe.root_module.linkSystemLibrary(opt_link_lapacke.?, .{});
}
b.installArtifact(exe);
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
const run_step = b.step("run", "Run the executable");
run_step.dependOn(&run_cmd.step);
// Compile only CBLAS
const cblas_lib = b.addLibrary(.{
.linkage = .dynamic,
.name = "blas",
.root_module = b.createModule(.{
.root_source_file = b.path("src/cblas.zig"),
.target = target,
.optimize = optimize,
}),
});
cblas_lib.root_module.addImport("zsl", module);
const cblas_install = b.addInstallArtifact(cblas_lib, .{});
const cblas_step = b.step("cblas", "Compile CBLAS library");
cblas_step.dependOn(&cblas_install.step);
// Tests
const opt_verbose_tests = b.option(bool, "verbose_tests", "Enable verbose output for tests") orelse false;
options.addOption(bool, "verbose_tests", opt_verbose_tests);
const lib_unit_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("test/zsl.zig"),
.target = target,
.optimize = optimize,
}),
});
lib_unit_tests.root_module.addImport("zsl", module);
if (opt_link_cblas != null or opt_link_lapacke != null) {
lib_unit_tests.linkLibC();
}
if (opt_link_cblas != null) {
lib_unit_tests.root_module.linkSystemLibrary(opt_link_cblas.?, .{});
}
if (opt_link_lapacke != null) {
lib_unit_tests.root_module.linkSystemLibrary(opt_link_lapacke.?, .{});
}
const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_lib_unit_tests.step);
// Documentation
const lib = b.addLibrary(.{
.name = "zsl",
.root_module = module,
});
const install_docs = b.addInstallDirectory(.{
.source_dir = lib.getEmittedDocs(),
.install_dir = .prefix,
.install_subdir = "docs",
});
const docs_step = b.step("docs", "Update documentation in the `docs/` directory");
docs_step.dependOn(&install_docs.step);
// Steps
const check_step = b.step("check", "Check if the code compiles; this is for ZLS");
check_step.dependOn(&exe.step);
}