-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
90 lines (77 loc) · 3.19 KB
/
build.zig
File metadata and controls
90 lines (77 loc) · 3.19 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
const std = @import("std");
pub const OSBuilder = @import("build");
const targets = OSBuilder.Targets;
const CompOS = @This();
fn root() []const u8 {
return comptime (std.fs.path.dirname(@src().file) orelse ".");
}
const build_root = root();
pub fn build(build_ctx: *std.Build) !void {
const target_options = build_ctx.standardTargetOptions(.{});
const optimize = build_ctx.standardOptimizeOption(.{});
const is_test = build_ctx.option(bool, "test", "Run test suite") orelse false;
if (!is_test) { // Normal Library build
const compile_target = build_ctx.option([]const u8, "Compile_Target", "Target to compile for") orelse "testing";
const library_type = build_ctx.option([]const u8, "Library_Type", "Type of library to build (Static/Shared)") orelse "Static";
const library = try OSBuilder.init(
build_ctx,
.{
.optimize = optimize,
.target = compile_target,
.lib_type = library_type,
},
"",
);
const size_step_option = build_ctx.step("size", "Display size information of the built artifact");
const size_step = build_ctx.addSystemCommand(&[_][]const u8{
"size",
"-A",
"-d",
library.getEmittedBin().getPath(build_ctx),
});
size_step.step.dependOn(&library.step);
size_step_option.dependOn(&size_step.step);
// Compile Commands for Intellisense
OSBuilder.AddCompileCommandStep(build_ctx, library);
} else {
// Test scenarios
const test_step = build_ctx.step("test", "Run all test scenarios");
const allocator_options = [_][]const u8{
// "USE_LIST_ALLOCATOR",
"USE_ZIG_ALLOCATOR",
"USE_CLANG_ALLOCATOR",
};
// Build test scenarios
inline for (allocator_options) |allocator| {
const test_name = build_ctx.fmt("test_scenario_{s}", .{allocator});
// Build the library
const lib = try OSBuilder.init(
build_ctx,
.{
.optimize = .Debug,
.target = "testing",
.lib_type = "Static",
},
allocator, // Add -D prefix
);
// Create test runner
const run_test = build_ctx.addTest(.{
.name = test_name,
.root_source_file = .{ .cwd_relative = "tests/main_test.zig" },
.optimize = .Debug,
.target = target_options,
.link_libc = true,
});
// Link with the library and add include paths
run_test.linkLibrary(lib);
run_test.addIncludePath(.{ .cwd_relative = build_root ++ "/inc" });
run_test.addIncludePath(.{ .cwd_relative = build_root ++ "/src" });
run_test.defineCMacro("TESTING_MODE", "1");
run_test.defineCMacro(allocator, "1");
// Create run step for this test
const run_test_step = build_ctx.addRunArtifact(run_test);
run_test_step.step.dependOn(&lib.step);
test_step.dependOn(&run_test_step.step);
}
}
}