From 270a68ca726699944d97d07a34c5f2c425edd1ac Mon Sep 17 00:00:00 2001 From: Mashrafi Rahman Date: Mon, 1 Jul 2024 00:17:53 +0800 Subject: [PATCH] Update Actions workflow. --- .github/workflows/cd.yml | 2 +- build.zig | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index da5c1db..ed24065 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -40,7 +40,7 @@ jobs: version: 0.13.0 - name: Build - run: zig build -DReleaseFast -Dtarget=${{ matrix.TARGET }} + run: zig build -Doptimize=ReleaseFast -Dtarget=${{ matrix.TARGET }} - name: Upload the binary uses: svenstaro/upload-release-action@v2 diff --git a/build.zig b/build.zig index bda69e6..c395ce4 100644 --- a/build.zig +++ b/build.zig @@ -3,7 +3,7 @@ const std = @import("std"); // Although this function looks imperative, note that its job is to // declaratively construct a build graph that will be executed by an external // runner. -pub fn build(b: *std.Build) void { +pub fn build(b: *std.Build) !void { // Standard target options allows the person running `zig build` to choose // what target to build for. Here we do not override the defaults, which // means any target is allowed, and the default is native. Other options @@ -21,8 +21,15 @@ pub fn build(b: *std.Build) void { .optimize = optimize, }); + // forgive the mess + const env: ?[]u8 = std.process.getEnvVarOwned(b.allocator, "RELEASE_VERSION") catch null; + defer if (env) |e| b.allocator.free(e); + + const printed: []u8 = if (env) |e| try std.fmt.allocPrint(b.allocator, "rf-{s}-{s}-{s}", .{ e, @tagName(target.result.cpu.arch), @tagName(target.result.os.tag) }) else try b.allocator.dupe(u8, "rf"); + defer b.allocator.free(printed); + const exe = b.addExecutable(.{ - .name = "rf", + .name = printed, .root_source_file = b.path("src/main.zig"), .target = target, .optimize = optimize,