From 06a9ac758c3c201625cbc17d3ccc0f8eea19cdf5 Mon Sep 17 00:00:00 2001 From: Uko Kokņevičs Date: Sun, 2 Apr 2023 22:28:09 +0300 Subject: Update to latest zig --- build.zig | 51 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 18 deletions(-) (limited to 'build.zig') diff --git a/build.zig b/build.zig index 934e826..8a080d1 100644 --- a/build.zig +++ b/build.zig @@ -1,25 +1,38 @@ const builtin = @import("builtin"); const std = @import("std"); -const Builder = std.build.Builder; +const Build = std.Build; const SemanticVersion = std.SemanticVersion; +const Version = std.builtin.Version; -pub fn build(b: *Builder) void { +pub fn build(b: *Build) void { const target = b.standardTargetOptions(.{}); - const mode = b.standardReleaseOptions(); + const optimize = b.standardOptimizeOption(.{}); + + const semanticVersion = getSemanticVersion(b); + const version = Version{ + .major = @intCast(u32, semanticVersion.major), + .minor = @intCast(u32, semanticVersion.minor), + .patch = @intCast(u32, semanticVersion.patch), + }; const config = b.addOptions(); - config.addOption(SemanticVersion, "version", getVersion(b)); + config.addOption(SemanticVersion, "version", semanticVersion); - const exe = b.addExecutable("zup", "src/main.zig"); - exe.setTarget(target); - exe.setBuildMode(mode); + const exe = b.addExecutable(.{ + .name = "zup", + .version = version, + .root_source_file = .{ .path = "src/main.zig" }, + .target = target, + .optimize = optimize, + }); exe.addOptions("zup-config", config); - exe.addPackagePath("clap", "libs/clap/clap.zig"); - exe.addPackagePath("curl", "libs/curl/curl.zig"); - exe.addPackagePath("libarchive", "libs/libarchive/libarchive.zig"); - exe.addPackagePath("xdg", "libs/xdg/xdg.zig"); - exe.addPackagePath("zup", "src/main.zig"); + exe.addModule("clap", b.createModule(.{ .source_file = .{ .path = "libs/clap/clap.zig" }})); + exe.addModule("curl", b.createModule(.{ .source_file = .{ .path = "libs/curl/curl.zig" }})); + exe.addModule("libarchive", b.createModule(.{ + .source_file = .{ .path = "libs/libarchive/libarchive.zig" }, + })); + exe.addModule("xdg", b.createModule(.{ .source_file = .{ .path = "libs/xdg/xdg.zig" }})); exe.linkLibC(); exe.linkSystemLibrary("libarchive"); exe.linkSystemLibrary("libcurl"); @@ -34,9 +47,11 @@ pub fn build(b: *Builder) void { const run_step = b.step("run", "Run the app"); run_step.dependOn(&run_cmd.step); - const exe_tests = b.addTest("src/main.zig"); - exe_tests.setTarget(target); - exe_tests.setBuildMode(mode); + const exe_tests = b.addTest(.{ + .root_source_file = .{ .path = "src/main.zig" }, + .target = target, + .optimize = optimize, + }); const test_step = b.step("test", "Run unit tests"); test_step.dependOn(&exe_tests.step); @@ -44,15 +59,15 @@ pub fn build(b: *Builder) void { const default_version = SemanticVersion.parse("0.2.1") catch unreachable; -fn getVersion(b: *Builder) SemanticVersion { +fn getSemanticVersion(b: *Build) SemanticVersion { var out_code: u8 = undefined; const untrimmed = b.execAllowFail( - &.{ "git", "-C", b.build_root, "describe", "--tags" }, + &.{ "git", "-C", b.build_root.path.?, "describe", "--tags" }, &out_code, .Ignore, ) catch return default_version; - const git_desc = std.mem.trim(u8, untrimmed, &std.ascii.spaces); + const git_desc = std.mem.trim(u8, untrimmed, &std.ascii.whitespace); // Turn something like 0.0.1-1-g85f815d into 0.0.1-1+g85f815d const ver_str = switch (std.mem.count(u8, git_desc, "-")) { 0 => git_desc, -- cgit v1.2.3