Skip to content

Commit a612508

Browse files
author
Brean
committed
fix: Enhance cross-compilation setup by adding aarch64 targets and improving packaging steps
1 parent 20c07f0 commit a612508

1 file changed

Lines changed: 121 additions & 8 deletions

File tree

.github/workflows/release.yml

Lines changed: 121 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@ jobs:
2323
with:
2424
toolchain: stable
2525
override: true
26-
target: aarch64-unknown-linux-musl
26+
27+
- name: Add build targets
28+
run: |
29+
rustup target add x86_64-unknown-linux-gnu
30+
rustup target add x86_64-unknown-linux-musl
31+
rustup target add aarch64-unknown-linux-gnu
32+
rustup target add aarch64-unknown-linux-musl
2733
2834
- name: Cache Cargo registry & index
2935
uses: actions/cache@v3
@@ -33,11 +39,13 @@ jobs:
3339
~/.cargo/git
3440
key: cargo-${{ hashFiles('**/Cargo.lock') }}
3541

36-
# Install additional required targets
37-
- name: Add x86_64 GNU target
38-
run: rustup target add x86_64-unknown-linux-gnu
42+
# Install cross-compilation tools
43+
- name: Install cross-compilation dependencies
44+
run: |
45+
sudo apt-get update
46+
sudo apt-get install -y gcc-aarch64-linux-gnu musl-tools
3947
40-
# Install Zig
48+
# Install Zig for cross-compilation
4149
- name: Install Zig
4250
run: |
4351
wget https://ziglang.org/download/0.10.0/zig-linux-x86_64-0.10.0.tar.xz
@@ -47,14 +55,119 @@ jobs:
4755
rm -rf zig-linux-x86_64-0.10.0.tar.xz
4856
zig version
4957
50-
# Install cargo-zigbuild
5158
- name: Install cargo-zigbuild
5259
run: cargo install cargo-zigbuild
5360

54-
- name: Install GoReleaser
55-
uses: goreleaser/goreleaser-action@v2
61+
# Build static binaries
62+
- name: Build static binaries
63+
run: |
64+
# x86_64 static binary
65+
cargo zigbuild --release --target x86_64-unknown-linux-musl
66+
67+
# aarch64 static binary
68+
cargo zigbuild --release --target aarch64-unknown-linux-musl
69+
70+
# Create directories for packaging
71+
- name: Prepare packaging directories
72+
run: |
73+
mkdir -p dist/bin
74+
mkdir -p dist/deb/DEBIAN
75+
mkdir -p dist/deb/usr/bin
76+
mkdir -p dist/rpm
77+
78+
# Copy binaries
79+
cp target/x86_64-unknown-linux-musl/release/rust-cli dist/bin/rust-cli-x86_64-linux
80+
cp target/aarch64-unknown-linux-musl/release/rust-cli dist/bin/rust-cli-aarch64-linux
81+
82+
# Make binaries executable
83+
chmod +x dist/bin/*
84+
85+
# Create Debian package
86+
- name: Create Debian package
87+
run: |
88+
# Get version from tag
89+
VERSION=${GITHUB_REF#refs/tags/v}
90+
91+
# Copy binary for deb package
92+
cp target/x86_64-unknown-linux-musl/release/rust-cli dist/deb/usr/bin/
93+
94+
# Create Debian control file
95+
cat > dist/deb/DEBIAN/control << EOF
96+
Package: rust-cli
97+
Version: ${VERSION}
98+
Section: utils
99+
Priority: optional
100+
Architecture: amd64
101+
Maintainer: Your Name <your.email@example.com>
102+
Description: Your Rust CLI application
103+
A description of your CLI tool.
104+
EOF
105+
106+
# Build the deb package
107+
dpkg-deb --build dist/deb dist/rust-cli_${VERSION}_amd64.deb
108+
109+
# Create RPM package
110+
- name: Create RPM package
111+
run: |
112+
# Install rpm tools
113+
sudo apt-get install -y rpm
114+
115+
# Get version from tag
116+
VERSION=${GITHUB_REF#refs/tags/v}
117+
118+
# Create RPM spec file
119+
mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
120+
121+
cat > ~/rpmbuild/SPECS/rust-cli.spec << EOF
122+
Name: rust-cli
123+
Version: ${VERSION}
124+
Release: 1%{?dist}
125+
Summary: Your Rust CLI application
126+
127+
License: MIT
128+
URL: https://github.com/${{ github.repository }}
129+
Source0: %{name}-%{version}.tar.gz
130+
131+
%description
132+
A description of your CLI tool.
133+
134+
%prep
135+
136+
%build
137+
138+
%install
139+
mkdir -p %{buildroot}/usr/bin
140+
cp $GITHUB_WORKSPACE/target/x86_64-unknown-linux-musl/release/rust-cli %{buildroot}/usr/bin/
141+
142+
%files
143+
/usr/bin/rust-cli
144+
145+
%changelog
146+
* $(date +'%a %b %d %Y') GitHub Actions <noreply@github.com> - ${VERSION}-1
147+
- Automated build
148+
EOF
149+
150+
# Build RPM
151+
rpmbuild -bb ~/rpmbuild/SPECS/rust-cli.spec
152+
cp ~/rpmbuild/RPMS/x86_64/rust-cli-${VERSION}-1.*.rpm dist/
153+
154+
# Create release with GoReleaser
155+
- name: Run GoReleaser
156+
uses: goreleaser/goreleaser-action@v5
56157
with:
57158
version: latest
58159
args: release --clean
59160
env:
60161
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
162+
163+
# Upload additional artifacts
164+
- name: Upload additional artifacts
165+
uses: softprops/action-gh-release@v1
166+
with:
167+
files: |
168+
dist/*.deb
169+
dist/*.rpm
170+
dist/bin/*
171+
generate_release_notes: true
172+
env:
173+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)