From e4b3cebf2beadcbe5bcf0c98202a372674a5c606 Mon Sep 17 00:00:00 2001 From: Sidney Zhang Date: Wed, 4 Feb 2026 17:54:09 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(build)=EF=BC=9A=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0UPX=E5=8E=8B=E7=BC=A9=E6=94=AF=E6=8C=81=E4=BB=A5?= =?UTF-8?q?=E5=87=8F=E5=B0=8F=E5=8F=AF=E6=89=A7=E8=A1=8C=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=BD=93=E7=A7=AF=20=F0=9F=93=9D=20docs=EF=BC=9A=E6=9B=B4?= =?UTF-8?q?=E6=96=B0README=E6=96=87=E6=A1=A3=EF=BC=8C=E6=B7=BB=E5=8A=A0Mak?= =?UTF-8?q?efile=E4=BD=BF=E7=94=A8=E8=AF=B4=E6=98=8E=E5=92=8CUPX=E5=8E=8B?= =?UTF-8?q?=E7=BC=A9=E8=AF=B4=E6=98=8E=20=F0=9F=94=A7=20chore=EF=BC=9A?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0Makefile=E7=AE=80=E5=8C=96=E6=9E=84=E5=BB=BA?= =?UTF-8?q?=E6=B5=81=E7=A8=8B=EF=BC=8C=E6=94=AF=E6=8C=81=E8=87=AA=E5=8A=A8?= =?UTF-8?q?UPX=E5=8E=8B=E7=BC=A9=20=F0=9F=94=A7=20chore=EF=BC=9A=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0cabal.project.local=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=BC=98=E5=8C=96=E6=9E=84=E5=BB=BA=20=E2=AC=86?= =?UTF-8?q?=EF=B8=8F=20chore=EF=BC=9A=E5=8D=87=E7=BA=A7=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E8=87=B30.3.0.2=20=F0=9F=94=A7=20chore?= =?UTF-8?q?=EF=BC=9A=E4=BC=98=E5=8C=96GHC=E7=BC=96=E8=AF=91=E9=80=89?= =?UTF-8?q?=E9=A1=B9=EF=BC=8C=E5=90=AF=E7=94=A8=E4=BC=98=E5=8C=96=E5=92=8C?= =?UTF-8?q?=E9=93=BE=E6=8E=A5=E5=99=A8=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yml | 28 ++++++++++++++++++++++++++ Makefile | 40 +++++++++++++++++++++++++++++++++++++ README.md | 36 +++++++++++++++++++++++++++++++++ app/Main.hs | 2 +- cabal.project.local | 3 +++ quickjump.cabal | 9 +++++++-- 6 files changed, 115 insertions(+), 3 deletions(-) create mode 100644 Makefile create mode 100644 cabal.project.local diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 229f48e..7e794dd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -57,6 +57,34 @@ jobs: run: | 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 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..7c03b8b --- /dev/null +++ b/Makefile @@ -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" diff --git a/README.md b/README.md index 4b22e9c..8d75b87 100644 --- a/README.md +++ b/README.md @@ -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` 目标会使用 UPX(Ultimate 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) diff --git a/app/Main.hs b/app/Main.hs index bf0603f..da9d10f 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -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" ) diff --git a/cabal.project.local b/cabal.project.local new file mode 100644 index 0000000..7becdc4 --- /dev/null +++ b/cabal.project.local @@ -0,0 +1,3 @@ +ignore-project: False +split-sections: True +optimization: True diff --git a/quickjump.cabal b/quickjump.cabal index 6f1c0d3..8303495 100644 --- a/quickjump.cabal +++ b/quickjump.cabal @@ -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.