-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathbuild.zig
More file actions
113 lines (105 loc) · 3.65 KB
/
Copy pathbuild.zig
File metadata and controls
113 lines (105 loc) · 3.65 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
// Copyright © 2026, Halide Compression, LLC.
// All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const strip = b.option(bool, "strip", "strip symbols from the binary, defaults to false") orelse false;
const flto = b.option(bool, "flto", "enable Link Time Optimization, defaults to false") orelse false;
const options = b.addOptions();
// simpleimgio
const simpleimgio_dep = b.dependency("simpleimgio", .{
.target = target,
.optimize = optimize,
});
const simpleimgio = simpleimgio_dep.module("simpleimgio");
// libspng
const spng_dep = b.dependency("spng", .{
.target = target,
.optimize = optimize,
});
const spng = spng_dep.artifact("spng");
const translate_c = b.addTranslateC(.{
.root_source_file = b.path("c_imports.h"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
translate_c.addIncludePath(b.path("."));
translate_c.addIncludePath(spng.getEmittedIncludeTree());
const c_module = translate_c.createModule();
// 'libcvvdp.a' static lib
const cvvdp = b.addLibrary(.{
.name = "cvvdp",
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
.strip = strip,
}),
});
const cvvdp_sources = [_][]const u8{
"src/cvvdp.c",
"src/cvvdp_c.c",
};
const cvvdp_flags = [_][]const u8{
"-std=c23",
"-Wall",
"-Wextra",
"-Wpedantic",
"-O3",
"-ffast-math",
};
const target_result = target.result;
cvvdp.root_module.addCSourceFiles(.{
.files = &cvvdp_sources,
.flags = &cvvdp_flags,
});
if (target_result.cpu.arch == .x86_64) {
cvvdp.root_module.addCSourceFile(.{
.file = b.path("src/cvvdp_avx2.c"),
.flags = &cvvdp_flags,
});
} else if (target_result.cpu.arch == .aarch64) {
cvvdp.root_module.addCSourceFile(.{
.file = b.path("src/cvvdp_neon.c"),
.flags = &cvvdp_flags,
});
}
cvvdp.root_module.addIncludePath(b.path("."));
cvvdp.lto = if (flto) .full else null;
b.installArtifact(cvvdp);
// cvvdp.h
cvvdp.installHeader(b.path("src/cvvdp.h"), "cvvdp.h");
// 'fcvvdp' executable
const cvvdpenc = b.addExecutable(.{
.name = "fcvvdp",
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
.strip = strip,
}),
.use_llvm = true,
});
cvvdpenc.root_module.addOptions("build_opts", options);
cvvdpenc.root_module.addImport("c", c_module);
cvvdpenc.root_module.addImport("simpleimgio", simpleimgio);
cvvdpenc.root_module.addIncludePath(b.path("."));
cvvdpenc.root_module.linkLibrary(cvvdp);
cvvdpenc.root_module.linkLibrary(spng);
b.installArtifact(cvvdpenc);
}