Repository navigation
204 lines (181 loc) · 7.41 KB
/
Copy pathrust-build.yml
File metadata and controls
204 lines (181 loc) · 7.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
name: Rust Build
on:
workflow_call:
inputs:
rust-targets:
description: 'JSON array of Rust target triples'
required: true
type: string
ubuntu-versions:
description: 'JSON array of Ubuntu versions'
required: false
type: string
default: '["22.04"]'
frontend-dist:
description: 'Path to frontend dist folder'
required: false
type: string
cache-key:
description: 'Cache key for dependencies'
required: false
type: string
outputs:
binary-path:
description: 'Path to built binary'
value: ${{ jobs.build.outputs.binary-path }}
deb-package:
description: 'Path to .deb package'
value: ${{ jobs.build.outputs.deb-package }}
env:
CARGO_TERM_COLOR: always
jobs:
build:
runs-on: [self-hosted, linux, x64]
strategy:
fail-fast: false
matrix:
target: ${{ fromJSON(inputs.rust-targets) }}
ubuntu-version: ${{ fromJSON(inputs.ubuntu-versions) }}
# Exclude some combinations to reduce CI time for non-release builds
exclude:
- ubuntu-version: "18.04"
target: "armv7-unknown-linux-gnueabihf"
- ubuntu-version: "24.04"
target: "x86_64-unknown-linux-musl"
container: ubuntu:${{ matrix.ubuntu-version }}
outputs:
binary-path: ${{ steps.build.outputs.binary-path }}
deb-package: ${{ steps.package.outputs.deb-package }}
steps:
- name: Install system dependencies
run: |
apt-get update -qq
apt-get install -yqq --no-install-recommends \
build-essential \
bison \
flex \
ca-certificates \
openssl \
libssl-dev \
bc \
wget \
git \
curl \
cmake \
pkg-config \
musl-tools \
musl-dev \
software-properties-common \
gpg-agent \
libglib2.0-dev \
libgtk-3-dev \
libwebkit2gtk-4.0-dev \
libsoup2.4-dev \
libjavascriptcoregtk-4.0-dev \
libappindicator3-dev \
librsvg2-dev \
clang \
libclang-dev \
llvm-dev \
libc++-dev \
libc++abi-dev
- name: Setup cross-compilation toolchain
if: matrix.target != 'x86_64-unknown-linux-gnu'
run: | # pragma: allowlist secret
case "${{ matrix.target }}" in
"aarch64-unknown-linux-gnu")
apt-get install -yqq gcc-aarch64-linux-gnu libc6-dev-arm64-cross
echo "CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc" >> $GITHUB_ENV # pragma: allowlist secret
echo "CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++" >> $GITHUB_ENV # pragma: allowlist secret
echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
;;
"armv7-unknown-linux-musleabihf"|"armv7-unknown-linux-gnueabihf")
apt-get install -yqq gcc-arm-linux-gnueabihf libc6-dev-armhf-cross
echo "CC_armv7_unknown_linux_gnueabihf=arm-linux-gnueabihf-gcc" >> $GITHUB_ENV # pragma: allowlist secret
echo "CXX_armv7_unknown_linux_gnueabihf=arm-linux-gnueabihf-g++" >> $GITHUB_ENV # pragma: allowlist secret
echo "CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER=arm-linux-gnueabihf-gcc" >> $GITHUB_ENV
;;
"x86_64-unknown-linux-musl")
# musl-tools already installed above
echo "CC_x86_64_unknown_linux_musl=musl-gcc" >> $GITHUB_ENV # pragma: allowlist secret
;;
esac
- name: Install Rust
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain 1.85.0
source "$HOME/.cargo/env"
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
echo "CARGO_HOME=$HOME/.cargo" >> $GITHUB_ENV
rustc --version
- name: Add Rust target
run: |
rustup target add ${{ matrix.target }}
rustup component add clippy rustfmt
- name: Checkout code
uses: actions/checkout@v6
- name: Cache Cargo dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ inputs.cache-key }}-${{ matrix.target }}-${{ matrix.ubuntu-version }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ inputs.cache-key }}-${{ matrix.target }}-${{ matrix.ubuntu-version }}-
${{ inputs.cache-key }}-${{ matrix.target }}-
- name: Copy frontend dist
if: inputs.frontend-dist != ''
run: |
mkdir -p terraphim_server/dist
cp -r ${{ inputs.frontend-dist }}/* terraphim_server/dist/
- name: Build Rust project
id: build
run: |
# Build all main binaries
cargo build --release --target ${{ matrix.target }} \
--package terraphim_server \
--package terraphim_mcp_server \
--package terraphim_agent
# Test binaries
./target/${{ matrix.target }}/release/terraphim_server --version
./target/${{ matrix.target }}/release/terraphim_mcp_server --version
./target/${{ matrix.target }}/release/terraphim-agent --version
echo "binary-path=target/${{ matrix.target }}/release" >> $GITHUB_OUTPUT
- name: Install cargo-deb
if: contains(matrix.target, 'linux') && !contains(matrix.target, 'musl')
run: cargo install cargo-deb
- name: Create .deb package
if: contains(matrix.target, 'linux') && !contains(matrix.target, 'musl')
id: package
run: |
# Create .deb package for terraphim_server
cargo deb --target ${{ matrix.target }} --package terraphim_server --no-build
# Find the generated .deb file
DEB_FILE=$(find target/${{ matrix.target }}/debian -name "*.deb" | head -1)
DEB_NAME=$(basename "$DEB_FILE")
# Create versioned filename with ubuntu version and architecture
ARCH=$(echo ${{ matrix.target }} | cut -d'-' -f1)
NEW_NAME="terraphim-server_$(cargo metadata --format-version 1 | jq -r '.packages[] | select(.name == "terraphim_server") | .version')_ubuntu${{ matrix.ubuntu-version }}_${ARCH}.deb"
mv "$DEB_FILE" "target/$NEW_NAME"
echo "deb-package=target/$NEW_NAME" >> $GITHUB_OUTPUT
- name: Upload binary artifacts
uses: actions/upload-artifact@v5
with:
name: binaries-${{ matrix.target }}-ubuntu${{ matrix.ubuntu-version }}
path: |
target/${{ matrix.target }}/release/terraphim_server
target/${{ matrix.target }}/release/terraphim_mcp_server
target/${{ matrix.target }}/release/terraphim-agent
retention-days: 30
- name: Upload .deb package
if: contains(matrix.target, 'linux') && !contains(matrix.target, 'musl')
uses: actions/upload-artifact@v5
with:
name: deb-package-${{ matrix.target }}-ubuntu${{ matrix.ubuntu-version }}
path: target/*.deb
retention-days: 30
- name: Run basic tests
run: |
# rocksdb feature disabled in CI
cargo test --target ${{ matrix.target }} --workspace --exclude terraphim_agent