diff --git a/.github/build-release.sh b/.github/build-release.sh index 4c04332..ff97dc2 100755 --- a/.github/build-release.sh +++ b/.github/build-release.sh @@ -29,20 +29,23 @@ targets=( export BUILD_DATE=$(date +'%Y-%m-%dT%H:%M:%S%z') export GIT_COMMIT=$(git rev-parse --short HEAD) -pandoc -f org -t markdown README.org -o README.md - for target in "${targets[@]}"; do echo "Building for ${target}..." filename=zigcli-${VERSION}-${target} dst_dir=zig-out/${filename} # 1. Build - zig build -Doptimize=ReleaseSafe -Dtarget="${target}" -p ${dst_dir} \ - -Dgit_commit=${GIT_COMMIT} -Dbuild_date=${BUILD_DATE} -Dis_ci=true + if [[ "${target}" == "x86_64" ]];then + zig build -Doptimize=ReleaseSafe -p ${dst_dir} \ + -Dgit_commit=${GIT_COMMIT} -Dbuild_date=${BUILD_DATE} + else + zig build -Dskip_zigfetch=true -Doptimize=ReleaseSafe -Dtarget="${target}" -p ${dst_dir} \ + -Dgit_commit=${GIT_COMMIT} -Dbuild_date=${BUILD_DATE} + fi # 2. Prepare files rm -f ${dst_dir}/bin/*demo - cp LICENSE README.md ${dst_dir} + cp LICENSE README.org ${dst_dir} # 3. Zip final file pushd zig-out diff --git a/.github/workflows/binary.yml b/.github/workflows/binary.yml deleted file mode 100644 index 6e28b35..0000000 --- a/.github/workflows/binary.yml +++ /dev/null @@ -1,60 +0,0 @@ -name: Build binary - -on: - workflow_dispatch: - pull_request: - paths: - - "**.zig" - - ".github/workflows/CI.yml" - - ".github/workflows/binary.yml" - push: - branches: - - main - paths: - - "**.zig" - - ".github/workflows/binary.yml" - -env: - ZIG_VERSION: 0.13.0 - -jobs: - build: - timeout-minutes: 10 - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - targets: - - "x86-windows" - - "x86_64-windows" - - "aarch64-windows" - - "x86-linux" - - "x86_64-linux" - - "arm-linux-musleabi" - - "aarch64-linux" - - "x86_64-macos" - - "aarch64-macos" - steps: - - uses: actions/checkout@v4 - with: - submodules: true - - uses: mlugg/setup-zig@v1 - with: - version: ${{ env.ZIG_VERSION }} - - name: Set Environment Variables - run: | - echo "BUILD_DATE=$(date +'%Y-%m-%dT%H:%M:%S%z')" >> $GITHUB_ENV - - name: deps - run: | - sudo apt update && sudo apt-get install -y libcurl4-openssl-dev - - name: Build - run: | - zig build -Dtarget=${{ matrix.targets }} -Doptimize=ReleaseSafe \ - -Dgit_commit=${{ github.head_ref }}-${{ github.sha }} \ - -Dbuild_date=${{ env.BUILD_DATE }} - tar -cvf zigcli.tar zig-out/bin/ - - name: Upload - uses: actions/upload-artifact@v4 - with: - name: zigcli-${{ matrix.targets }} - path: zigcli.tar diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d83d0c4..46795df 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,7 +2,17 @@ name: Release on: workflow_dispatch: + pull_request: + paths: + - "**.zig" + - ".github/workflows/CI.yml" + - ".github/workflows/release.yml" push: + branches: + - main + paths: + - "**.zig" + - ".github/workflows/release.yml" tags: - "v*" @@ -11,7 +21,11 @@ permissions: jobs: upload-assets: - runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest] + runs-on: ${{ matrix.os }} steps: - name: Checkout uses: actions/checkout@v4 @@ -22,13 +36,20 @@ jobs: run: | echo "RELEASE_VERSION=${{ github.ref_name }}" >> $GITHUB_ENV echo "OUT_DIR=/tmp/zigcli-${{ github.ref_name }}" >> $GITHUB_ENV - - name: Install - uses: pandoc/actions/setup@v1 - with: - version: 2.19 - - name: Build + - name: Build(Ubuntu) + if: matrix.os == 'ubuntu-latest' run: | bash .github/build-release.sh + - name: Build(MacOS) + if: matrix.os == 'macos-latest' + run: | + zig build -Doptimize=ReleaseSafe \ + -Dgit_commit=${GIT_COMMIT} -Dbuild_date=${BUILD_DATE} + rm -f zig-out/bin/*demo + cp LICENSE README.org zig-out + pushd zig-out + zip -r ${OUT_DIR}/zigcli-${RELEASE_VERSION}-aarch64-macos.zip . + popd - name: Release uses: softprops/action-gh-release@v2 if: startsWith(github.ref, 'refs/tags/') diff --git a/build.zig b/build.zig index aaa52a3..9fb8056 100644 --- a/build.zig +++ b/build.zig @@ -6,11 +6,11 @@ const macos_private_framework = "/Applications/Xcode.app/Contents/Developer/Plat pub fn build(b: *Build) !void { const optimize = b.standardOptimizeOption(.{}); const target = b.standardTargetOptions(.{}); - + const skip_zigfetch = b.option(bool, "skip_zigfetch", "Skip zig fetch") orelse false; var all_tests = std.ArrayList(*Build.Step).init(b.allocator); try addModules(b, target, &all_tests); - try buildBinaries(b, optimize, target, &all_tests); + try buildBinaries(b, optimize, target, &all_tests, skip_zigfetch); try buildExamples(b, optimize, target, &all_tests); const test_all_step = b.step("test", "Run all tests"); @@ -87,7 +87,7 @@ fn buildExamples( "simargs-demo", "pretty-table-demo", }) |name| { - try buildBinary(b, .{ .ex = name }, optimize, target, all_tests); + try buildBinary(b, .{ .ex = name }, optimize, target, all_tests, false); } } @@ -96,6 +96,7 @@ fn buildBinaries( optimize: std.builtin.Mode, target: std.Build.ResolvedTarget, all_tests: *std.ArrayList(*Build.Step), + skip_zigfetch: bool, ) !void { inline for (.{ "zigfetch", @@ -108,7 +109,7 @@ fn buildBinaries( "repeat", "tcp-proxy", }) |name| { - try buildBinary(b, .{ .bin = name }, optimize, target, all_tests); + try buildBinary(b, .{ .bin = name }, optimize, target, all_tests, skip_zigfetch); } // TODO: move util out of `bin` @@ -121,8 +122,9 @@ fn buildBinary( optimize: std.builtin.Mode, target: std.Build.ResolvedTarget, all_tests: *std.ArrayList(*Build.Step), + skip_zigfetch: bool, ) !void { - if (makeCompileStep(b, source, optimize, target)) |exe| { + if (makeCompileStep(b, source, optimize, target, skip_zigfetch)) |exe| { var deps = b.modules.iterator(); while (deps.next()) |dep| { exe.root_module.addImport(dep.key_ptr.*, dep.value_ptr.*); @@ -165,6 +167,7 @@ fn makeCompileStep( comptime source: Source, optimize: std.builtin.Mode, target: std.Build.ResolvedTarget, + skip_zigfetch: bool, ) ?*Build.Step.Compile { const name = comptime source.name(); const path = comptime source.path(); @@ -194,6 +197,9 @@ fn makeCompileStep( } else if (std.mem.eql(u8, name, "tcp-proxy")) { exe.linkLibC(); } else if (std.mem.eql(u8, name, "zigfetch")) { + if (skip_zigfetch) { + return null; + } const host_os = @import("builtin").os.tag; const build_os = target.result.os.tag; if (host_os != build_os) { // don't support cross compile