Skip to content

Commit 0f35831

Browse files
committed
feature: Makefile build approach + compress binary with UPX
1 parent a560454 commit 0f35831

5 files changed

Lines changed: 104 additions & 2 deletions

File tree

.github/workflows/release.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,18 @@ jobs:
2727
- target: x86_64-unknown-linux-gnu
2828
runner: ubuntu-latest
2929
asset_name: dstimer-linux-x86_64
30+
use_upx: true
3031

3132
- target: aarch64-unknown-linux-gnu
3233
runner: ubuntu-latest
3334
asset_name: dstimer-linux-aarch64
3435
use_cross: true
36+
use_upx: true
3537

3638
- target: x86_64-pc-windows-msvc
3739
runner: windows-latest
3840
asset_name: dstimer-windows-x86_64.exe
41+
use_upx: true
3942

4043
steps:
4144
- uses: actions/checkout@v4
@@ -61,6 +64,18 @@ jobs:
6164
if: matrix.use_cross != true
6265
run: cargo build --release --target ${{ matrix.target }}
6366

67+
- name: Compress binary with UPX (Linux)
68+
if: matrix.use_upx == true && matrix.runner == 'ubuntu-latest'
69+
run: |
70+
sudo apt-get install -y upx-ucl
71+
upx --best --lzma target/${{ matrix.target }}/release/dstimer
72+
73+
- name: Compress binary with UPX (Windows)
74+
if: matrix.use_upx == true && matrix.runner == 'windows-latest'
75+
run: |
76+
choco install upx -y
77+
upx --best --lzma target/${{ matrix.target }}/release/dstimer.exe
78+
6479
- name: Rename binary (Unix)
6580
if: matrix.runner != 'windows-latest'
6681
run: cp target/${{ matrix.target }}/release/dstimer ${{ matrix.asset_name }}
@@ -90,3 +105,49 @@ jobs:
90105
with:
91106
files: artifacts/*
92107
generate_release_notes: true
108+
109+
# TODO: Enable after first manual submission to microsoft/winget-pkgs is accepted
110+
# publish-winget:
111+
# name: Publish to WinGet
112+
# needs: release
113+
# runs-on: windows-latest
114+
# steps:
115+
# - name: Submit to WinGet
116+
# uses: vedantmgoyal9/winget-releaser@v2
117+
# with:
118+
# identifier: madLinux7.dstimer
119+
# installers-regex: 'dstimer-windows-x86_64\.exe$'
120+
# token: ${{ secrets.WINGET_TOKEN }}
121+
122+
# TODO: Enable when ready for Scoop distribution
123+
# update-scoop:
124+
# name: Update Scoop manifest
125+
# needs: release
126+
# runs-on: ubuntu-latest
127+
# steps:
128+
# - uses: actions/checkout@v4
129+
#
130+
# - name: Download Windows artifact
131+
# uses: actions/download-artifact@v4
132+
# with:
133+
# name: dstimer-windows-x86_64.exe
134+
# path: artifacts
135+
#
136+
# - name: Update Scoop manifest
137+
# run: |
138+
# VERSION="${GITHUB_REF_NAME#v}"
139+
# SHA256=$(sha256sum artifacts/dstimer-windows-x86_64.exe | cut -d' ' -f1)
140+
# cd pkg/scoop
141+
# jq --arg v "$VERSION" --arg h "$SHA256" \
142+
# '.version = $v |
143+
# .architecture."64bit".url = "https://github.com/madLinux7/dead-simple-cli-timer/releases/download/v\($v)/dstimer-windows-x86_64.exe#/dstimer.exe" |
144+
# .architecture."64bit".hash = $h' \
145+
# dstimer.json > dstimer.json.tmp && mv dstimer.json.tmp dstimer.json
146+
#
147+
# - name: Commit updated manifest
148+
# run: |
149+
# git config user.name "github-actions[bot]"
150+
# git config user.email "github-actions[bot]@users.noreply.github.com"
151+
# git add pkg/scoop/dstimer.json
152+
# git diff --cached --quiet || git commit -m "chore: update Scoop manifest to ${GITHUB_REF_NAME}"
153+
# git push

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/target/
2+
/pkg/
23
**/*.rs.bk
34
*.pdb
45
.idea/

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "dstimer"
3-
version = "1.0.1"
3+
version = "1.0.2"
44
edition = "2021"
55
description = "A dead-simple, cross-platform CLI countdown timer with color-changing progress bar and optional audio playback"
66
license = "MIT"

Makefile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
VERSION := $(shell grep -m1 '^version' Cargo.toml | sed 's/.*"\(.*\)".*/\1/')
2+
BIN := dstimer
3+
TARGET := target/release/$(BIN)
4+
5+
.PHONY: build release clean
6+
7+
## Default: build release binary + compress with UPX
8+
release: build upx
9+
10+
## Build optimized release binary
11+
build:
12+
cargo build --release
13+
14+
## Compress binary with UPX (skip on macOS)
15+
upx: build
16+
ifeq ($(shell uname),Darwin)
17+
@echo "Skipping UPX on macOS (breaks code signing)"
18+
else
19+
@command -v upx >/dev/null 2>&1 || { echo "Error: upx not found. Install it first."; exit 1; }
20+
upx --best --lzma $(TARGET)
21+
endif
22+
23+
## Build without UPX
24+
build-only: build
25+
26+
## Show binary size before/after
27+
size: build
28+
@echo "Before UPX:"
29+
@ls -lh $(TARGET) | awk '{print $$5, $$9}'
30+
@$(MAKE) upx
31+
@echo "After UPX:"
32+
@ls -lh $(TARGET) | awk '{print $$5, $$9}'
33+
34+
## Clean build artifacts
35+
clean:
36+
cargo clean
37+
38+
## Print version from Cargo.toml
39+
version:
40+
@echo $(VERSION)

0 commit comments

Comments
 (0)