Skip to content

Commit

Permalink
add skip opt
Browse files Browse the repository at this point in the history
  • Loading branch information
jiacai2050 committed Jan 1, 2025
1 parent 22b4342 commit 27da99c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 76 deletions.
13 changes: 8 additions & 5 deletions .github/build-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
60 changes: 0 additions & 60 deletions .github/workflows/binary.yml

This file was deleted.

33 changes: 27 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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*"

Expand All @@ -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
Expand All @@ -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/')
Expand Down
16 changes: 11 additions & 5 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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",
Expand All @@ -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`
Expand All @@ -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.*);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 27da99c

Please sign in to comment.