Skip to content

Commit c3a8ba4

Browse files
committed
fix ci
1 parent a23f5fa commit c3a8ba4

File tree

4 files changed

+100
-133
lines changed

4 files changed

+100
-133
lines changed

.github/workflows/ci.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
runs-on: ubuntu-latest
2828
strategy:
2929
matrix:
30-
go-version: [ '1.22' ]
30+
go-version: ['1.22']
3131
steps:
3232
- uses: actions/checkout@v3
3333
- uses: actions/setup-go@v3
@@ -36,6 +36,10 @@ jobs:
3636
- uses: acifani/setup-tinygo@v2
3737
with:
3838
tinygo-version: '0.31.2'
39+
- name: Install build tools
40+
run: |
41+
sudo apt-get update
42+
sudo apt-get install -y build-essential git curl
3943
- name: golangci-lint
4044
uses: golangci/golangci-lint-action@v3
4145
with:

.github/workflows/statestore-test.yml

Lines changed: 37 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,10 @@ jobs:
3333
with:
3434
go-version: '1.22'
3535

36-
- name: Install system dependencies
36+
- name: Install build tools
3737
run: |
3838
sudo apt-get update
39-
sudo apt-get install -y build-essential git libzstd-dev liblz4-dev libsnappy-dev zlib1g-dev libbz2-dev
40-
41-
- name: Setup RocksDB (only for rocksdb tests)
42-
if: matrix.test-type == 'rocksdb'
43-
run: |
44-
echo "🔧 检查并安装 RocksDB 依赖..."
45-
chmod +x scripts/setup-rocksdb-deps.sh
46-
./scripts/setup-rocksdb-deps.sh check || echo "依赖检查完成(可能已安装)"
47-
echo ""
48-
echo "🔧 安装 RocksDB 到 bin/lib 目录..."
49-
make setup-rocksdb
50-
echo "✅ RocksDB 安装完成"
51-
ls -lh bin/lib/rocksdb/lib/ || echo "检查库文件目录..."
39+
sudo apt-get install -y build-essential git curl
5240
5341
- name: Test Pebble
5442
if: matrix.test-type == 'pebble'
@@ -60,14 +48,13 @@ jobs:
6048

6149
- name: Build with Pebble
6250
if: matrix.test-type == 'pebble'
63-
run: make build
51+
run: make build-lite
6452

6553
- name: Build with RocksDB
6654
if: matrix.test-type == 'rocksdb'
67-
run: make build-rocksdb
55+
run: make build-all
6856

