this repo has no description
56
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 98 lines 2.9 kB view raw
1const std = @import("std"); 2const zzdoc = @import("zzdoc"); 3 4/// Must be kept in sync with git tags 5const version: std.SemanticVersion = .{ .major = 1, .minor = 0, .patch = 0 }; 6 7pub fn build(b: *std.Build) void { 8 const target = b.standardTargetOptions(.{}); 9 const optimize = b.standardOptimizeOption(.{}); 10 11 // manpages 12 { 13 var man_step = zzdoc.addManpageStep(b, .{ 14 .root_doc_dir = b.path("docs/"), 15 }); 16 17 const install_step = man_step.addInstallStep(.{}); 18 b.default_step.dependOn(&install_step.step); 19 } 20 21 const exe_mod = b.createModule(.{ 22 .root_source_file = b.path("src/main.zig"), 23 .target = target, 24 .optimize = optimize, 25 }); 26 27 const io_dep = b.dependency("ourio", .{ .optimize = optimize, .target = target }); 28 const io_mod = io_dep.module("ourio"); 29 exe_mod.addImport("ourio", io_mod); 30 31 const zeit_dep = b.dependency("zeit", .{ .optimize = optimize, .target = target }); 32 const zeit_mod = zeit_dep.module("zeit"); 33 exe_mod.addImport("zeit", zeit_mod); 34 35 const opts = b.addOptions(); 36 const version_string = genVersion(b) catch |err| { 37 std.debug.print("{}", .{err}); 38 @compileError("couldn't get version"); 39 }; 40 opts.addOption([]const u8, "version", version_string); 41 42 exe_mod.addOptions("build_options", opts); 43 44 const exe = b.addExecutable(.{ 45 .name = "lsr", 46 .root_module = exe_mod, 47 }); 48 exe.linkLibC(); 49 50 b.installArtifact(exe); 51 52 const run_cmd = b.addRunArtifact(exe); 53 54 run_cmd.step.dependOn(b.getInstallStep()); 55 56 if (b.args) |args| { 57 run_cmd.addArgs(args); 58 } 59 60 const run_step = b.step("run", "Run the app"); 61 run_step.dependOn(&run_cmd.step); 62 63 const exe_unit_tests = b.addTest(.{ 64 .root_module = exe_mod, 65 }); 66 67 const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests); 68 69 const test_step = b.step("test", "Run unit tests"); 70 test_step.dependOn(&run_exe_unit_tests.step); 71} 72 73fn genVersion(b: *std.Build) ![]const u8 { 74 if (!std.process.can_spawn) { 75 std.debug.print("error: version info cannot be retrieved from git. Zig version must be provided using -Dversion-string\n", .{}); 76 std.process.exit(1); 77 } 78 const version_string = b.fmt("v{d}.{d}.{d}", .{ version.major, version.minor, version.patch }); 79 80 var code: u8 = undefined; 81 const git_describe_untrimmed = b.runAllowFail(&[_][]const u8{ 82 "git", 83 "-C", 84 b.build_root.path orelse ".", 85 "describe", 86 "--match", 87 "*.*.*", 88 "--tags", 89 "--abbrev=9", 90 }, &code, .Ignore) catch { 91 return version_string; 92 }; 93 if (!std.mem.startsWith(u8, git_describe_untrimmed, version_string)) { 94 std.debug.print("error: tagged version does not match internal version\n", .{}); 95 std.process.exit(1); 96 } 97 return std.mem.trim(u8, git_describe_untrimmed, " \n\r"); 98}