Skip to content

Commit 17fb1c4

Browse files
committed
更新构建配置,减少二进制体积
1 parent ab25d4b commit 17fb1c4

File tree

5 files changed

+150
-32
lines changed

5 files changed

+150
-32
lines changed

.cargo/config.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[build]
2+
rustflags = ["-Zlocation-detail=none", "-Cpanic=abort"]
3+
4+
[unstable]
5+
build-std = ["std", "panic_abort"]
6+
build-std-features = ["panic_immediate_abort", "optimize_for_size"]

.github/workflows/release.yml

Lines changed: 115 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,137 @@
1-
name: Release Build
1+
name: Release
22

33
on:
44
workflow_dispatch:
55
push:
66
tags:
7-
- "v*" # 当推送 v 开头的 tag 时触发(例如 v1.0.0)
7+
- '*.*.*'
8+
- 'v*.*.*'
9+
- '*.*.*-*'
10+
- 'v*.*.*-*'
811

9-
# for gh release upload
1012
permissions:
1113
contents: write
1214

1315
jobs:
14-
build-and-release:
15-
runs-on: windows-latest
16+
linux-build:
17+
runs-on: ubuntu-latest
18+
outputs:
19+
name: ${{ steps.meta.outputs.name }}
20+
version: ${{ steps.meta.outputs.version }}
21+
pre: ${{ steps.meta.outputs.pre }}
1622
steps:
1723
- name: Checkout code
1824
uses: actions/checkout@v4
25+
with:
26+
fetch-depth: 0
27+
filter: tree:0
28+
29+
- name: Get metadata
30+
id: meta
31+
run: |
32+
# 获取所有标签以保证最新标签的准确性
33+
git fetch --tags
34+
35+
APP_NAME=$(grep -m1 -oP 'name = "\K[^"]+' Cargo.toml)
36+
APP_VERSION=$(grep -m1 -oP 'version = "\K[^"]+' Cargo.toml)
37+
echo "name=$APP_NAME" >> $GITHUB_OUTPUT
38+
echo "version=$APP_VERSION" >> $GITHUB_OUTPUT
39+
40+
# 动态获取标签信息
41+
if [[ "$GITHUB_EVENT_NAME" == "workflow_dispatch" ]]; then
42+
TAG=$(git describe --tags --abbrev=0)
43+
TAG=${TAG#v}
44+
else
45+
TAG=${GITHUB_REF#refs/tags/}
46+
TAG=${TAG#v}
47+
fi
48+
49+
# 版本一致性检查
50+
if [[ "$APP_VERSION" != "$TAG" ]]; then
51+
echo "ERROR: Cargo.toml version ($APP_VERSION) ≠ tag ($TAG)" >&2
52+
exit 1
53+
fi
54+
55+
# 设置预发布标识
56+
[[ "$APP_VERSION" == *-* ]] && PRE=true || PRE=false
57+
echo "pre=$PRE" >> $GITHUB_OUTPUT
1958
20-
- name: Install Rust
59+
- name: Setup OpenSSL
60+
run: sudo apt-get install -y pkg-config libssl-dev lld
61+
62+
- name: Setup Rust
2163
uses: actions-rust-lang/setup-rust-toolchain@v1
64+
65+
- name: Build Linux binaries
66+
run: |
67+
cargo install cross
68+
cross build --release --target x86_64-unknown-linux-gnu
69+
cross build --release --target aarch64-unknown-linux-gnu
70+
71+
- name: Package assets
72+
run: |
73+
rm -rf release && mkdir -p release
74+
for target in x86_64-unknown-linux-gnu aarch64-unknown-linux-gnu; do
75+
binary_path="./target/$target/release/${{ steps.meta.outputs.name }}"
76+
[ ! -f "$binary_path" ] && echo "Missing $binary_path" && exit 1
77+
78+
target_name=$(echo $target | sed 's/-unknown//g')
79+
package_name="${{ steps.meta.outputs.name }}-${{ steps.meta.outputs.version }}-$target_name"
80+
tmp_dir="release/$package_name"
81+
mkdir -p "$tmp_dir"
82+
cp "$binary_path" README.md LICENSE "$tmp_dir"
83+
84+
tar -C "release" -czf "release/$package_name.tar.gz" "$package_name"
85+
sha256sum "release/$package_name.tar.gz" \
86+
| awk '{print $1}' > "release/$package_name.tar.gz.sha256"
87+
done
88+
89+
- name: Upload assets
90+
uses: actions/upload-artifact@v4
2291
with:
23-
toolchain: stable
24-
target: x86_64-pc-windows-msvc
25-
override: true
92+
path: |
93+
release/*.tar.gz
94+
release/*.tar.gz.sha256
2695
27-
- name: Build Release
96+
windows-build:
97+
runs-on: windows-latest
98+
needs: linux-build
99+
steps:
100+
- name: Checkout code
101+
uses: actions/checkout@v4
102+
with:
103+
fetch-depth: 0
104+
filter: tree:0
105+
106+
- name: Setup Rust
107+
uses: actions-rust-lang/setup-rust-toolchain@v1
108+
109+
- name: Build Windows binary
28110
run: cargo build --release
29111

30-
- name: Create Release
112+
- name: Package Windows assets
113+
shell: pwsh
114+
run: |
115+
New-Item -ItemType Directory -Path release -Force
116+
$exe = "${{ needs.linux-build.outputs.name }}.exe"
117+
$dest = "release/${{ needs.linux-build.outputs.name }}-${{ needs.linux-build.outputs.version }}-x86_64-pc-windows-msvc.exe"
118+
Move-Item "target/release/$exe" $dest -Force
119+
(Get-FileHash $dest).Hash.ToLower() | Out-File "$dest.sha256"
120+
121+
- name: Download Linux assets
122+
uses: actions/download-artifact@v4
123+
with:
124+
path: release
125+
merge-multiple: true
126+
127+
- name: Upload Windows assets
31128
uses: softprops/action-gh-release@v2
32129
with:
33-
name: ${{ github.ref_name }}
34130
files: |
35-
target/release/*.exe
36-
draft: false
37-
prerelease: false
38-
env:
39-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
131+
release/*.exe
132+
release/*.exe.sha256
133+
release/*.tar.gz
134+
release/*.tar.gz.sha256
135+
tag_name: v${{ needs.linux-build.outputs.version }}
136+
prerelease: ${{ needs.linux-build.outputs.pre }}
137+
make_latest: ${{ needs.linux-build.outputs.pre == 'false' }}

Cargo.lock

Lines changed: 23 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "torrent-tidy"
3-
version = "0.1.0"
3+
version = "0.1.9"
44
edition = "2024"
55

66
[workspace]
@@ -16,7 +16,7 @@ strip = true # Strip symbols from binary*, strip = true is equivalent to
1616
debug = false # Disable debug info
1717

1818
[dependencies]
19-
reqwest = { version = "0.12", features = ["json", "cookies"] }
19+
reqwest = { version = "0.12", features = ["json", "cookies", "native-tls-vendored"] }
2020
serde = { version = "1.0", features = ["derive"] }
2121
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
2222
clap = { version = "4.5", features = ["derive"] }

rust-toolchain.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[toolchain]
2+
channel = "nightly"
3+
components = ["rust-src"]
4+
profile = "minimal"

0 commit comments

Comments
 (0)