-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
98 lines (86 loc) · 2.78 KB
/
build.zig
File metadata and controls
98 lines (86 loc) · 2.78 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
const std = @import("std");
const builtin = @import("builtin");
fn addDep(
artifact: *std.Build.Step.Compile,
b: *std.Build,
) void {
const has_avx2 = std.Target.x86.featureSetHas(builtin.cpu.features, .avx2);
if (has_avx2) {
const asm_step = b.addSystemCommand(&.{
"zig",
"cc",
"-c",
"src/asm_folly.S",
"-o",
"src/folly.o",
"-D__AVX2__",
// "-DFOLLY_MEMCPY_IS_MEMCPY",
"-mtune=native",
"-fno-exceptions",
"-g0",
});
artifact.step.dependOn(&asm_step.step);
artifact.addObjectFile(b.path("src/folly.o"));
const asm_step2 = b.addSystemCommand(&.{
"zig",
"cc",
"-c",
"src/asm_folly_memset.S",
"-o",
"src/folly_memset.o",
"-D__AVX2__",
// "-DFOLLY_MEMCPY_IS_MEMCPY",
"-mtune=native",
"-fno-exceptions",
"-g0",
});
artifact.step.dependOn(&asm_step2.step);
artifact.addObjectFile(b.path("src/folly_memset.o"));
}
}
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const lib_mod = b.createModule(.{
.root_source_file = b.path("src/lib.zig"),
.target = target,
.optimize = optimize,
});
const has_avx2 = std.Target.x86.featureSetHas(builtin.cpu.features, .avx2);
if (has_avx2 and builtin.cpu.arch == .x86_64) {
lib_mod.addAssemblyFile(b.path("src/asm_folly.S"));
lib_mod.addAssemblyFile(b.path("src/asm_folly_memset.S"));
}
b.modules.put("stdx", lib_mod) catch @panic("OOM");
const lib = b.addLibrary(.{
.linkage = .static,
.name = "stdx",
.root_module = lib_mod,
.use_llvm = true,
});
// addDep(lib, b);
b.installArtifact(lib);
const bench_mod = b.createModule(.{
.root_source_file = b.path("benchmarks/bench.zig"),
.target = target,
.optimize = .ReleaseFast,
});
bench_mod.addImport("stdx", lib_mod);
const bench_exe = b.addExecutable(.{
.name = "bench",
.root_module = bench_mod,
});
bench_exe.linkLibrary(lib);
b.installArtifact(bench_exe);
const bench_cmd = b.addRunArtifact(bench_exe);
bench_cmd.step.dependOn(b.getInstallStep());
const bench_step = b.step("bench", "Run benchmarks");
bench_step.dependOn(&bench_cmd.step);
const lib_unit_tests = b.addTest(.{
.root_module = lib_mod,
.use_llvm = true,
});
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);
}