Skip to content

Commit 7bea29c

Browse files
committed
refactor(db): migrate sqlite to pure-go and add mips compatibility switch (#2296)
- Switch default SQLite path to github.com/glebarez/sqlite to reduce CGO dependency pressure. - Introduce a unified openSQLite entry in bootstrap and split driver selection by build tags. - Add sqlite_cgo_compat fallback for linux mips, mips64, loong64 and mipsle to keep legacy target builds working. - Update build.sh musl build flow to apply compatibility tag for mips-family targets. - Update beta_release workflow to pass compatibility tag cleanly and avoid conflicting flag composition.
1 parent 29447a4 commit 7bea29c

File tree

8 files changed

+130
-262
lines changed

8 files changed

+130
-262
lines changed

.github/workflows/beta_release.yml

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,38 @@ jobs:
6161
strategy:
6262
matrix:
6363
include:
64-
- target: "!(*musl*|*windows-arm64*|*windows7-*|*android*|*freebsd*)" # xgo and loongarch
64+
- target: "!(*musl*|*windows-arm64*|*windows7-*|*android*|*freebsd*)" # xgo and loongarch (exclude mips64le)
6565
hash: "md5"
66-
- target: "linux-!(arm*)-musl*" #musl-not-arm
66+
flags: ""
67+
goflags: ""
68+
- target: "linux-(mips|mips64|mipsle|mips64le|loong64)-musl*" # musl-compat-family
69+
hash: "md5-linux-musl-mips"
70+
flags: ""
71+
goflags: ""
72+
- target: "linux-!(arm*|mips|mips64|mipsle|mips64le|loong64)-musl*" # musl-not-arm (exclude compat-family)
6773
hash: "md5-linux-musl"
74+
flags: ""
75+
goflags: ""
6876
- target: "linux-arm*-musl*" #musl-arm
6977
hash: "md5-linux-musl-arm"
78+
flags: ""
79+
goflags: ""
7080
- target: "windows-arm64" #win-arm64
7181
hash: "md5-windows-arm64"
82+
flags: ""
83+
goflags: ""
7284
- target: "windows7-*" #win7
7385
hash: "md5-windows7"
86+
flags: ""
87+
goflags: "-tags=sqlite_cgo_compat"
7488
- target: "android-*" #android
7589
hash: "md5-android"
90+
flags: ""
91+
goflags: ""
7692
- target: "freebsd-*" #freebsd
7793
hash: "md5-freebsd"
94+
flags: ""
95+
goflags: ""
7896

7997
name: Beta Release
8098
runs-on: ubuntu-latest
@@ -99,6 +117,7 @@ jobs:
99117
uses: OpenListTeam/cgo-actions@v1.2.2
100118
with:
101119
targets: ${{ matrix.target }}
120+
flags: ${{ matrix.flags || '-ldflags=' }}
102121
musl-target-format: $os-$musl-$arch
103122
github-token: ${{ secrets.GITHUB_TOKEN }}
104123
out-dir: build
@@ -110,6 +129,8 @@ jobs:
110129
github.com/OpenListTeam/OpenList/v4/internal/conf.GitCommit=$git_commit
111130
github.com/OpenListTeam/OpenList/v4/internal/conf.Version=$tag
112131
github.com/OpenListTeam/OpenList/v4/internal/conf.WebVersion=rolling
132+
env:
133+
GOFLAGS: ${{ matrix.goflags }}
113134

114135
- name: Compress
115136
run: |

build.sh

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,19 @@ ldflags="\
4848
-X 'github.com/OpenListTeam/OpenList/v4/internal/conf.WebVersion=$webVersion' \
4949
"
5050

51+
# Keep sqlite driver tag selection centralized to avoid target drift.
52+
GetBuildTagsForTarget() {
53+
local target="$1"
54+
case "$target" in
55+
linux-loong64|linux-mips|linux-mips64|linux-mips64le|linux-mipsle|linux-musl-loong64|linux-musl-mips|linux-musl-mips64|linux-musl-mips64le|linux-musl-mipsle|windows-386|windows7-386|windows7-amd64)
56+
echo "jsoniter,sqlite_cgo_compat"
57+
;;
58+
*)
59+
echo "jsoniter"
60+
;;
61+
esac
62+
}
63+
5164
FetchWebRolling() {
5265
pre_release_json=$(eval "curl -fsSL --max-time 2 $githubAuthArgs -H \"Accept: application/vnd.github.v3+json\" \"https://api.github.com/repos/$frontendRepo/releases/tags/rolling\"")
5366
pre_release_assets=$(echo "$pre_release_json" | jq -r '.assets[].browser_download_url')
@@ -110,6 +123,7 @@ BuildWin7() {
110123
# Build for both 386 and amd64 architectures
111124
for arch in "386" "amd64"; do
112125
echo "building for windows7-${arch}"
126+
build_tags=$(GetBuildTagsForTarget "windows7-${arch}")
113127
export GOOS=windows
114128
export GOARCH=${arch}
115129
export CGO_ENABLED=1
@@ -124,7 +138,7 @@ BuildWin7() {
124138
fi
125139

126140
# Use the patched Go compiler for Win7 compatibility
127-
$(pwd)/go-win7/bin/go build -o "${1}-${arch}.exe" -ldflags="$ldflags" -tags=jsoniter .
141+
$(pwd)/go-win7/bin/go build -o "${1}-${arch}.exe" -ldflags="$ldflags" -tags="$build_tags" .
128142
done
129143
}
130144

@@ -193,11 +207,12 @@ BuildDockerMultiplatform() {
193207
cgo_cc=${CGO_ARGS[$i]}
194208
os=${os_arch%%-*}
195209
arch=${os_arch##*-}
210+
build_tags=$(GetBuildTagsForTarget "$os_arch")
196211
export GOOS=$os
197212
export GOARCH=$arch
198213
export CC=${cgo_cc}
199214
echo "building for $os_arch"
200-
go build -o build/$os/$arch/"$appName" -ldflags="$docker_lflags" -tags=jsoniter .
215+
go build -o build/$os/$arch/"$appName" -ldflags="$docker_lflags" -tags="$build_tags" .
201216
done
202217

203218
DOCKER_ARM_ARCHES=(linux-arm/v6 linux-arm/v7)
@@ -237,6 +252,8 @@ BuildLoongGLIBC() {
237252
local target_abi="$2"
238253
local output_file="$1"
239254
local oldWorldGoVersion="1.25.0"
255+
local loong_tags
256+
loong_tags=$(GetBuildTagsForTarget "linux-loong64")
240257

241258
if [ "$target_abi" = "abi1.0" ]; then
242259
echo building for linux-loong64-abi1.0
@@ -311,7 +328,7 @@ BuildLoongGLIBC() {
311328
CXX="$(pwd)/gcc8-loong64-abi1.0/bin/loongarch64-linux-gnu-g++" \
312329
CGO_ENABLED=1 \
313330
GOCACHE="$abi1_cache_dir" \
314-
$(pwd)/go-loong64-abi1.0/bin/go build -a -o "$output_file" -ldflags="$ldflags" -tags=jsoniter .; then
331+
$(pwd)/go-loong64-abi1.0/bin/go build -a -o "$output_file" -ldflags="$ldflags" -tags="$loong_tags" .; then
315332
echo "Error: Build failed with patched Go compiler"
316333
echo "Attempting retry with cache cleanup..."
317334
env GOCACHE="$abi1_cache_dir" $(pwd)/go-loong64-abi1.0/bin/go clean -cache
@@ -320,7 +337,7 @@ BuildLoongGLIBC() {
320337
CXX="$(pwd)/gcc8-loong64-abi1.0/bin/loongarch64-linux-gnu-g++" \
321338
CGO_ENABLED=1 \
322339
GOCACHE="$abi1_cache_dir" \
323-
$(pwd)/go-loong64-abi1.0/bin/go build -a -o "$output_file" -ldflags="$ldflags" -tags=jsoniter .; then
340+
$(pwd)/go-loong64-abi1.0/bin/go build -a -o "$output_file" -ldflags="$ldflags" -tags="$loong_tags" .; then
324341
echo "Error: Build failed again after cache cleanup"
325342
echo "Build environment details:"
326343
echo "GOOS=linux"
@@ -366,11 +383,11 @@ BuildLoongGLIBC() {
366383

367384
# Use standard Go compiler for new-world build
368385
echo "Building with standard Go compiler for new-world ABI2.0..."
369-
if ! go build -a -o "$output_file" -ldflags="$ldflags" -tags=jsoniter .; then
386+
if ! go build -a -o "$output_file" -ldflags="$ldflags" -tags="$loong_tags" .; then
370387
echo "Error: Build failed with standard Go compiler"
371388
echo "Attempting retry with cache cleanup..."
372389
go clean -cache
373-
if ! go build -a -o "$output_file" -ldflags="$ldflags" -tags=jsoniter .; then
390+
if ! go build -a -o "$output_file" -ldflags="$ldflags" -tags="$loong_tags" .; then
374391
echo "Error: Build failed again after cache cleanup"
375392
echo "Build environment details:"
376393
echo "GOOS=$GOOS"
@@ -391,6 +408,7 @@ BuildReleaseLinuxMusl() {
391408
mkdir -p "build"
392409
muslflags="--extldflags '-static -fpic' $ldflags"
393410
BASE="https://github.com/OpenListTeam/musl-compilers/releases/latest/download/"
411+
# Keep mips-family targets enabled; sqlite driver selection is handled by Go build tags.
394412
FILES=(x86_64-linux-musl-cross aarch64-linux-musl-cross mips-linux-musl-cross mips64-linux-musl-cross mips64el-linux-musl-cross mipsel-linux-musl-cross powerpc64le-linux-musl-cross s390x-linux-musl-cross loongarch64-linux-musl-cross)
395413
for i in "${FILES[@]}"; do
396414
url="${BASE}${i}.tgz"
@@ -403,12 +421,13 @@ BuildReleaseLinuxMusl() {
403421
for i in "${!OS_ARCHES[@]}"; do
404422
os_arch=${OS_ARCHES[$i]}
405423
cgo_cc=${CGO_ARGS[$i]}
424+
build_tags=$(GetBuildTagsForTarget "$os_arch")
406425
echo building for ${os_arch}
407426
export GOOS=${os_arch%%-*}
408427
export GOARCH=${os_arch##*-}
409428
export CC=${cgo_cc}
410429
export CGO_ENABLED=1
411-
go build -o ./build/$appName-$os_arch -ldflags="$muslflags" -tags=jsoniter .
430+
go build -o ./build/$appName-$os_arch -ldflags="$muslflags" -tags="$build_tags" .
412431
done
413432
}
414433

go.mod

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ require (
4141
github.com/foxxorcat/weiyun-sdk-go v0.1.4
4242
github.com/gin-contrib/cors v1.7.6
4343
github.com/gin-gonic/gin v1.10.1
44+
github.com/glebarez/sqlite v1.11.0
4445
github.com/go-resty/resty/v2 v2.16.5
4546
github.com/go-webauthn/webauthn v0.13.4
4647
github.com/golang-jwt/jwt/v4 v4.5.2
@@ -89,8 +90,8 @@ require (
8990
)
9091

9192
require (
92-
cloud.google.com/go/compute/metadata v0.9.0 // indirect
9393
github.com/Azure/azure-sdk-for-go/sdk/internal v1.11.1 // indirect
94+
github.com/BurntSushi/toml v1.6.0 // indirect
9495
github.com/ProtonMail/bcrypt v0.0.0-20211005172633-e235017c1baf // indirect
9596
github.com/ProtonMail/gluon v0.17.1-0.20230724134000-308be39be96e // indirect
9697
github.com/ProtonMail/go-mime v0.0.0-20230322103455-7d82a3887f2f // indirect
@@ -104,10 +105,12 @@ require (
104105
github.com/cloudsoda/sddl v0.0.0-20250224235906-926454e91efc // indirect
105106
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
106107
github.com/cronokirby/saferith v0.33.0 // indirect
108+
github.com/dustin/go-humanize v1.0.1 // indirect
107109
github.com/ebitengine/purego v0.8.4 // indirect
108110
github.com/emersion/go-message v0.18.2 // indirect
109111
github.com/emersion/go-vcard v0.0.0-20241024213814-c9703dde27ff // indirect
110112
github.com/geoffgarside/ber v1.2.0 // indirect
113+
github.com/glebarez/go-sqlite v1.21.2 // indirect
111114
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
112115
github.com/hashicorp/go-uuid v1.0.3 // indirect
113116
github.com/jcmturner/aescts/v2 v2.0.0 // indirect
@@ -123,11 +126,16 @@ require (
123126
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
124127
github.com/quic-go/qpack v0.5.1 // indirect
125128
github.com/relvacode/iso8601 v1.6.0 // indirect
129+
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
126130
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
127131
go.uber.org/mock v0.5.0 // indirect
128132
golang.org/x/exp v0.0.0-20250606033433-dcc06ee1d476 // indirect
129133
golang.org/x/mod v0.30.0 // indirect
130134
gopkg.in/go-jose/go-jose.v2 v2.6.3 // indirect
135+
modernc.org/libc v1.22.5 // indirect
136+
modernc.org/mathutil v1.5.0 // indirect
137+
modernc.org/memory v1.5.0 // indirect
138+
modernc.org/sqlite v1.23.1 // indirect
131139
)
132140

133141
require (

0 commit comments

Comments
 (0)