1- on :
2- release :
3- types : [created]
1+ name : Rust Build, Test and Release
42
5- permissions :
6- contents : write
3+ on :
4+ push :
5+ tags :
6+ - ' v*'
77
88jobs :
9- release :
10- name : release ${{ matrix.target }}
11- runs-on : ubuntu-latest
9+ build :
10+ name : Build on ${{ matrix.os }} - ${{ matrix.target }}
11+ runs-on : ${{ matrix.os }}
1212 strategy :
13- fail-fast : false
1413 matrix :
1514 include :
16- # - target: x86_64-pc-windows-gnu
17- # archive: zip
18- - target : x86_64-unknown-linux-musl
19- archive : tar.gz tar.xz tar.zst
20- # - target: x86_64-apple-darwin
21- # archive: zip
15+ - os : ubuntu-latest
16+ target : x86_64-unknown-linux-gnu
17+ # - os: ubuntu-latest
18+ # target: aarch64-unknown-linux-gnu
19+ - os : macos-latest
20+ target : x86_64-apple-darwin
21+ - os : macos-latest
22+ target : aarch64-apple-darwin
23+ - os : windows-latest
24+ target : x86_64-pc-windows-msvc
25+
2226 steps :
23- - uses : actions/checkout@master
24- - name : Compile and release
25- uses :
rust-build/[email protected] 27+ - name : Checkout code
28+ uses : actions/checkout@v4
29+
30+ - name : Install system dependencies (Ubuntu only)
31+ if : matrix.os == 'ubuntu-latest'
32+ run : |
33+ sudo apt-get update
34+ sudo apt-get install -y build-essential
35+ sudo apt-get install -y libssl-dev
36+ if [ "${{ matrix.target }}" == "aarch64-unknown-linux-gnu" ]; then
37+ sudo apt-get install -y gcc-aarch64-linux-gnu
38+ sudo apt-get install -y g++-aarch64-linux-gnu
39+ sudo apt-get install -y libc6-dev-arm64-cross
40+ fi
41+
42+ - name : Set up Rust
43+ run : |
44+ rustup update stable
45+ rustup target add ${{ matrix.target }}
46+
47+ - name : Set environment variables for ARM cross-compilation (Ubuntu only)
48+ if : matrix.os == 'ubuntu-latest' && matrix.target == 'aarch64-unknown-linux-gnu'
49+ run : |
50+ echo "CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
51+ echo "CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++" >> $GITHUB_ENV
52+ echo "AR_aarch64_unknown_linux_gnu=aarch64-linux-gnu-ar" >> $GITHUB_ENV
53+ echo "RANLIB_aarch64_unknown_linux_gnu=aarch64-linux-gnu-ranlib" >> $GITHUB_ENV
54+ echo "PKG_CONFIG_ALLOW_CROSS=1" >> $GITHUB_ENV
55+ echo "PKG_CONFIG_SYSROOT_DIR=/usr/aarch64-linux-gnu" >> $GITHUB_ENV
56+
57+ - name : Build project
58+ run : cargo build --release --target ${{ matrix.target }} --verbose
59+
60+ - name : Test binary
61+ run : |
62+ if [ "${{ matrix.os }}" == "windows-latest" ]; then
63+ binary_path=$(find target/${{ matrix.target }}/release -maxdepth 1 -type f -name "*.exe" | head -n 1)
64+ else
65+ binary_path=$(find target/${{ matrix.target }}/release -maxdepth 1 -type f \( -perm -u=x -o -perm -g=x -o -perm -o=x \) | head -n 1)
66+ fi
67+ if [ -n "$binary_path" ]; then
68+ $binary_path --version
69+ else
70+ echo "No executable binary found."
71+ exit 1
72+ fi
73+ shell : bash
74+ env :
75+ RUST_BACKTRACE : 1
76+
77+ - name : Package binary
78+ shell : bash
79+ run : |
80+ if [ "${{ matrix.os }}" == "windows-latest" ]; then
81+ binary_path=$(find target/${{ matrix.target }}/release -maxdepth 1 -type f -name "*.exe" | head -n 1)
82+ binary_name=$(basename "$binary_path")
83+ else
84+ binary_path=$(find target/${{ matrix.target }}/release -maxdepth 1 -type f \( -perm -u=x -o -perm -g=x -o -perm -o=x \) | head -n 1)
85+ binary_name=$(basename "$binary_path")
86+ fi
87+ mkdir -p ./release
88+ cp "$binary_path" release/"$binary_name"
89+ cd release
90+ if [ "${{ matrix.os }}" == "windows-latest" ]; then
91+ 7z a "$binary_name-${{ matrix.target }}.zip" "$binary_name"
92+ echo "Packaged file: ./release/$binary_name-${{ matrix.target }}.zip"
93+ else
94+ tar czvf "$binary_name-${{ matrix.target }}.tar.gz" "$binary_name"
95+ echo "Packaged file: ./release/$binary_name-${{ matrix.target }}.tar.gz"
96+ fi
97+ cd ..
98+
99+ - name : Upload artifact
100+ uses : actions/upload-artifact@v4
101+ with :
102+ name : ${{ matrix.target }}
103+ path : |
104+ release/*.zip
105+ release/*.tar.gz
106+ if-no-files-found : error
107+
108+ release :
109+ name : Create Release
110+ needs : build
111+ runs-on : ubuntu-latest
112+ permissions :
113+ contents : write
114+
115+ steps :
116+ - name : Download all artifacts
117+ uses : actions/download-artifact@v4
118+ with :
119+ path : artifacts
120+
121+ - name : Create Release
122+ id : create_release
123+ uses : softprops/action-gh-release@v2
26124 env :
27125 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
28126 with :
29- RUSTTARGET : ${{ matrix.target }}
30- ARCHIVE_TYPES : ${{ matrix.archive }}
127+ tag_name : ${{ github.ref_name }}
128+ name : Release ${{ github.ref_name }}
129+ draft : false
130+ prerelease : false
131+ files : |
132+ artifacts/**/*.zip
133+ artifacts/**/*.tar.gz
0 commit comments