forked from twoeths/hashtree-z
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbuild.zig
More file actions
96 lines (85 loc) · 3.16 KB
/
Copy pathbuild.zig
File metadata and controls
96 lines (85 loc) · 3.16 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
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const upstream = b.dependency("hashtree", .{});
const lib = b.addLibrary(.{
.name = "hashtree",
.linkage = .static,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
.pic = true,
}),
});
const base_asm_flags: []const []const u8 = &.{ "-g", "-fpic" };
// The x86 .S files use GAS-specific constructs (`.equiv` register aliases
// in Intel syntax) that LLVM's integrated assembler doesn't parse the same
// way binutils `as` does. Force the clang driver to delegate to an external
// `as` so the files assemble. Requires binutils in the host environment —
// this drops hermetic cross-compilation for the x86 asm path, but matches
// what upstream's Makefile relies on.
const x86_asm_flags: []const []const u8 = base_asm_flags ++ &[_][]const u8{
"-fno-integrated-as",
};
const os = target.result.os.tag;
const abi = target.result.abi;
if (target.result.cpu.arch.isArm() or target.result.cpu.arch.isAARCH64()) {
lib.root_module.addCSourceFiles(.{
.root = upstream.path("src"),
.files = &[_][]const u8{
"sha256_armv8_neon_x4.S",
"sha256_armv8_neon_x1.S",
"sha256_armv8_crypto.S",
},
.flags = base_asm_flags,
});
// The x86 .S files use ELF-only directives (.section .rodata, byte-count
// .align, .type %function) that LLVM MC can't translate to Mach-O or
// COFF-MSVC. Those targets fall through to the generic C implementation.
} else if (target.result.cpu.arch.isX86() and
os != .macos and
!(os == .windows and abi == .msvc))
{
lib.root_module.addCSourceFiles(.{
.root = upstream.path("src"),
.files = &[_][]const u8{
"sha256_shani.S",
"sha256_avx_x16.S",
"sha256_avx_x8.S",
"sha256_avx_x4.S",
"sha256_avx_x1.S",
"sha256_sse_x1.S",
},
.flags = x86_asm_flags,
});
}
lib.root_module.addCSourceFiles(.{
.root = upstream.path("src"),
.files = &[_][]const u8{
"hashtree.c",
"sha256_generic.c",
},
.flags = &.{
"-g",
"-Wall",
"-Werror",
},
});
lib.root_module.addIncludePath(upstream.path("src"));
lib.installHeader(upstream.path("src/hashtree.h"), "hashtree.h");
b.installArtifact(lib);
const module = b.addModule("hashtree", .{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
});
module.linkLibrary(lib);
const mod_unit_tests = b.addTest(.{
.root_module = module,
});
const run_mod_unit_tests = b.addRunArtifact(mod_unit_tests);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_mod_unit_tests.step);
}