-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.zig
90 lines (78 loc) · 2.66 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
84
85
86
87
88
89
90
const std = @import("std");
const builtin = @import("builtin");
const zcc = @import("compile_commands");
const app_name = "vmath";
const lib_flags = &[_][]const u8{
"-std=c99", // need inline and restrict
"-pedantic",
"-Wall",
"-Werror",
"-march=znver1",
// flag only for lib
"-Iinclude/",
};
// test flags dont include "-Iinclude"
const test_flags = lib_flags[0..(lib_flags.len - 1)];
const test_source_files = &[_][]const u8{
"vec2_f32.c",
"vec4_f32.c",
"vec8_f32.c",
"vec16_f32.c",
};
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// targets which will only build with the run_tests and install_tests steps
var tests = std.ArrayList(*std.Build.Step.Compile).init(b.allocator);
defer tests.deinit();
var lib = b.addStaticLibrary(.{
.name = "vmath",
.optimize = optimize,
.target = target,
// TODO: figure out how to not have to link libc, needed for mm_malloc
// in xmmtrin but im pretty sure its not needed in theory
.link_libc = true,
});
lib.addCSourceFiles(.{
.root = b.path("src/"),
.files = &.{
"impl.c",
"memutil.c",
},
.flags = lib_flags,
});
lib.installHeadersDirectory(b.path("include/"), "", .{});
b.installArtifact(lib);
for (test_source_files) |source_file| {
var test_exe = b.addExecutable(.{
.name = std.fs.path.stem(source_file),
.optimize = optimize,
.target = target,
});
test_exe.addCSourceFile(.{
.file = .{ .src_path = .{
.owner = b,
.sub_path = b.pathJoin(&.{ "tests", source_file }),
} },
.flags = test_flags,
});
test_exe.linkLibC();
test_exe.linkSystemLibrary("check");
test_exe.linkLibrary(lib);
try tests.append(test_exe);
}
const run_tests_step = b.step("run_tests", "Compile and run all the tests");
const install_tests_step = b.step("install_tests", "Install all the tests but don't run them");
for (tests.items) |test_exe| {
const test_install = b.addInstallArtifact(test_exe, .{});
install_tests_step.dependOn(&test_install.step);
const test_run = b.addRunArtifact(test_exe);
if (b.args) |args| {
test_run.addArgs(args);
}
run_tests_step.dependOn(&test_run.step);
}
try @import("templates/build.zig").generate(b, "code");
try tests.append(lib); // get intellisense for tests + lib
zcc.createStep(b, "cdb", try tests.toOwnedSlice());
}