69-
- name: Verify binary exists
70-
if: matrix.test-type == 'pebble'
57+
- name: Verify binary
7158
run: |
7259
if [ ! -f bin/function-stream ]; then
7360
echo "❌ Binary not found!"
@@ -76,27 +63,23 @@ jobs:
7663
echo "✅ Binary created: bin/function-stream"
7764
ls -lh bin/function-stream
7865
79-
- name: Verify RocksDB binary exists
80-
if: matrix.test-type == 'rocksdb'
81-
run: |
82-
if [ ! -f bin/function-stream ]; then
83-
echo "❌ Binary not found!"
84-
exit 1
85-
fi
86-
echo "✅ Binary created: bin/function-stream"
87-
ls -lh bin/function-stream
88-
if [ -f bin/lib/rocksdb/lib/librocksdb.a ]; then
89-
echo "✅ RocksDB library found"
90-
ls -lh bin/lib/rocksdb/lib/*.a
91-
fi
66+
- name: Upload Pebble build artifacts
67+
if: matrix.test-type == 'pebble'
68+
uses: actions/upload-artifact@v4
69+
with:
70+
name: function-stream-linux-pebble
71+
path: bin/function-stream
72+
if-no-files-found: error
73+
retention-days: 7
9274

93-
- name: Upload build artifacts
75+
- name: Upload RocksDB build artifacts
76+
if: matrix.test-type == 'rocksdb'
9477
uses: actions/upload-artifact@v4
9578
with:
96-
name: function-stream-linux-${{ matrix.test-type }}
79+
name: function-stream-linux-rocksdb
9780
path: |
9881
bin/function-stream
99-
bin/lib/rocksdb/lib/*.a
82+
bin/function-stream/lib/rocksdb/lib/*.a
10083
if-no-files-found: ignore
10184
retention-days: 7
10285

@@ -112,45 +95,45 @@ jobs:
11295
with:
11396
go-version: '1.22'
11497

115-
- name: Install dependencies
98+
- name: Install build tools
11699
run: |
117100
sudo apt-get update
118-
sudo apt-get install -y build-essential git libzstd-dev liblz4-dev libsnappy-dev zlib1g-dev
119-
120-
- name: Setup RocksDB
121-
run: |
122-
echo "🔧 安装 RocksDB 到 bin/lib 目录..."
123-
make setup-rocksdb
124-
echo "✅ RocksDB 安装完成"
125-
echo "验证安装:"
126-
ls -lh bin/lib/rocksdb/lib/ || echo "库文件目录不存在"
127-
ls -lh bin/lib/rocksdb/include/ || echo "头文件目录不存在"
101+
sudo apt-get install -y build-essential git curl
128102
129103
- name: Test Pebble
130104
run: make test-statestore
131105

132106
- name: Test RocksDB
133107
run: make test-statestore-rocksdb
134108

135-
- name: Build all variants
136-
run: |
137-
make build
138-
make build-rocksdb
109+
- name: Build RocksDB variant
110+
run: make build-all
139111

140-
- name: List build artifacts
112+
- name: Verify build artifacts
141113
run: |
142-
echo "=== Build Artifacts ==="
143-
find bin -type f -executable 2>/dev/null || true
114+
echo "=== Build Artifacts ==="
115+
if [ -f bin/function-stream ]; then
116+
echo "✅ Binary: bin/function-stream"
117+
ls -lh bin/function-stream
118+
else
119+
echo "❌ Binary not found!"
120+
exit 1
121+
fi
144122
echo ""
145123
echo "=== RocksDB Libraries ==="
146-
find bin/lib/rocksdb -type f 2>/dev/null || true
124+
if [ -d bin/function-stream/lib/rocksdb/lib ]; then
125+
ls -lh bin/function-stream/lib/rocksdb/lib/*.a 2>/dev/null || echo "No library files found"
126+
else
127+
echo "⚠️ RocksDB library directory not found"
128+
fi
147129
148130
- name: Upload all artifacts
149131
uses: actions/upload-artifact@v4
150132
with:
151133
name: function-stream-linux-complete
152134
path: |
153-
bin/
135+
bin/function-stream
136+
bin/function-stream/lib/rocksdb/lib/*.a
154137
if-no-files-found: ignore
155138
retention-days: 7
156139

Makefile

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,29 @@ build: build-all
2020
build-all: setup-rocksdb
2121
@echo ""
2222
@echo "Building with RocksDB support..."
23-
@# Check and install dependencies
2423
@chmod +x scripts/setup-rocksdb-deps.sh
2524
@./scripts/setup-rocksdb-deps.sh check
26-
@# Detect operating system and generate link flags
25+
@echo "Generating link flags..."
2726
@ROCKSDB_LIB_DIR=$$(pwd)/bin/function-stream/lib/rocksdb/lib; \
2827
ROCKSDB_INCLUDE_DIR=$$(pwd)/bin/function-stream/lib/rocksdb/include; \
2928
TMP_LDFLAGS=$$(mktemp); \
3029
trap "rm -f $$TMP_LDFLAGS" EXIT; \
3130
./scripts/setup-rocksdb-deps.sh ldflags "$$ROCKSDB_LIB_DIR" "$$TMP_LDFLAGS"; \
3231
CGO_LDFLAGS=$$(cat $$TMP_LDFLAGS); \
3332
PKG_CONFIG_PATH="" \
34-
CGO_ENABLED=1 CGO_CFLAGS="-I$$ROCKSDB_INCLUDE_DIR" CGO_LDFLAGS="$$CGO_LDFLAGS" \
33+
CGO_ENABLED=1 \
34+
CGO_CFLAGS="-I$$ROCKSDB_INCLUDE_DIR" \
35+
CGO_LDFLAGS="$$CGO_LDFLAGS" \
3536
go build -v -tags "rocksdb,grocksdb_no_link" -ldflags="-s -w" -o bin/function-stream ./cmd
3637
@echo ""
3738
@echo "Checking binary dependencies..."
3839
@if command -v otool >/dev/null 2>&1; then \
3940
echo "Binary dependencies:"; \
40-
otool -L bin/function-stream 2>/dev/null | grep -v "^bin/function-stream:" | grep -v "^\t/usr/lib/" | grep -v "^\t/System/Library/" | head -10 || echo " ✅ Only system libraries (compatible with all macOS)"; \
41+
otool -L bin/function-stream 2>/dev/null | \
42+
grep -v "^bin/function-stream:" | \
43+
grep -v "^\t/usr/lib/" | \
44+
grep -v "^\t/System/Library/" | \
45+
head -10 || echo " ✅ Only system libraries (compatible with all macOS)"; \
4146
fi
4247
@echo ""
4348
@echo "Cleaning RocksDB files for packaging..."

scripts/setup-rocksdb-deps.sh

Lines changed: 49 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -149,98 +149,73 @@ install_deps_linux() {
149149
return 0
150150
}
151151

152-
# Generate CGO_LDFLAGS
153-
# Note: Even though compression is disabled, RocksDB's compressed_secondary_cache still needs bzip2 and zlib
152+
# Find static library file by checking common paths
153+
# Arguments: library name (e.g., "bz2" or "z"), library directory
154+
# Returns: full path to static library if found, empty string otherwise
155+
find_static_library() {
156+
local lib_name=$1
157+
local lib_dir=$2
158+
local static_paths=(
159+
"${lib_dir}/lib${lib_name}.a"
160+
"/usr/lib/x86_64-linux-gnu/lib${lib_name}.a"
161+
"/usr/lib64/lib${lib_name}.a"
162+
"/usr/lib/lib${lib_name}.a"
163+
)
164+
165+
for path in "${static_paths[@]}"; do
166+
if [ -f "$path" ]; then
167+
echo "$path"
168+
return 0
169+
fi
170+
done
171+
172+
return 1
173+
}
174+
175+
# Generate CGO_LDFLAGS for linking RocksDB and dependencies
176+
# Note: RocksDB's compressed_secondary_cache requires bzip2 and zlib
154177
# These libraries are statically linked to avoid runtime dependencies
155178
generate_cgo_ldflags() {
156179
local os=$(detect_os)
157180
local rocksdb_lib_dir=$1
158181
local output_file=$2
159-
local lib_dir=""
182+
local rocksdb_static="${rocksdb_lib_dir}/librocksdb.a"
160183

161184
if [ "$os" = "darwin" ]; then
162-
# macOS: Statically link rocksdb, link bz2 and z as system libraries
163-
# Note: Using grocksdb_no_link tag, so we need to provide all necessary libraries
164-
# Note: macOS system libraries (bz2, z) are available on all macOS systems, so dynamic linking is acceptable
165-
# Note: RocksDB is statically linked by directly specifying the .a file
166-
# Note: Using -Wl,-force_load to ensure all symbols from static library are included
167-
local rocksdb_static="${rocksdb_lib_dir}/librocksdb.a"
185+
# macOS: Statically link RocksDB, dynamically link system libraries
186+
# Using grocksdb_no_link tag, so we provide all necessary libraries
187+
# macOS system libraries (bz2, z) are available on all macOS systems
168188
if [ -f "$rocksdb_static" ]; then
169189
# Force load static library to ensure all symbols are included
170-
# Link system libraries (bz2, z) - these are available on all macOS systems
171-
# Use -Wl,-dead_strip to remove unused code
172190
echo "-Wl,-force_load,${rocksdb_static} -pthread -lstdc++ -ldl -lbz2 -lz" > "$output_file"
173191
else
174192
# Fallback: use library path (should not happen if setup-rocksdb completed)
175193
echo "-L${rocksdb_lib_dir} -lrocksdb -pthread -lstdc++ -ldl -lbz2 -lz" > "$output_file"
176194
fi
177195
elif [ "$os" = "linux" ]; then
178-
# Linux: Use static linking for bz2 and z, keep rocksdb as static library
179-
# Use -static flag to force static linking of system libraries
180-
lib_dir=$(detect_linux_lib_dir)
181-
# Try to find static library paths
182-
local bz2_static=""
183-
local z_static=""
184-
185-
# Find static library paths
186-
if [ -f "${lib_dir}/libbz2.a" ]; then
187-
bz2_static="${lib_dir}/libbz2.a"
188-
elif [ -f "/usr/lib/x86_64-linux-gnu/libbz2.a" ]; then
189-
bz2_static="/usr/lib/x86_64-linux-gnu/libbz2.a"
190-
elif [ -f "/usr/lib64/libbz2.a" ]; then
191-
bz2_static="/usr/lib64/libbz2.a"
192-
elif [ -f "/usr/lib/libbz2.a" ]; then
193-
bz2_static="/usr/lib/libbz2.a"
194-
fi
195-
196-
if [ -f "${lib_dir}/libz.a" ]; then
197-
z_static="${lib_dir}/libz.a"
198-
elif [ -f "/usr/lib/x86_64-linux-gnu/libz.a" ]; then
199-
z_static="/usr/lib/x86_64-linux-gnu/libz.a"
200-
elif [ -f "/usr/lib64/libz.a" ]; then
201-
z_static="/usr/lib64/libz.a"
202-
elif [ -f "/usr/lib/libz.a" ]; then
203-
z_static="/usr/lib/libz.a"
204-
fi
196+
# Linux: Fully static link all libraries for maximum portability
197+
local lib_dir=$(detect_linux_lib_dir)
198+
local bz2_static
199+
local z_static
205200

206-
# Force static linking of rocksdb by directly specifying the static library file
207-
local rocksdb_static="${rocksdb_lib_dir}/librocksdb.a"
201+
# Try to find static library files
202+
bz2_static=$(find_static_library "bz2" "$lib_dir" 2>/dev/null || echo "")
203+
z_static=$(find_static_library "z" "$lib_dir" 2>/dev/null || echo "")
208204

209-
# Build link flags with static libraries if available, otherwise use -static flag
210-
# Note: Using grocksdb_no_link tag, so we need to provide all necessary libraries
211-
# Note: On Linux, we can fully static link all libraries for portability
212-
if [ -n "$bz2_static" ] && [ -n "$z_static" ]; then
213-
# Use direct static library paths for all libraries - fully static binary
214-
if [ -f "$rocksdb_static" ]; then
215-
# Directly link all static library files
216-
# This creates a fully static binary that can run on any Linux system
217-
# Add necessary system libraries: pthread, stdc++, dl
218-
echo "${rocksdb_static} ${bz2_static} ${z_static} -static -pthread -lstdc++ -ldl" > "$output_file"
219-
else
220-
# RocksDB static library not found, use library path with static linking
221-
if [ -d "$lib_dir" ] && [ "$lib_dir" != "/usr/lib" ]; then
222-
echo "-L${rocksdb_lib_dir} -L${lib_dir} -Wl,-Bstatic -lrocksdb ${bz2_static} ${z_static} -Wl,-Bdynamic -static -pthread -lstdc++ -ldl" > "$output_file"
223-
else
224-
echo "-L${rocksdb_lib_dir} -Wl,-Bstatic -lrocksdb ${bz2_static} ${z_static} -Wl,-Bdynamic -static -pthread -lstdc++ -ldl" > "$output_file"
225-
fi
226-
fi
205+
# Build link flags based on available static libraries
206+
if [ -n "$bz2_static" ] && [ -n "$z_static" ] && [ -f "$rocksdb_static" ]; then
207+
# Best case: all static libraries found, create fully static binary
208+
echo "${rocksdb_static} ${bz2_static} ${z_static} -static -pthread -lstdc++ -ldl" > "$output_file"
209+
elif [ -f "$rocksdb_static" ]; then
210+
# RocksDB static found, but system libs not found - use -static flag
211+
local lib_search=""
212+
[ -d "$lib_dir" ] && [ "$lib_dir" != "/usr/lib" ] && lib_search="-L${lib_dir}"
213+
echo "${rocksdb_static} ${lib_search} -static -lbz2 -lz -pthread -lstdc++ -ldl" > "$output_file"
227214
else
228-
# Static libraries not found, use -static flag for full static linking
229-
if [ -f "$rocksdb_static" ]; then
230-
# RocksDB is static, use -static for system libraries (fully static binary)
231-
if [ -d "$lib_dir" ] && [ "$lib_dir" != "/usr/lib" ]; then
232-
echo "${rocksdb_static} -L${lib_dir} -static -lbz2 -lz -pthread -lstdc++ -ldl" > "$output_file"
233-
else
234-
echo "${rocksdb_static} -static -lbz2 -lz -pthread -lstdc++ -ldl" > "$output_file"
235-
fi
236-
else
237-
# Fall back to -static flag for static linking (fully static binary)
238-
if [ -d "$lib_dir" ] && [ "$lib_dir" != "/usr/lib" ]; then
239-
echo "-L${rocksdb_lib_dir} -L${lib_dir} -Wl,-Bstatic -lrocksdb -lbz2 -lz -Wl,-Bdynamic -static -pthread -lstdc++ -ldl" > "$output_file"
240-
else
241-
echo "-L${rocksdb_lib_dir} -Wl,-Bstatic -lrocksdb -lbz2 -lz -Wl,-Bdynamic -static -pthread -lstdc++ -ldl" > "$output_file"
242-
fi
243-
fi
215+
# Fallback: use library paths with static linking flags
216+
local lib_search="-L${rocksdb_lib_dir}"
217+
[ -d "$lib_dir" ] && [ "$lib_dir" != "/usr/lib" ] && lib_search="${lib_search} -L${lib_dir}"
218+
echo "${lib_search} -Wl,-Bstatic -lrocksdb -lbz2 -lz -Wl,-Bdynamic -static -pthread -lstdc++ -ldl" > "$output_file"
244219
fi
245220
else
246221
echo_error "Unsupported operating system: $os"

0 commit comments

Comments
 (0)