2026-01-17 18:32:29 +05:30
|
|
|
const std = @import("std");
|
2026-01-28 17:01:28 +05:30
|
|
|
pub const compile_tpls = @import("src/compile_tpls.zig");
|
2026-01-17 18:32:29 +05:30
|
|
|
|
|
|
|
|
pub fn build(b: *std.Build) void {
|
|
|
|
|
const target = b.standardTargetOptions(.{});
|
|
|
|
|
const optimize = b.standardOptimizeOption(.{});
|
2026-01-25 15:23:57 +05:30
|
|
|
|
2026-01-28 17:01:28 +05:30
|
|
|
// Main pugz module
|
2026-01-17 18:32:29 +05:30
|
|
|
const mod = b.addModule("pugz", .{
|
|
|
|
|
.root_source_file = b.path("src/root.zig"),
|
|
|
|
|
.target = target,
|
2026-01-22 11:08:52 +05:30
|
|
|
.optimize = optimize,
|
2026-01-17 18:32:29 +05:30
|
|
|
});
|
|
|
|
|
|
2026-01-28 17:01:28 +05:30
|
|
|
// ============================================================================
|
|
|
|
|
// CLI Tool - Pug Template Compiler
|
|
|
|
|
// ============================================================================
|
|
|
|
|
const cli_exe = b.addExecutable(.{
|
|
|
|
|
.name = "pug-compile",
|
|
|
|
|
.root_module = b.createModule(.{
|
|
|
|
|
.root_source_file = b.path("src/cli/main.zig"),
|
|
|
|
|
.target = target,
|
|
|
|
|
.optimize = optimize,
|
|
|
|
|
.imports = &.{
|
|
|
|
|
.{ .name = "pugz", .module = mod },
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
});
|
|
|
|
|
b.installArtifact(cli_exe);
|
|
|
|
|
|
|
|
|
|
// CLI run step for manual testing
|
|
|
|
|
const run_cli = b.addRunArtifact(cli_exe);
|
|
|
|
|
if (b.args) |args| {
|
|
|
|
|
run_cli.addArgs(args);
|
|
|
|
|
}
|
|
|
|
|
const cli_step = b.step("cli", "Run the pug-compile CLI tool");
|
|
|
|
|
cli_step.dependOn(&run_cli.step);
|
|
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
// Tests
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
|
|
// Module tests (from root.zig)
|
2026-01-17 18:32:29 +05:30
|
|
|
const mod_tests = b.addTest(.{
|
|
|
|
|
.root_module = mod,
|
|
|
|
|
});
|
|
|
|
|
const run_mod_tests = b.addRunArtifact(mod_tests);
|
|
|
|
|
|
2026-01-28 17:01:28 +05:30
|
|
|
// Source file unit tests
|
2026-01-25 15:23:57 +05:30
|
|
|
const source_files_with_tests = [_][]const u8{
|
|
|
|
|
"src/lexer.zig",
|
|
|
|
|
"src/parser.zig",
|
|
|
|
|
"src/runtime.zig",
|
|
|
|
|
"src/template.zig",
|
|
|
|
|
"src/codegen.zig",
|
|
|
|
|
"src/strip_comments.zig",
|
|
|
|
|
"src/linker.zig",
|
|
|
|
|
"src/load.zig",
|
|
|
|
|
"src/error.zig",
|
|
|
|
|
"src/pug.zig",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var source_test_steps: [source_files_with_tests.len]*std.Build.Step.Run = undefined;
|
|
|
|
|
inline for (source_files_with_tests, 0..) |file, i| {
|
|
|
|
|
const file_tests = b.addTest(.{
|
|
|
|
|
.root_module = b.createModule(.{
|
|
|
|
|
.root_source_file = b.path(file),
|
|
|
|
|
.target = target,
|
|
|
|
|
.optimize = optimize,
|
|
|
|
|
}),
|
|
|
|
|
});
|
|
|
|
|
source_test_steps[i] = b.addRunArtifact(file_tests);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-28 17:01:28 +05:30
|
|
|
// Integration tests
|
|
|
|
|
const test_all = b.addTest(.{
|
2026-01-17 18:32:29 +05:30
|
|
|
.root_module = b.createModule(.{
|
2026-01-28 17:01:28 +05:30
|
|
|
.root_source_file = b.path("src/tests/root.zig"),
|
2026-01-17 18:32:29 +05:30
|
|
|
.target = target,
|
|
|
|
|
.optimize = optimize,
|
|
|
|
|
.imports = &.{
|
|
|
|
|
.{ .name = "pugz", .module = mod },
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
});
|
2026-01-28 17:01:28 +05:30
|
|
|
const run_test_all = b.addRunArtifact(test_all);
|
2026-01-17 18:32:29 +05:30
|
|
|
|
2026-01-28 17:01:28 +05:30
|
|
|
// Test steps
|
2026-01-17 18:32:29 +05:30
|
|
|
const test_step = b.step("test", "Run all tests");
|
|
|
|
|
test_step.dependOn(&run_mod_tests.step);
|
2026-01-28 17:01:28 +05:30
|
|
|
test_step.dependOn(&run_test_all.step);
|
2026-01-25 15:23:57 +05:30
|
|
|
for (&source_test_steps) |step| {
|
|
|
|
|
test_step.dependOn(&step.step);
|
|
|
|
|
}
|
2026-01-17 18:32:29 +05:30
|
|
|
|
|
|
|
|
const test_unit_step = b.step("test-unit", "Run unit tests (lexer, parser, etc.)");
|
|
|
|
|
test_unit_step.dependOn(&run_mod_tests.step);
|
2026-01-25 15:23:57 +05:30
|
|
|
for (&source_test_steps) |step| {
|
|
|
|
|
test_unit_step.dependOn(&step.step);
|
|
|
|
|
}
|
2026-01-17 18:32:29 +05:30
|
|
|
|
2026-01-28 17:01:28 +05:30
|
|
|
const test_integration_step = b.step("test-integration", "Run integration tests");
|
|
|
|
|
test_integration_step.dependOn(&run_test_all.step);
|
|
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
// Benchmarks
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
|
|
// Create module for compiled benchmark templates
|
|
|
|
|
const bench_compiled_mod = b.createModule(.{
|
|
|
|
|
.root_source_file = b.path("benchmarks/compiled/root.zig"),
|
|
|
|
|
.target = target,
|
|
|
|
|
.optimize = .ReleaseFast,
|
|
|
|
|
});
|
2026-01-24 14:31:24 +05:30
|
|
|
|
2026-01-24 23:53:19 +05:30
|
|
|
const bench_exe = b.addExecutable(.{
|
|
|
|
|
.name = "bench",
|
2026-01-17 23:59:22 +05:30
|
|
|
.root_module = b.createModule(.{
|
2026-01-28 17:01:28 +05:30
|
|
|
.root_source_file = b.path("src/tests/benchmarks/bench.zig"),
|
2026-01-17 23:59:22 +05:30
|
|
|
.target = target,
|
|
|
|
|
.optimize = .ReleaseFast,
|
|
|
|
|
.imports = &.{
|
2026-01-24 23:53:19 +05:30
|
|
|
.{ .name = "pugz", .module = mod },
|
2026-01-28 17:01:28 +05:30
|
|
|
.{ .name = "bench_compiled", .module = bench_compiled_mod },
|
2026-01-17 23:59:22 +05:30
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
});
|
2026-01-24 23:53:19 +05:30
|
|
|
b.installArtifact(bench_exe);
|
2026-01-17 23:59:22 +05:30
|
|
|
|
2026-01-24 23:53:19 +05:30
|
|
|
const run_bench = b.addRunArtifact(bench_exe);
|
|
|
|
|
run_bench.setCwd(b.path("."));
|
2026-01-28 17:01:28 +05:30
|
|
|
const bench_step = b.step("bench", "Run benchmarks");
|
2026-01-24 23:53:19 +05:30
|
|
|
bench_step.dependOn(&run_bench.step);
|
2026-01-25 15:23:57 +05:30
|
|
|
|
2026-01-28 17:01:28 +05:30
|
|
|
// ============================================================================
|
|
|
|
|
// Examples
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
|
|
// Example: Using compiled templates (only if generated/ exists)
|
|
|
|
|
const generated_exists = blk: {
|
|
|
|
|
var f = std.fs.cwd().openDir("generated", .{}) catch break :blk false;
|
|
|
|
|
f.close();
|
|
|
|
|
break :blk true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (generated_exists) {
|
|
|
|
|
const generated_mod = b.addModule("generated", .{
|
|
|
|
|
.root_source_file = b.path("generated/root.zig"),
|
|
|
|
|
.target = target,
|
|
|
|
|
.optimize = optimize,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const example_compiled = b.addExecutable(.{
|
|
|
|
|
.name = "example-compiled",
|
|
|
|
|
.root_module = b.createModule(.{
|
|
|
|
|
.root_source_file = b.path("examples/use_compiled_templates.zig"),
|
|
|
|
|
.target = target,
|
|
|
|
|
.optimize = optimize,
|
|
|
|
|
.imports = &.{
|
|
|
|
|
.{ .name = "generated", .module = generated_mod },
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
});
|
|
|
|
|
b.installArtifact(example_compiled);
|
|
|
|
|
|
|
|
|
|
const run_example_compiled = b.addRunArtifact(example_compiled);
|
|
|
|
|
const example_compiled_step = b.step("example-compiled", "Run compiled templates example");
|
|
|
|
|
example_compiled_step.dependOn(&run_example_compiled.step);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Example: Test includes
|
2026-01-25 15:23:57 +05:30
|
|
|
const test_includes_exe = b.addExecutable(.{
|
|
|
|
|
.name = "test-includes",
|
|
|
|
|
.root_module = b.createModule(.{
|
2026-01-28 17:01:28 +05:30
|
|
|
.root_source_file = b.path("src/tests/run/test_includes.zig"),
|
2026-01-25 15:23:57 +05:30
|
|
|
.target = target,
|
|
|
|
|
.optimize = optimize,
|
|
|
|
|
.imports = &.{
|
|
|
|
|
.{ .name = "pugz", .module = mod },
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
});
|
|
|
|
|
b.installArtifact(test_includes_exe);
|
|
|
|
|
|
|
|
|
|
const run_test_includes = b.addRunArtifact(test_includes_exe);
|
2026-01-28 17:01:28 +05:30
|
|
|
const test_includes_step = b.step("test-includes", "Run includes example");
|
2026-01-25 15:23:57 +05:30
|
|
|
test_includes_step.dependOn(&run_test_includes.step);
|
2026-01-28 17:01:28 +05:30
|
|
|
|
|
|
|
|
// Add template compile test
|
|
|
|
|
addTemplateCompileTest(b);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Public API for other build.zig files to use
|
|
|
|
|
pub fn addCompileStep(b: *std.Build, options: compile_tpls.CompileOptions) *compile_tpls.CompileStep {
|
|
|
|
|
return compile_tpls.addCompileStep(b, options);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test the compile step
|
|
|
|
|
fn addTemplateCompileTest(b: *std.Build) void {
|
|
|
|
|
const compile_step = addCompileStep(b, .{
|
|
|
|
|
.name = "compile-test-templates",
|
|
|
|
|
.source_dirs = &.{"examples/cli-templates-demo"},
|
|
|
|
|
.output_dir = "zig-out/generated-test",
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const test_compile = b.step("test-compile", "Test template compilation build step");
|
|
|
|
|
test_compile.dependOn(&compile_step.step);
|
2026-01-17 18:32:29 +05:30
|
|
|
}
|