2024-11-16 01:00:15 +00:00
|
|
|
const std = @import("std");
|
|
|
|
|
|
|
|
pub fn build(b: *std.Build) void {
|
2024-12-29 12:34:56 +00:00
|
|
|
// Standard target options
|
2024-11-16 01:00:15 +00:00
|
|
|
const target = b.standardTargetOptions(.{});
|
|
|
|
const optimize = b.standardOptimizeOption(.{});
|
|
|
|
|
2024-12-29 12:34:56 +00:00
|
|
|
// Create options module for tracing
|
|
|
|
const executionTracing = b.option(bool, "tracing", "enable execution tracing") orelse false;
|
|
|
|
const options = b.addOptions();
|
|
|
|
options.addOption(bool, "tracing", executionTracing);
|
|
|
|
|
|
|
|
// Create the options module that will be shared
|
|
|
|
const options_module = options.createModule();
|
|
|
|
|
2024-12-06 02:02:09 +00:00
|
|
|
const exe = b.addExecutable(.{
|
2024-11-16 01:00:15 +00:00
|
|
|
.name = "thp",
|
2024-12-06 02:02:09 +00:00
|
|
|
.root_source_file = b.path("src/main.zig"),
|
2024-11-16 01:00:15 +00:00
|
|
|
.target = target,
|
|
|
|
.optimize = optimize,
|
|
|
|
});
|
|
|
|
|
2024-12-29 12:34:56 +00:00
|
|
|
// Add options to executable
|
|
|
|
exe.root_module.addImport("config", options_module);
|
2024-12-21 11:46:53 +00:00
|
|
|
|
2024-12-21 11:11:16 +00:00
|
|
|
//
|
|
|
|
// Error handling module
|
|
|
|
//
|
|
|
|
const error_module = b.addModule("errors", .{
|
|
|
|
.root_source_file = b.path("src/errors/root.zig"),
|
|
|
|
.target = target,
|
|
|
|
.optimize = optimize,
|
|
|
|
});
|
2024-12-29 12:34:56 +00:00
|
|
|
error_module.addImport("config", options_module);
|
2024-12-21 11:11:16 +00:00
|
|
|
exe.root_module.addImport("errors", error_module);
|
|
|
|
|
2024-12-06 02:02:09 +00:00
|
|
|
//
|
|
|
|
// Lexic module
|
|
|
|
//
|
|
|
|
const lexic_module = b.addModule("lexic", .{
|
|
|
|
.root_source_file = b.path("src/01_lexic/root.zig"),
|
|
|
|
.target = target,
|
|
|
|
.optimize = optimize,
|
|
|
|
});
|
2024-12-29 12:34:56 +00:00
|
|
|
lexic_module.addImport("config", options_module);
|
2024-12-21 11:11:16 +00:00
|
|
|
lexic_module.addImport("errors", error_module);
|
2024-12-29 12:34:56 +00:00
|
|
|
exe.root_module.addImport("lexic", lexic_module);
|
2024-11-16 01:00:15 +00:00
|
|
|
|
2024-12-06 02:02:09 +00:00
|
|
|
//
|
|
|
|
// Syntax module
|
|
|
|
//
|
|
|
|
const syntax_module = b.addModule("syntax", .{
|
|
|
|
.root_source_file = b.path("src/02_syntax/root.zig"),
|
2024-11-16 01:00:15 +00:00
|
|
|
.target = target,
|
|
|
|
.optimize = optimize,
|
|
|
|
});
|
2024-12-29 12:34:56 +00:00
|
|
|
syntax_module.addImport("config", options_module);
|
2024-12-21 11:11:16 +00:00
|
|
|
syntax_module.addImport("lexic", lexic_module);
|
|
|
|
syntax_module.addImport("errors", error_module);
|
2024-12-29 12:34:56 +00:00
|
|
|
exe.root_module.addImport("syntax", syntax_module);
|
2024-11-16 01:00:15 +00:00
|
|
|
|
2024-12-29 12:34:56 +00:00
|
|
|
// Install step
|
2024-11-16 01:00:15 +00:00
|
|
|
b.installArtifact(exe);
|
|
|
|
|
2024-12-29 12:34:56 +00:00
|
|
|
// Run command
|
2024-11-16 01:00:15 +00:00
|
|
|
const run_cmd = b.addRunArtifact(exe);
|
|
|
|
run_cmd.step.dependOn(b.getInstallStep());
|
|
|
|
|
2024-12-29 12:34:56 +00:00
|
|
|
// Pass arguments if any
|
2024-11-16 01:00:15 +00:00
|
|
|
if (b.args) |args| {
|
|
|
|
run_cmd.addArgs(args);
|
|
|
|
}
|
|
|
|
|
2024-12-29 12:34:56 +00:00
|
|
|
// Run step
|
2024-11-16 01:00:15 +00:00
|
|
|
const run_step = b.step("run", "Run the app");
|
|
|
|
run_step.dependOn(&run_cmd.step);
|
|
|
|
|
2024-12-29 12:34:56 +00:00
|
|
|
// Unit tests
|
2024-11-16 01:00:15 +00:00
|
|
|
const exe_unit_tests = b.addTest(.{
|
|
|
|
.root_source_file = b.path("src/main.zig"),
|
|
|
|
.target = target,
|
|
|
|
.optimize = optimize,
|
|
|
|
});
|
2024-12-29 12:34:56 +00:00
|
|
|
exe_unit_tests.root_module.addImport("config", options_module);
|
2024-12-06 02:02:09 +00:00
|
|
|
exe_unit_tests.root_module.addImport("lexic", lexic_module);
|
|
|
|
exe_unit_tests.root_module.addImport("syntax", syntax_module);
|
2024-12-21 11:11:16 +00:00
|
|
|
exe_unit_tests.root_module.addImport("errors", error_module);
|
2024-11-16 01:00:15 +00:00
|
|
|
|
|
|
|
const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests);
|
|
|
|
|
2024-11-16 12:16:10 +00:00
|
|
|
const test_step = b.step("test", "Run ALL unit tests");
|
2024-11-16 01:00:15 +00:00
|
|
|
test_step.dependOn(&run_exe_unit_tests.step);
|
2024-11-16 12:16:10 +00:00
|
|
|
|
2024-12-06 02:02:09 +00:00
|
|
|
// Add dependencies for unit testing
|
2024-11-16 12:16:10 +00:00
|
|
|
const files = [_][]const u8{
|
|
|
|
"src/01_lexic/root.zig",
|
2024-12-06 02:02:09 +00:00
|
|
|
"src/02_syntax/root.zig",
|
2024-12-24 23:33:02 +00:00
|
|
|
"src/errors/root.zig",
|
2024-11-16 12:16:10 +00:00
|
|
|
};
|
|
|
|
for (files) |file| {
|
|
|
|
const file_unit_test = b.addTest(.{
|
|
|
|
.root_source_file = b.path(file),
|
|
|
|
.target = target,
|
|
|
|
.optimize = optimize,
|
|
|
|
});
|
2024-12-29 12:34:56 +00:00
|
|
|
file_unit_test.root_module.addImport("config", options_module);
|
2024-12-06 02:02:09 +00:00
|
|
|
file_unit_test.root_module.addImport("lexic", lexic_module);
|
|
|
|
file_unit_test.root_module.addImport("syntax", syntax_module);
|
2024-12-21 11:11:16 +00:00
|
|
|
file_unit_test.root_module.addImport("errors", error_module);
|
2024-12-06 02:02:09 +00:00
|
|
|
|
2024-11-16 12:16:10 +00:00
|
|
|
var test_artifact = b.addRunArtifact(file_unit_test);
|
|
|
|
test_step.dependOn(&test_artifact.step);
|
|
|
|
}
|
2024-11-16 01:00:15 +00:00
|
|
|
}
|