-
Notifications
You must be signed in to change notification settings - Fork 1
165 lines (149 loc) · 6 KB
/
build-cli-binaries.yml
File metadata and controls
165 lines (149 loc) · 6 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
name: Build CLI Binaries
on:
workflow_call:
inputs:
ref:
description: 'Git ref (tag or branch) to checkout'
required: false
type: string
workflow_dispatch:
inputs:
ref:
description: 'Git ref (tag or branch) to checkout'
required: false
type: string
env:
CARGO_TERM_COLOR: always
jobs:
build:
name: Build (${{ matrix.target }})
strategy:
fail-fast: false
matrix:
include:
- target: aarch64-apple-darwin
os: macos-latest
package: cli-node-darwin-arm64
- target: x86_64-apple-darwin
os: macos-latest
package: cli-node-darwin-x64
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
package: cli-node-linux-x64
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
package: cli-node-linux-arm64
use-cross: "true"
- target: x86_64-unknown-linux-musl
os: ubuntu-latest
package: cli-node-linux-x64-musl
use-cross: "true"
- target: aarch64-unknown-linux-musl
os: ubuntu-latest
package: cli-node-linux-arm64-musl
use-cross: "true"
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v6
with:
ref: ${{ inputs.ref || github.ref }}
- name: Install build dependencies (Ubuntu)
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y build-essential pkg-config libssl-dev openssl
- name: Detect OpenSSL paths (Ubuntu)
if: matrix.os == 'ubuntu-latest'
run: |
# Detect OpenSSL paths using pkg-config if available
OPENSSL_PREFIX=""
if command -v pkg-config >/dev/null 2>&1 && pkg-config --exists openssl 2>/dev/null; then
OPENSSL_INCLUDE_DIR=$(pkg-config --variable=includedir openssl 2>/dev/null || echo "/usr/include")
OPENSSL_LIB_DIR=$(pkg-config --variable=libdir openssl 2>/dev/null || echo "/usr/lib")
OPENSSL_PREFIX=$(pkg-config --variable=prefix openssl 2>/dev/null || echo "/usr")
OPENSSL_DIR="$OPENSSL_PREFIX"
else
# Fallback: check common locations
if [ -d "/usr/include/openssl" ]; then
OPENSSL_INCLUDE_DIR="/usr/include"
OPENSSL_LIB_DIR="/usr/lib"
OPENSSL_DIR="/usr"
OPENSSL_PREFIX="/usr"
elif [ -d "/usr/local/include/openssl" ]; then
OPENSSL_INCLUDE_DIR="/usr/local/include"
OPENSSL_LIB_DIR="/usr/local/lib"
OPENSSL_DIR="/usr/local"
OPENSSL_PREFIX="/usr/local"
else
# Default fallback
OPENSSL_INCLUDE_DIR="/usr/include"
OPENSSL_LIB_DIR="/usr/lib"
OPENSSL_DIR="/usr"
OPENSSL_PREFIX="/usr"
fi
fi
# Build PKG_CONFIG_PATH from detected paths and common multiarch locations
PKG_CONFIG_PATHS=()
# Standard location
[ -d "/usr/lib/pkgconfig" ] && PKG_CONFIG_PATHS+=("/usr/lib/pkgconfig")
# Architecture-specific paths (x86_64, aarch64, etc.)
for arch_dir in /usr/lib/*/pkgconfig; do
[ -d "$arch_dir" ] && PKG_CONFIG_PATHS+=("$arch_dir")
done
# Also check prefix-based paths if detected and different from /usr
if [ -n "$OPENSSL_PREFIX" ] && [ "$OPENSSL_PREFIX" != "/usr" ]; then
[ -d "$OPENSSL_PREFIX/lib/pkgconfig" ] && PKG_CONFIG_PATHS+=("$OPENSSL_PREFIX/lib/pkgconfig")
for arch_dir in "$OPENSSL_PREFIX"/lib/*/pkgconfig; do
[ -d "$arch_dir" ] && PKG_CONFIG_PATHS+=("$arch_dir")
done
fi
PKG_CONFIG_PATH=$(IFS=:; echo "${PKG_CONFIG_PATHS[*]}")
# Export for subsequent steps
echo "OPENSSL_DIR=$OPENSSL_DIR" >> $GITHUB_ENV
echo "OPENSSL_INCLUDE_DIR=$OPENSSL_INCLUDE_DIR" >> $GITHUB_ENV
echo "OPENSSL_LIB_DIR=$OPENSSL_LIB_DIR" >> $GITHUB_ENV
echo "PKG_CONFIG_PATH=$PKG_CONFIG_PATH" >> $GITHUB_ENV
# Debug output
echo "Detected OpenSSL paths:"
echo " OPENSSL_DIR=$OPENSSL_DIR"
echo " OPENSSL_INCLUDE_DIR=$OPENSSL_INCLUDE_DIR"
echo " OPENSSL_LIB_DIR=$OPENSSL_LIB_DIR"
echo " PKG_CONFIG_PATH=$PKG_CONFIG_PATH"
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Add Rust target
if: ${{ matrix.use-cross != 'true' }}
run: rustup target add ${{ matrix.target }}
- name: Install cross (for cross-compilation targets)
if: ${{ matrix.use-cross == 'true' }}
run: cargo install cross --version 0.2.5
- name: Rust cache
uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}
- name: Build binary
env:
# Use detected paths (set in previous step for Ubuntu, empty for others)
PKG_CONFIG_PATH: ${{ env.PKG_CONFIG_PATH }}
OPENSSL_DIR: ${{ env.OPENSSL_DIR }}
OPENSSL_INCLUDE_DIR: ${{ env.OPENSSL_INCLUDE_DIR }}
OPENSSL_LIB_DIR: ${{ env.OPENSSL_LIB_DIR }}
run: |
if [ "${{ matrix.use-cross }}" = "true" ]; then
cross build --release --target ${{ matrix.target }} -p opencode-cloud --bin occ
else
cargo build --release --target ${{ matrix.target }} -p opencode-cloud --bin occ
fi
- name: Prepare binary
run: |
mkdir -p packages/${{ matrix.package }}/bin
cp target/${{ matrix.target }}/release/occ packages/${{ matrix.package }}/bin/occ
chmod +x packages/${{ matrix.package }}/bin/occ
- name: Upload binary artifact
uses: actions/upload-artifact@v6
with:
name: ${{ matrix.package }}
path: packages/${{ matrix.package }}/bin/occ
retention-days: 1