const std = @import("std"); const AppBundle = @import("src/zilch/AppBundle.zig"); pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); const sqlite_c = b.addTranslateC(.{ .root_source_file = b.path("src/db/sqlite.h"), .target = target, .optimize = optimize, }); sqlite_c.linkSystemLibrary("sqlite3", .{}); const db_mod = b.addModule("db", .{ .root_source_file = b.path("src/db/root.zig"), .target = target, }); db_mod.addImport("sqlite", sqlite_c.createModule()); const api_mod = b.addModule("api", .{ .root_source_file = b.path("src/api/root.zig"), .target = target, }); const http_mod = b.addModule("http", .{ .root_source_file = b.path("src/http/root.zig"), .target = target, }); api_mod.addImport("http", http_mod); const zilch_mod = b.addModule("zilch", .{ .root_source_file = b.path("src/zilch/root.zig"), .target = target, }); const site: AppBundle = .init(b, .{ .root_source_file = b.path("src/app/root.zig"), .target = target, }, zilch_mod); const exe = b.addExecutable(.{ .name = "memora", .root_module = b.createModule(.{ .root_source_file = b.path("src/main.zig"), .target = target, .optimize = optimize, .imports = &.{ .{ .name = "db", .module = db_mod }, .{ .name = "api", .module = api_mod }, .{ .name = "http", .module = http_mod }, .{ .name = "site", .module = site.mod }, }, }), }); exe.root_module.addAnonymousImport("wasm", .{ .root_source_file = site.getEmittedWasm(), }); b.installArtifact(exe); const run_step = b.step("run", "Run the app"); const run_cmd = b.addRunArtifact(exe); run_step.dependOn(&run_cmd.step); run_cmd.step.dependOn(b.getInstallStep()); if (b.args) |args| { run_cmd.addArgs(args); } const db_tests = b.addTest(.{ .root_module = db_mod, }); const run_db_tests = b.addRunArtifact(db_tests); const db_test_step = b.step("test-db", "Run database tests"); db_test_step.dependOn(&run_db_tests.step); const api_tests = b.addTest(.{ .root_module = api_mod, }); const run_api_tests = b.addRunArtifact(api_tests); const api_test_step = b.step("test-api", "Run api tests"); api_test_step.dependOn(&run_api_tests.step); const http_tests = b.addTest(.{ .root_module = http_mod, }); const run_http_tests = b.addRunArtifact(http_tests); const http_test_step = b.step("test-http", "Run http tests"); http_test_step.dependOn(&run_http_tests.step); const exe_tests = b.addTest(.{ .root_module = exe.root_module, }); const run_exe_tests = b.addRunArtifact(exe_tests); const test_step = b.step("test", "Run all tests"); test_step.dependOn(&run_db_tests.step); test_step.dependOn(&run_api_tests.step); test_step.dependOn(&run_http_tests.step); test_step.dependOn(&run_exe_tests.step); const fmt_step = b.step("fmt", "Format"); const do_fmt = b.addFmt(.{ .paths = &.{"src"}, }); fmt_step.dependOn(&do_fmt.step); const check_fmt_step = b.step("check", "Check format and syntax"); const do_check_fmt = b.addFmt(.{ .paths = &.{"src"}, .check = true, }); check_fmt_step.dependOn(&do_check_fmt.step); const docs_step = b.step("docs", "Emit documentation"); const docs_install = b.addInstallDirectory(.{ .install_dir = .prefix, .install_subdir = "docs", .source_dir = exe.getEmittedDocs(), }); docs_step.dependOn(&docs_install.step); const dev_cmd = b.addSystemCommand(&.{ "watchexec", "-r", "-I", "-c", "clear", "zig build run", }); const dev_step = b.step("dev", "Run server in dev mode"); dev_step.dependOn(&dev_cmd.step); run_cmd.step.dependOn(b.getInstallStep()); }