-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.zig
More file actions
97 lines (79 loc) · 2.82 KB
/
build.zig
File metadata and controls
97 lines (79 loc) · 2.82 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
const std = @import("std");
const path = std.fs.path;
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const is_windows = target.query.os_tag == .windows;
const tiny_aes_lib = b.addStaticLibrary(.{
.name = "aes",
.optimize = .Debug,
.target = target,
});
tiny_aes_lib.addCSourceFiles(.{
.files = &.{"lib/aes/aes.c"},
.flags = &.{"-std=c99"},
});
tiny_aes_lib.linkLibC();
const zigwin32_module = b.dependency("zigwin32", .{}).module("zigwin32");
const module = b.addModule("zig-sec", .{
.root_source_file = b.path("src/utils/zig-sec.zig"),
.imports = &.{
.{ .name = "zigwin32", .module = zigwin32_module },
},
.target = target,
.optimize = optimize,
});
const file_to_build = b.option(
[]const u8,
"file",
"Specify the file to build",
) orelse "src/main.zig";
const build_type = b.option(
enum { exe, lib },
"type",
"Specify build type: exe or lib",
) orelse .exe;
const use_tiny_aes = b.option(
bool,
"tiny-aes",
"Use Tiny AES library",
) orelse false;
if (use_tiny_aes and !is_windows) @panic("Tiny AES library is only supported on Windows");
switch (build_type) {
.exe => {
const exe = b.addExecutable(.{
.name = path.stem(file_to_build),
.root_source_file = b.path(file_to_build),
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("zigwin32", zigwin32_module);
exe.root_module.addImport("zig-sec", module);
exe.addLibraryPath(b.path("lib"));
exe.addIncludePath(b.path("lib"));
if (use_tiny_aes) exe.linkLibrary(tiny_aes_lib);
b.installArtifact(exe);
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
},
.lib => {
const lib = b.addSharedLibrary(.{
.name = std.fs.path.stem(file_to_build),
.root_source_file = b.path(file_to_build),
.target = target,
.optimize = optimize,
});
lib.root_module.addImport("zigwin32", zigwin32_module);
lib.root_module.addImport("zig-sec", module);
lib.addLibraryPath(b.path("lib"));
lib.addIncludePath(b.path("lib"));
if (use_tiny_aes) lib.linkLibrary(tiny_aes_lib);
b.installArtifact(lib);
},
}
}