-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild.zig
More file actions
95 lines (78 loc) · 3.11 KB
/
Copy pathbuild.zig
File metadata and controls
95 lines (78 loc) · 3.11 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
const std = @import("std");
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const portable = b.option(bool, "portable", "turn on portable mode") orelse false;
const upstream = b.dependency("blst", .{});
var c_flags = std.ArrayList([]const u8).empty;
defer c_flags.deinit(b.allocator);
try c_flags.append(b.allocator, "-fno-builtin");
try c_flags.append(b.allocator, "-Wno-unused-function");
try c_flags.append(b.allocator, "-Wno-unused-command-line-argument");
if (target.result.cpu.arch == .x86_64) {
try c_flags.append(b.allocator, "-mno-avx"); // avoid costly transitions
}
const lib = b.addLibrary(.{
.name = "blst",
.root_module = b.createModule(
.{
.target = target,
.optimize = optimize,
.link_libc = true,
.pic = true,
},
),
});
if (portable) {
lib.root_module.addCMacro("__BLST_PORTABLE__", "");
} else {
// Guard __ADX__ check to x86_64 only.
// std.Target.x86.featureSetHas on non-x86 cpu features is meaningless —
// the feature indices differ per-arch and may accidentally return true
// for unrelated ARM features, incorrectly defining __ADX__ and breaking
// symbol resolution (server.c then references ctx_* symbols that don't
// exist in the mach-o/elf ARM64 assembly).
if (target.result.cpu.arch == .x86_64 and
std.Target.x86.featureSetHas(target.result.cpu.features, .adx))
{
lib.root_module.addCMacro("__ADX__", "");
}
}
if (target.result.cpu.arch == .aarch64) lib.root_module.addCMacro("__ARM_FEATURE_CRYPTO", "1");
if (target.result.cpu.arch != .x86_64 and
target.result.cpu.arch != .aarch64)
{
lib.root_module.addCMacro("__BLST_NO_ASM__", "");
}
lib.installHeader(upstream.path("bindings/blst.h"), "blst.h");
lib.installHeader(upstream.path("bindings/blst_aux.h"), "blst_aux.h");
lib.root_module.addCSourceFiles(.{
.root = upstream.path(""),
.files = &.{
"src/server.c",
"build/assembly.S",
},
.flags = c_flags.items,
});
const translated_headers = b.addTranslateC(.{
.root_source_file = upstream.path("bindings/blst.h"),
.target = target,
.optimize = optimize,
});
translated_headers.addIncludePath(upstream.path("bindings"));
const module = translated_headers.addModule("blst");
module.linkLibrary(lib);
b.installArtifact(lib);
const module_tests = b.addTest(.{
.name = "blst-module-tests",
.root_module = b.createModule(.{
.root_source_file = b.path("src/test.zig"),
.target = target,
.optimize = optimize,
}),
});
module_tests.root_module.addImport("blst", module);
const run_module_tests = b.addRunArtifact(module_tests);
const test_step = b.step("test", "Test the public blst module");
test_step.dependOn(&run_module_tests.step);
}