| 1 | const std = @import("std"); |
| 2 | |
| 3 | pub fn build(b: *std.Build) void { |
| 4 | const target = b.standardTargetOptions(.{}); |
| 5 | const optimize = b.standardOptimizeOption(.{}); |
| 6 | const strip = b.option(bool, "strip", "Omit debug info (default: on unless Debug)") orelse (optimize != .debug); |
| 7 | const version = b.option([]const u8, "version", "Build version reported by /api/version") orelse "dev"; |
| 8 | |
| 9 | const options = b.addOptions(); |
| 10 | options.addOption([]const u8, "version", version); |
| 11 | |
| 12 | // SQLite is the official amalgamation, compiled here as C. |
| 13 | const sqlite_dep = b.dependency("sqlite", .{}); |
| 14 | const sqlite_h = b.addTranslateC(.{ |
| 15 | .root_source_file = sqlite_dep.path("sqlite3.h"), |
| 16 | .target = target, |
| 17 | .optimize = optimize, |
| 18 | }); |
| 19 | |
| 20 | const mod = b.createModule(.{ |
| 21 | .root_source_file = b.path("src/main.zig"), |
| 22 | .target = target, |
| 23 | .optimize = optimize, |
| 24 | .strip = strip, |
| 25 | .link_libc = true, |
| 26 | .imports = &.{ |
| 27 | .{ .name = "sqlite", .module = sqlite_h.createModule() }, |
| 28 | }, |
| 29 | }); |
| 30 | mod.addOptions("build_options", options); |
| 31 | mod.addCSourceFile(.{ |
| 32 | .file = sqlite_dep.path("sqlite3.c"), |
| 33 | .flags = &.{ |
| 34 | "-DSQLITE_DQS=0", |
| 35 | "-DSQLITE_DEFAULT_MEMSTATUS=0", |
| 36 | "-DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1", |
| 37 | "-DSQLITE_LIKE_DOESNT_MATCH_BLOBS", |
| 38 | "-DSQLITE_OMIT_DEPRECATED", |
| 39 | "-DSQLITE_OMIT_LOAD_EXTENSION", |
| 40 | "-DSQLITE_OMIT_SHARED_CACHE", |
| 41 | "-DSQLITE_USE_ALLOCA", |
| 42 | "-DSQLITE_THREADSAFE=1", |
| 43 | }, |
| 44 | }); |
| 45 | // The TodoMVC stylesheets are served byte for byte from the repo's |
| 46 | // shared/ directory, so they are embedded from there, not copied. |
| 47 | mod.addAnonymousImport("base.css", .{ .root_source_file = b.path("../../shared/base.css") }); |
| 48 | mod.addAnonymousImport("index.css", .{ .root_source_file = b.path("../../shared/index.css") }); |
| 49 | mod.addAnonymousImport("app.css", .{ .root_source_file = b.path("static/app.css") }); |
| 50 | mod.addAnonymousImport("app.js", .{ .root_source_file = b.path("static/app.js") }); |
| 51 | |
| 52 | const exe = b.addExecutable(.{ .name = "app", .root_module = mod, .linkage = .static }); |
| 53 | b.installArtifact(exe); |
| 54 | |
| 55 | const tests = b.addTest(.{ .root_module = mod }); |
| 56 | const run_tests = b.addRunArtifact(tests); |
| 57 | b.step("test", "Run unit tests").dependOn(&run_tests.step); |
| 58 | } |
| 59 | |