-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
78 lines (69 loc) · 2.66 KB
/
build.zig
File metadata and controls
78 lines (69 loc) · 2.66 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
const std = @import("std");
const builtin = @import("builtin");
pub fn build(b: *std.Build) void {
comptime {
const needed = "0.15.2";
const current = builtin.zig_version;
const needed_vers = std.SemanticVersion.parse(needed) catch unreachable;
if (current.order(needed_vers) != .eq) {
@compileError(std.fmt.comptimePrint("Your zig version is not supported, need version {s}", .{needed}));
}
}
const optimize = b.standardOptimizeOption(.{});
const strip = b.option(bool, "strip", "Strip the binary") orelse switch (optimize) {
.Debug, .ReleaseSafe => false,
else => true,
};
const fmt_step = b.step("fmt", "Format zig source code");
const fmt = b.addFmt(.{
.paths = &.{
"build.zig",
},
});
fmt_step.dependOn(&fmt.step);
const Executable = struct {
name: []const u8,
srcs: []const []const u8,
};
const executables = [_]Executable{
.{ .name = "kevs", .srcs = &[_][]const u8{ "src/c/cli.c", "src/c/util.c", "src/c/kevs.c" } },
.{ .name = "unittests", .srcs = &[_][]const u8{ "src/c/unittests.c", "src/c/kevs.c" } },
.{ .name = "example", .srcs = &[_][]const u8{ "src/c/example.c", "src/c/util.c", "src/c/kevs.c" } },
};
const targets = [_]std.Target.Query{
.{ .os_tag = .linux, .cpu_arch = .aarch64 },
.{ .os_tag = .linux, .cpu_arch = .x86_64 },
.{ .os_tag = .macos, .cpu_arch = .aarch64 },
.{ .os_tag = .macos, .cpu_arch = .x86_64 },
.{ .os_tag = .windows, .cpu_arch = .x86 },
.{ .os_tag = .windows, .cpu_arch = .x86_64 },
};
for (executables) |executable| {
for (targets) |query| {
const target = b.resolveTargetQuery(query);
const t = target.result;
const exe = b.addExecutable(.{
.name = executable.name,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.strip = strip,
.link_libc = true,
}),
});
exe.addCSourceFiles(.{
.files = executable.srcs,
.flags = &.{ "-std=c99", "-g", "-Wall", "-Wextra", "-Werror" },
});
const install = b.addInstallArtifact(exe, .{});
install.dest_dir = .prefix;
install.dest_sub_path = b.fmt("{s}/{s}/{s}/{s}", .{
@tagName(optimize),
@tagName(t.os.tag),
@tagName(t.cpu.arch),
exe.name,
});
b.getInstallStep().dependOn(&install.step);
}
}
}