summaryrefslogtreecommitdiff
path: root/build.zig
diff options
context:
space:
mode:
authorGravatar Uko Kokņevičs2023-04-02 22:28:09 +0300
committerGravatar Uko Kokņevičs2023-04-02 22:30:53 +0300
commit06a9ac758c3c201625cbc17d3ccc0f8eea19cdf5 (patch)
tree1d8261677108400367497a1adec01135e18ad6f5 /build.zig
parentActually use my zig-curl instead of zelda. (diff)
downloadzup-06a9ac758c3c201625cbc17d3ccc0f8eea19cdf5.tar.gz
zup-06a9ac758c3c201625cbc17d3ccc0f8eea19cdf5.tar.xz
zup-06a9ac758c3c201625cbc17d3ccc0f8eea19cdf5.zip
Update to latest zig
Diffstat (limited to 'build.zig')
-rw-r--r--build.zig51
1 files changed, 33 insertions, 18 deletions
diff --git a/build.zig b/build.zig
index 934e826..8a080d1 100644
--- a/build.zig
+++ b/build.zig
@@ -1,25 +1,38 @@
1const builtin = @import("builtin"); 1const builtin = @import("builtin");
2const std = @import("std"); 2const std = @import("std");
3 3
4const Builder = std.build.Builder; 4const Build = std.Build;
5const SemanticVersion = std.SemanticVersion; 5const SemanticVersion = std.SemanticVersion;
6const Version = std.builtin.Version;
6 7
7pub fn build(b: *Builder) void { 8pub fn build(b: *Build) void {
8 const target = b.standardTargetOptions(.{}); 9 const target = b.standardTargetOptions(.{});
9 const mode = b.standardReleaseOptions(); 10 const optimize = b.standardOptimizeOption(.{});
11
12 const semanticVersion = getSemanticVersion(b);
13 const version = Version{
14 .major = @intCast(u32, semanticVersion.major),
15 .minor = @intCast(u32, semanticVersion.minor),
16 .patch = @intCast(u32, semanticVersion.patch),
17 };
10 18
11 const config = b.addOptions(); 19 const config = b.addOptions();
12 config.addOption(SemanticVersion, "version", getVersion(b)); 20 config.addOption(SemanticVersion, "version", semanticVersion);
13 21
14 const exe = b.addExecutable("zup", "src/main.zig"); 22 const exe = b.addExecutable(.{
15 exe.setTarget(target); 23 .name = "zup",
16 exe.setBuildMode(mode); 24 .version = version,
25 .root_source_file = .{ .path = "src/main.zig" },
26 .target = target,
27 .optimize = optimize,
28 });
17 exe.addOptions("zup-config", config); 29 exe.addOptions("zup-config", config);
18 exe.addPackagePath("clap", "libs/clap/clap.zig"); 30 exe.addModule("clap", b.createModule(.{ .source_file = .{ .path = "libs/clap/clap.zig" }}));
19 exe.addPackagePath("curl", "libs/curl/curl.zig"); 31 exe.addModule("curl", b.createModule(.{ .source_file = .{ .path = "libs/curl/curl.zig" }}));
20 exe.addPackagePath("libarchive", "libs/libarchive/libarchive.zig"); 32 exe.addModule("libarchive", b.createModule(.{
21 exe.addPackagePath("xdg", "libs/xdg/xdg.zig"); 33 .source_file = .{ .path = "libs/libarchive/libarchive.zig" },
22 exe.addPackagePath("zup", "src/main.zig"); 34 }));
35 exe.addModule("xdg", b.createModule(.{ .source_file = .{ .path = "libs/xdg/xdg.zig" }}));
23 exe.linkLibC(); 36 exe.linkLibC();
24 exe.linkSystemLibrary("libarchive"); 37 exe.linkSystemLibrary("libarchive");
25 exe.linkSystemLibrary("libcurl"); 38 exe.linkSystemLibrary("libcurl");
@@ -34,9 +47,11 @@ pub fn build(b: *Builder) void {
34 const run_step = b.step("run", "Run the app"); 47 const run_step = b.step("run", "Run the app");
35 run_step.dependOn(&run_cmd.step); 48 run_step.dependOn(&run_cmd.step);
36 49
37 const exe_tests = b.addTest("src/main.zig"); 50 const exe_tests = b.addTest(.{
38 exe_tests.setTarget(target); 51 .root_source_file = .{ .path = "src/main.zig" },
39 exe_tests.setBuildMode(mode); 52 .target = target,
53 .optimize = optimize,
54 });
40 55
41 const test_step = b.step("test", "Run unit tests"); 56 const test_step = b.step("test", "Run unit tests");
42 test_step.dependOn(&exe_tests.step); 57 test_step.dependOn(&exe_tests.step);
@@ -44,15 +59,15 @@ pub fn build(b: *Builder) void {
44 59
45const default_version = SemanticVersion.parse("0.2.1") catch unreachable; 60const default_version = SemanticVersion.parse("0.2.1") catch unreachable;
46 61
47fn getVersion(b: *Builder) SemanticVersion { 62fn getSemanticVersion(b: *Build) SemanticVersion {
48 var out_code: u8 = undefined; 63 var out_code: u8 = undefined;
49 const untrimmed = b.execAllowFail( 64 const untrimmed = b.execAllowFail(
50 &.{ "git", "-C", b.build_root, "describe", "--tags" }, 65 &.{ "git", "-C", b.build_root.path.?, "describe", "--tags" },
51 &out_code, 66 &out_code,
52 .Ignore, 67 .Ignore,
53 ) catch return default_version; 68 ) catch return default_version;
54 69
55 const git_desc = std.mem.trim(u8, untrimmed, &std.ascii.spaces); 70 const git_desc = std.mem.trim(u8, untrimmed, &std.ascii.whitespace);
56 // Turn something like 0.0.1-1-g85f815d into 0.0.1-1+g85f815d 71 // Turn something like 0.0.1-1-g85f815d into 0.0.1-1+g85f815d
57 const ver_str = switch (std.mem.count(u8, git_desc, "-")) { 72 const ver_str = switch (std.mem.count(u8, git_desc, "-")) {
58 0 => git_desc, 73 0 => git_desc,