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.