-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.zig
91 lines (74 loc) · 2.94 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
91
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
const std = @import("std");
// TODO: https://github.com/ziglang/zig/issues/14531
const version = "0.1.0-dev";
pub fn build(b: *std.Build) anyerror!void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const install_tls = b.getInstallStep();
const check_tls = b.step("check", "Run source code checks");
const fmt_tls = b.step("fmt", "Fix source code formatting");
const test_tls = b.step("test", "Build and run tests");
const fmt_paths = &[_][]const u8{
"lib",
"build.zig",
"build.zig.zon",
};
check_tls.dependOn(&b.addFmt(.{
.paths = fmt_paths,
.check = true,
}).step);
fmt_tls.dependOn(&b.addFmt(.{
.paths = fmt_paths,
}).step);
_ = b.addModule("ap", .{
.root_source_file = b.path(b.pathJoin(&.{ "lib", "ap.zig" })),
.target = target,
.optimize = optimize,
// Avoid adding opinionated build options to the module itself as those will be forced on third-party users.
});
const stlib_step = b.addStaticLibrary(.{
// Avoid name clash with the DLL import library on Windows.
.name = if (target.result.os.tag == .windows) "libap" else "ap",
.root_source_file = b.path(b.pathJoin(&.{ "lib", "c.zig" })),
.target = target,
.optimize = optimize,
.strip = optimize != .Debug,
});
const shlib_step = b.addSharedLibrary(.{
.name = "ap",
.root_source_file = b.path(b.pathJoin(&.{ "lib", "c.zig" })),
.target = target,
.optimize = optimize,
.strip = optimize != .Debug,
});
// On Linux, undefined symbols are allowed in shared libraries by default; override that.
shlib_step.linker_allow_shlib_undefined = false;
inline for (.{ stlib_step, shlib_step }) |step| {
step.installHeadersDirectory(b.path("inc"), "ap", .{});
b.installArtifact(step);
}
install_tls.dependOn(&b.addInstallLibFile(b.addWriteFiles().add("libap.pc", b.fmt(
\\prefix=${{pcfiledir}}/../..
\\exec_prefix=${{prefix}}
\\includedir=${{prefix}}/include/ap
\\libdir=${{prefix}}/lib
\\
\\Name: libap
\\Description: An arbitrary-precision numerics library, ported from LLVM to Zig with a C API.
\\URL: https://github.com/vezel-dev/libap
\\Version: {s}
\\
\\Cflags: -I${{includedir}}
\\Libs: -L${{libdir}} -lap
, .{version})), b.pathJoin(&.{ "pkgconfig", "libap.pc" })).step);
const run_test_step = b.addRunArtifact(b.addTest(.{
.name = "ap-test",
.root_source_file = b.path(b.pathJoin(&.{ "lib", "ap.zig" })),
.target = target,
.optimize = optimize,
}));
// Always run tests when requested, even if the binary has not changed.
run_test_step.has_side_effects = true;
test_tls.dependOn(&run_test_step.step);
}