feat(build):添加UPX压缩支持以减小可执行文件体积

📝 docs:更新README文档,添加Makefile使用说明和UPX压缩说明
🔧 chore:添加Makefile简化构建流程,支持自动UPX压缩
🔧 chore:添加cabal.project.local配置文件优化构建
⬆️ chore:升级项目版本至0.3.0.2
🔧 chore:优化GHC编译选项,启用优化和链接器优化
This commit is contained in:
2026-02-04 17:54:09 +08:00
parent 83d6d79bc4
commit e4b3cebf2b
6 changed files with 115 additions and 3 deletions

View File

@@ -58,6 +58,34 @@ jobs:
cabal update
cabal build --enable-executable-stripping --disable-debug-info -j2
# 安装 UPX
- name: Install UPX
shell: bash
run: |
if [ "$RUNNER_OS" == "Linux" ]; then
wget https://github.com/upx/upx/releases/download/v5.1.0/upx-5.1.0-amd64_linux.tar.xz
tar -xf upx-5.1.0-amd64_linux.tar.xz
sudo mv upx-5.1.0-amd64_linux/upx /usr/local/bin/
rm -rf upx-5.1.0-amd64_linux*
elif [ "$RUNNER_OS" == "macOS" ]; then
wget https://github.com/upx/upx/releases/download/v5.1.0/upx-5.1.0-arm64_macos.tar.xz
tar -xf upx-5.1.0-arm64_macos.tar.xz
sudo mv upx-5.1.0-arm64_macos/upx /usr/local/bin/
rm -rf upx-5.1.0-arm64_macos*
elif [ "$RUNNER_OS" == "Windows" ]; then
curl -L -o upx.zip https://github.com/upx/upx/releases/download/v5.1.0/upx-5.1.0-win64.zip
unzip -o upx.zip
echo "$PWD/upx-5.1.0-win64" >> $GITHUB_PATH
rm upx.zip
fi
# 使用 UPX 压缩可执行文件
- name: Compress with UPX
shell: bash
run: |
EXE_PATH=$(cabal list-bin quickjump)
upx --best --lzma "$EXE_PATH"
# 提取可执行文件路径
- name: Find Executable
id: exe

40
Makefile Normal file
View File

@@ -0,0 +1,40 @@
.PHONY: all build compress install clean help
all: build compress
build:
cabal build --enable-executable-stripping --disable-debug-info
compress:
@echo "Compressing executable with UPX..."
@EXE_PATH=$$(cabal list-bin quickjump); \
if [ -f "$$EXE_PATH" ]; then \
if command -v upx >/dev/null 2>&1; then \
upx --best --lzma "$$EXE_PATH"; \
echo "Compression complete: $$EXE_PATH"; \
else \
echo "UPX not found. Installing via npx..."; \
npx -y @upx/upx@latest --best --lzma "$$EXE_PATH"; \
echo "Compression complete: $$EXE_PATH"; \
fi \
else \
echo "Error: Executable not found. Please run 'make build' first."; \
exit 1; \
fi
install:
cabal install
clean:
cabal clean
help:
@echo "QuickJump Makefile"
@echo ""
@echo "Available targets:"
@echo " all - Build and compress the executable (default)"
@echo " build - Build the executable with cabal"
@echo " compress - Compress the executable with UPX (uses npx if UPX not installed)"
@echo " install - Install the executable with cabal"
@echo " clean - Clean build artifacts"
@echo " help - Show this help message"

View File

@@ -29,6 +29,42 @@ cabal build
cabal install
```
### 使用 Makefile
项目提供了 Makefile 来简化构建和压缩过程:
```bash
git clone https://git.lyz.one/sidneyzhang/quickjump.git
cd quickjump
# 构建并压缩(推荐)
make
# 或者分步执行
make build # 仅构建
make compress # 压缩可执行文件
make install # 安装
```
### 关于 UPX 压缩
Makefile 的 `compress` 目标会使用 UPXUltimate Packer for eXecutables来压缩可执行文件显著减小文件体积
- 如果系统已安装 UPX直接使用本地 UPX 进行压缩
- 如果系统未安装 UPX会自动使用 `npx` 下载并运行最新版本的 UPX
UPX 压缩参数:
- `--best`:使用最佳压缩级别
- `--lzma`:使用 LZMA 算法(压缩率更高)
**注意**:使用 `npx` 运行 UPX 需要 Node.js 和 npm 环境。如果不想使用 UPX 压缩,可以直接运行 `make build``cabal build`
查看所有可用的 Makefile 目标:
```bash
make help
```
## 配置 Shell 集成
### Linux/macOS (Bash/Zsh)

View File

@@ -35,7 +35,7 @@ quietOption = switch
-- | 版本选项
versionOption :: Parser (a -> a)
versionOption = infoOption "quickjump 0.3.0.1"
versionOption = infoOption "quickjump 0.3.0.2"
( long "version"
<> short 'v'
<> help "Show version information" )

3
cabal.project.local Normal file
View File

@@ -0,0 +1,3 @@
ignore-project: False
split-sections: True
optimization: True

View File

@@ -20,7 +20,7 @@ name: quickjump
-- PVP summary: +-+------- breaking API changes
-- | | +----- non-breaking API additions
-- | | | +--- code changes with no API change
version: 0.3.0.1
version: 0.3.0.2
-- A short (one-line) description of the package.
synopsis: Directory Jump and Quick Directory Open
@@ -55,7 +55,12 @@ extra-doc-files: CHANGELOG.md
-- extra-source-files:
common warnings
ghc-options: -Wall
ghc-options:
-O1
-optl-s
-optl-Wl,--gc-sections
-optl-Wl,--strip-all
-fPIC
executable quickjump
-- Import common warning flags.