From 71e0b0c879c53726734fbd68b08bca49b671a030 Mon Sep 17 00:00:00 2001 From: booniepepper Date: Sun, 15 Oct 2023 01:56:41 -0700 Subject: [PATCH] bump to 1.1.2, compile with zig 0.11.0, add aqua.yaml, update workflows and release artifact naming/layout --- .github/workflows/compile.yml | 19 +++++-- .github/workflows/release.yml | 17 +++--- .tool-versions | 2 +- README.md | 2 +- aqua.yaml | 13 +++++ build.zig | 101 ++++++++++++++++++++++++++-------- src/main.zig | 2 +- src/test.zig | 15 ++--- 8 files changed, 127 insertions(+), 44 deletions(-) create mode 100644 aqua.yaml diff --git a/.github/workflows/compile.yml b/.github/workflows/compile.yml index 2632165..2b6d24d 100644 --- a/.github/workflows/compile.yml +++ b/.github/workflows/compile.yml @@ -16,13 +16,22 @@ jobs: - name: Setup Zig uses: goto-bus-stop/setup-zig@v2.1.0 with: - version: 0.10.1 + version: 0.11.0 - name: Checkout project uses: actions/checkout@v3 - - name: Build and Test - run: ./build compile test release + - name: zig build + run: | + zig env + zig build - - name: Cross Compile - run: ./build cross-release + - name: zig build test + run: | + zig env + zig build test + + - name: zig build cross + run: | + zig env + zig build cross diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index bc23c76..f5a2b62 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -12,21 +12,24 @@ jobs: - name: Setup Zig uses: goto-bus-stop/setup-zig@v2.1.0 with: - version: 0.10.1 + version: 0.11.0 - name: Checkout project uses: actions/checkout@v3 - - name: Build and Test - run: ./build compile test release + - name: zig build test + run: | + zig env + zig build test - - name: Cross Compile - run: ./build cross-release cross-tar + - name: zig build cross -Doptimize=ReleaseSmall + run: | + zig env + zig build cross -Doptimize=ReleaseSmall - name: Upload the artifacts uses: skx/github-action-publish-binaries@master env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - args: 'target/*.tgz' - + args: 'zig-out/cross/*/findup-*.tgz' diff --git a/.tool-versions b/.tool-versions index 802c792..8294b3c 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1 +1 @@ -zig 0.10.1 +zig 0.11.0 diff --git a/README.md b/README.md index 42b9538..4bab303 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # `findup` ```text -findup 1.1.1 +findup 1.1.2 USAGE: findup FILE diff --git a/aqua.yaml b/aqua.yaml new file mode 100644 index 0000000..4bf50f2 --- /dev/null +++ b/aqua.yaml @@ -0,0 +1,13 @@ +--- +# aqua - Declarative CLI Version Manager +# https://aquaproj.github.io/ +# checksum: +# enabled: true +# require_checksum: true +# supported_envs: +# - all +registries: +- type: standard + ref: v4.65.0 # renovate: depName=aquaproj/aqua-registry +packages: +- name: ziglang/zig@0.11.0 diff --git a/build.zig b/build.zig index 02a850d..5c6451b 100644 --- a/build.zig +++ b/build.zig @@ -1,30 +1,87 @@ const std = @import("std"); -pub fn build(b: *std.build.Builder) void { - - // ----- install ------ +pub fn build(b: *std.Build) !void { const target = b.standardTargetOptions(.{}); - const mode = b.standardReleaseOptions(); - const exe = b.addExecutable("findup", "src/main.zig"); - exe.setTarget(target); - exe.setBuildMode(mode); - exe.install(); - - // ----- run ----- - - const run_cmd = exe.run(); - run_cmd.step.dependOn(b.getInstallStep()); - if (b.args) |args| { - run_cmd.addArgs(args); + const optimize = b.standardOptimizeOption(.{}); + + const name = "findup"; + + // Compile + const compile_step = b.step("findup", "Install findup executable"); + const cross_step = b.step("cross", "Generate cross-compiled executables"); + + const source = std.Build.FileSource.relative("src/main.zig"); + const exe = b.addExecutable(.{ + .name = name, + .root_source_file = source, + .optimize = optimize, + .target = target, + }); + const install_exe = b.addInstallArtifact(exe, .{}); + compile_step.dependOn(&install_exe.step); + b.default_step.dependOn(compile_step); + + // Cross-compile + inline for (TRIPLES) |TRIPLE| { + const cross = b.addExecutable(.{ + .name = name, + .root_source_file = source, + .optimize = optimize, + .target = try std.zig.CrossTarget.parse(.{ .arch_os_abi = TRIPLE }), + }); + + const cross_install = b.addInstallArtifact(cross, .{ + .dest_dir = .{ .override = .{ .custom = "cross/" ++ TRIPLE } }, + }); + + const cross_tar = b.addSystemCommand(&.{ "sh", "-c", "tar -czvf findup-" ++ TRIPLE ++ ".tgz findup" }); + cross_tar.cwd = "./zig-out/cross/" ++ TRIPLE; + + cross_tar.step.dependOn(&cross_install.step); + cross_step.dependOn(&cross_tar.step); } - const run_step = b.step("run", "Run the app"); - run_step.dependOn(&run_cmd.step); + // Tests + const testSource = std.Build.FileSource.relative("src/test.zig"); + + const test_exe = b.addTest(.{ + .root_source_file = testSource, + .optimize = optimize, + .target = target, + }); - // ----- test ----- + const test_run = b.addRunArtifact(test_exe); - const test_cmd = b.addTest("src/test.zig"); - test_cmd.step.dependOn(b.getInstallStep()); - const test_step = b.step("test", "Run test against the built CLI"); - test_step.dependOn(&test_cmd.step); + const test_step = b.step("test", "Run unit tests"); + test_step.dependOn(compile_step); + test_step.dependOn(&test_run.step); + + b.default_step.dependOn(test_step); } + +const TRIPLES = .{ + "aarch64-linux-gnu", + "aarch64-linux-musleabi", + "aarch64-macos-none", + "arm-linux-musleabi", + "arm-linux-musleabihf", + "mips-linux-gnu", + "mips-linux-musl", + "mips64-linux-gnuabi64", + "mips64-linux-musl", + "mips64el-linux-gnuabi64", + "mips64el-linux-musl", + "mipsel-linux-gnu", + "mipsel-linux-musl", + "powerpc-linux-gnu", + "powerpc-linux-musl", + "powerpc64le-linux-gnu", + "powerpc64le-linux-musl", + "riscv64-linux-gnu", + "riscv64-linux-musl", + "x86_64-linux-gnu", + "x86_64-linux-musl", + "x86_64-macos-none", + "x86-linux-gnu", + "x86-linux-musl", +}; diff --git a/src/main.zig b/src/main.zig index c0d1fe5..b3521aa 100644 --- a/src/main.zig +++ b/src/main.zig @@ -9,7 +9,7 @@ const AccessError = std.os.AccessError; const Findup = struct { program: [:0]const u8, target: [:0]const u8, cwd: Dir, printHelp: bool, printVersion: bool }; const FindupError = error{NoFileSpecified}; -const VERSION = "findup 1.1.1\n"; +const VERSION = "findup 1.1.2\n"; const USAGE = \\USAGE: diff --git a/src/test.zig b/src/test.zig index 42dcda6..be82c03 100644 --- a/src/test.zig +++ b/src/test.zig @@ -13,7 +13,7 @@ test "findup --version" { defer allocator.free(result.stdout); defer allocator.free(result.stderr); - try testing.expectEqualStrings("findup 1.1.1\n", result.stdout); + try testing.expectEqualStrings("findup 1.1.2\n", result.stdout); } test "findup build.zig" { @@ -23,10 +23,12 @@ test "findup build.zig" { defer allocator.free(result.stdout); defer allocator.free(result.stderr); + var buf: [256]u8 = undefined; + const cwd = try std.os.getcwd(&buf); + // Test that some non-empty string is returned. - const zero: usize = 0; - const is_equal = testing.expectEqual(zero, result.stdout.len); - try testing.expectError(error.TestExpectedEqual, is_equal); + try testing.expectStringStartsWith(std.mem.trimRight(u8, cwd, &std.ascii.whitespace), std.mem.trimRight(u8, result.stdout, &std.ascii.whitespace)); + try testing.expectEqualStrings("", result.stderr); } test "findup SOME_FILE_THAT_I_SUPPOSE_DOES_NOT_EXIST" { @@ -36,8 +38,7 @@ test "findup SOME_FILE_THAT_I_SUPPOSE_DOES_NOT_EXIST" { defer allocator.free(result.stdout); defer allocator.free(result.stderr); - const zero: usize = 0; try testing.expectEqual(ChildProcess.Term{ .Exited = 1 }, result.term); - try testing.expectEqual(zero, result.stdout.len); - try testing.expectEqual(zero, result.stderr.len); + try testing.expectEqualStrings("", result.stdout); + try testing.expectEqualStrings("", result.stderr); }