an experimental irc client
at fad1823f9dfbfc143a6d9cfd0ed4060c23e75c13 119 lines 4.0 kB view raw
1const std = @import("std"); 2const zzdoc = @import("zzdoc"); 3 4/// Must be kept in sync with git tags 5const comlink_version: std.SemanticVersion = .{ .major = 0, .minor = 1, .patch = 1 }; 6 7pub fn build(b: *std.Build) void { 8 const target = b.standardTargetOptions(.{}); 9 const optimize = b.standardOptimizeOption(.{}); 10 11 const pie = b.option(bool, "pie", "Build a Position Independent Executable"); 12 13 // manpages 14 { 15 var man_step = zzdoc.addManpageStep(b, .{ 16 .root_doc_dir = b.path("docs/"), 17 }); 18 19 const install_step = man_step.addInstallStep(.{}); 20 b.default_step.dependOn(&install_step.step); 21 } 22 23 const ziglua_dep = b.dependency("ziglua", .{ 24 .target = target, 25 .optimize = optimize, 26 .lang = .lua54, 27 }); 28 29 const tls_dep = b.dependency("tls", .{ 30 .target = target, 31 .optimize = optimize, 32 }); 33 34 const vaxis_dep = b.dependency("vaxis", .{ 35 .target = target, 36 .optimize = optimize, 37 }); 38 39 const zeit_dep = b.dependency("zeit", .{ 40 .target = target, 41 .optimize = optimize, 42 }); 43 44 const exe = b.addExecutable(.{ 45 .name = "comlink", 46 .root_source_file = b.path("src/main.zig"), 47 .target = target, 48 .optimize = optimize, 49 }); 50 exe.pie = pie; 51 52 const opts = b.addOptions(); 53 const version_string = version(b) catch |err| { 54 std.debug.print("{}", .{err}); 55 @compileError("couldn't get version"); 56 }; 57 opts.addOption([]const u8, "version", version_string); 58 59 exe.root_module.addOptions("build_options", opts); 60 exe.root_module.addImport("tls", tls_dep.module("tls")); 61 exe.root_module.addImport("ziglua", ziglua_dep.module("ziglua")); 62 exe.root_module.addImport("vaxis", vaxis_dep.module("vaxis")); 63 exe.root_module.addImport("zeit", zeit_dep.module("zeit")); 64 65 b.installArtifact(exe); 66 b.installFile("docs/comlink.lua", "share/comlink/lua/comlink.lua"); 67 b.installFile("contrib/comlink.desktop", "share/applications/comlink.desktop"); 68 69 const run_cmd = b.addRunArtifact(exe); 70 run_cmd.step.dependOn(b.getInstallStep()); 71 72 // This allows the user to pass arguments to the application in the build 73 // command itself, like this: `zig build run -- arg1 arg2 etc` 74 if (b.args) |args| { 75 run_cmd.addArgs(args); 76 } 77 const run_step = b.step("run", "Run the app"); 78 run_step.dependOn(&run_cmd.step); 79 80 const exe_unit_tests = b.addTest(.{ 81 .root_source_file = b.path("src/main.zig"), 82 .target = target, 83 .optimize = optimize, 84 }); 85 exe_unit_tests.root_module.addImport("vaxis", vaxis_dep.module("vaxis")); 86 exe_unit_tests.root_module.addImport("tls", tls_dep.module("tls")); 87 exe_unit_tests.root_module.addImport("zeit", zeit_dep.module("zeit")); 88 exe_unit_tests.root_module.addImport("ziglua", ziglua_dep.module("ziglua")); 89 90 const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests); 91 92 const test_step = b.step("test", "Run unit tests"); 93 test_step.dependOn(&run_exe_unit_tests.step); 94} 95 96fn version(b: *std.Build) ![]const u8 { 97 if (!std.process.can_spawn) { 98 std.debug.print("error: version info cannot be retrieved from git. Zig version must be provided using -Dversion-string\n", .{}); 99 std.process.exit(1); 100 } 101 const version_string = b.fmt("v{d}.{d}.{d}", .{ comlink_version.major, comlink_version.minor, comlink_version.patch }); 102 103 var code: u8 = undefined; 104 const git_describe_untrimmed = b.runAllowFail(&[_][]const u8{ 105 "git", 106 "-C", 107 b.build_root.path orelse ".", 108 "describe", 109 "--tags", 110 "--abbrev=9", 111 }, &code, .Ignore) catch { 112 return version_string; 113 }; 114 if (!std.mem.startsWith(u8, git_describe_untrimmed, version_string)) { 115 std.debug.print("error: tagged version does not match internal version\n", .{}); 116 std.process.exit(1); 117 } 118 return std.mem.trim(u8, git_describe_untrimmed, " \n\r"); 119}