feat: 添加 cpa-ext 插件及相关配置和构建脚本
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
[CmdletBinding()]
|
||||
param()
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
Push-Location (Split-Path -Parent $PSScriptRoot)
|
||||
try {
|
||||
& wsl.exe bash ./scripts/build.sh
|
||||
} finally {
|
||||
Pop-Location
|
||||
}
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "WSL 构建失败,退出码 $LASTEXITCODE。"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
bash "$root/scripts/check-env.sh"
|
||||
|
||||
cd "$root"
|
||||
mkdir -p bin
|
||||
gofmt -w cmd internal
|
||||
go mod tidy
|
||||
go test ./...
|
||||
CGO_ENABLED=1 go build -tags cshared -buildmode=c-shared -o bin/cpa-ext.so ./cmd/cpa-ext
|
||||
|
||||
echo "Built: $root/bin/cpa-ext.so"
|
||||
@@ -0,0 +1,17 @@
|
||||
[CmdletBinding()]
|
||||
param()
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
function Resolve-Tool([string]$Name) {
|
||||
$tool = Get-Command $Name -ErrorAction SilentlyContinue
|
||||
if ($null -eq $tool) {
|
||||
throw "缺少 $Name,请先安装并加入 PATH。"
|
||||
}
|
||||
return $tool.Source
|
||||
}
|
||||
|
||||
$go = Resolve-Tool 'go'
|
||||
Write-Host "Go: $(& $go version)"
|
||||
Write-Host 'CLIProxyAPI target: ABI 1 / RPC schema 3'
|
||||
Write-Warning '本项目默认在 WSL/Linux 构建;请优先运行 wsl bash ./scripts/build.sh。'
|
||||
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
command -v go >/dev/null 2>&1 || {
|
||||
echo '缺少 Go,请先在 WSL 中安装 Go 1.24+ 并加入 PATH。' >&2
|
||||
exit 1
|
||||
}
|
||||
command -v gcc >/dev/null 2>&1 || {
|
||||
echo '缺少 gcc,请安装 build-essential(CGO 构建动态库需要)。' >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
echo "Go: $(go version)"
|
||||
echo "GCC: $(gcc --version | head -n 1)"
|
||||
echo 'CLIProxyAPI target: ABI 1 / RPC schema 3'
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
runtime="$root/.runtime"
|
||||
pid_file="$runtime/cliproxy.pid"
|
||||
log_file="$runtime/cliproxy.log"
|
||||
|
||||
if [[ -f "$pid_file" ]]; then
|
||||
old_pid="$(cat "$pid_file" || true)"
|
||||
if [[ -n "$old_pid" ]] && kill -0 "$old_pid" 2>/dev/null; then
|
||||
echo "CPA test host is already running (PID $old_pid)."
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
mkdir -p "$runtime/auths" "$runtime/plugins"
|
||||
: >"$log_file"
|
||||
nohup "$runtime/cliproxy" -config "$runtime/config.yaml" \
|
||||
>"$log_file" 2>&1 </dev/null &
|
||||
pid=$!
|
||||
echo "$pid" >"$pid_file"
|
||||
echo "Started CPA test host (PID $pid)."
|
||||
|
||||
for _ in $(seq 1 30); do
|
||||
if curl -fsS http://127.0.0.1:8317/healthz >/dev/null 2>&1; then
|
||||
echo 'CPA test host is ready at http://127.0.0.1:8317'
|
||||
exit 0
|
||||
fi
|
||||
if ! kill -0 "$pid" 2>/dev/null; then
|
||||
echo 'CPA test host exited during startup.' >&2
|
||||
tail -n 100 "$log_file" >&2
|
||||
exit 1
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
|
||||
echo 'Timed out waiting for CPA test host.' >&2
|
||||
tail -n 100 "$log_file" >&2
|
||||
exit 1
|
||||
@@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
pid_file="$root/.runtime/cliproxy.pid"
|
||||
|
||||
if [[ ! -f "$pid_file" ]]; then
|
||||
echo 'CPA test host is not running.'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
pid="$(cat "$pid_file")"
|
||||
if [[ -n "$pid" ]] && kill -0 "$pid" 2>/dev/null; then
|
||||
kill "$pid"
|
||||
for _ in $(seq 1 20); do
|
||||
kill -0 "$pid" 2>/dev/null || break
|
||||
sleep 0.25
|
||||
done
|
||||
fi
|
||||
rm -f "$pid_file"
|
||||
echo 'CPA test host stopped.'
|
||||
Reference in New Issue
Block a user