4
This commit is contained in:
27
scripts/README.md
Normal file
27
scripts/README.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# scripts — 构建与代码生成脚本
|
||||
|
||||
PowerShell 脚本,需在 Windows PowerShell 5.1 下运行。脚本内对 Go 工具链与 protoc 的路径做了硬编码,换机时按本机实际调整。
|
||||
|
||||
| 脚本 | 作用 |
|
||||
|---|---|
|
||||
| `build.ps1` | 全量构建:① 调 `genproto.ps1` 生成 proto 代码 → ② 编译内核入口 `cmd/relay` 到 `build/relay.exe` → ③ 逐个编译全部插件到 `build/plugins/<name>.exe` |
|
||||
| `genproto.ps1` | 从 `src/go/proto/contract/v1/contract.proto` 生成 Go 代码(`*.pb.go` / `*_grpc.pb.go`,已入库)。仅在改契约时需要重跑 |
|
||||
|
||||
## 用法
|
||||
|
||||
```powershell
|
||||
.\scripts\build.ps1 # 完整构建(含 codegen)
|
||||
.\scripts\genproto.ps1 # 仅重新生成 proto 代码
|
||||
```
|
||||
|
||||
## 产物
|
||||
|
||||
`build.ps1` 产出:
|
||||
|
||||
- `build/relay.exe` — 内核入口
|
||||
- `build/plugins/{echo-base,transform-mid,streaming-demo,recorder-base,usage-base,proxy,dashboard}.exe` — 七个插件(产物名与各自 manifest 中的插件名一致)
|
||||
|
||||
## 注意
|
||||
|
||||
- 脚本注释一律用 ASCII。PowerShell 5.1 对含中文注释的脚本可能因 GBK/UTF-8 解码不一致而误判 token,导致解析错误,故 `build.ps1` 全用英文注释。
|
||||
- `protoc-gen-go` / `protoc-gen-go-grpc` 须先 `go install` 到 `GOPATH\bin`,脚本会把该目录加到 PATH 供 protoc 发现。
|
||||
@@ -1,12 +1,54 @@
|
||||
# 编译脚本(位于 scripts/):源码在 src/go/,产物输出到 build/relay.exe
|
||||
# Build script (in scripts/):
|
||||
# 1) generate proto code (calls genproto.ps1)
|
||||
# 2) build kernel entry cmd/relay -> build/relay.exe
|
||||
# 3) build all plugins -> build/plugins/<name>.exe
|
||||
# Source in src/go/, artifacts output to build/.
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$root = Split-Path $PSScriptRoot -Parent # 仓库根目录(scripts/ 的上一级)
|
||||
$out = Join-Path $root 'build\relay.exe'
|
||||
$root = Split-Path $PSScriptRoot -Parent # repo root (parent of scripts/)
|
||||
|
||||
Push-Location (Join-Path $root 'src\go')
|
||||
$goExe = 'D:\RJ\Basic\GO\bin\go.exe'
|
||||
$gopath = 'C:\Users\Administrator\go'
|
||||
$env:GOPATH = $gopath
|
||||
$env:PATH = "$gopath\bin;$env:PATH"
|
||||
|
||||
$srcGo = Join-Path $root 'src\go'
|
||||
$relayOut = Join-Path $root 'build\relay.exe'
|
||||
$pluginOut = Join-Path $root 'build\plugins'
|
||||
|
||||
# 1) generate proto code
|
||||
& (Join-Path $PSScriptRoot 'genproto.ps1')
|
||||
|
||||
# 2) build kernel entry
|
||||
Push-Location $srcGo
|
||||
try {
|
||||
go build -o $out .
|
||||
Write-Host "Built: $out"
|
||||
& $goExe build -o $relayOut ./cmd/relay
|
||||
if ($LASTEXITCODE -ne 0) { throw "build relay failed (exit $LASTEXITCODE)" }
|
||||
Write-Host "Built: $relayOut"
|
||||
} finally {
|
||||
Pop-Location
|
||||
}
|
||||
|
||||
# 3) build all plugins (output name matches manifest plugin name)
|
||||
New-Item -ItemType Directory -Force $pluginOut | Out-Null
|
||||
$plugins = @(
|
||||
@{ dir = 'echo'; out = 'echo-base.exe' },
|
||||
@{ dir = 'transform'; out = 'transform-mid.exe' },
|
||||
@{ dir = 'streaming'; out = 'streaming-demo.exe' },
|
||||
@{ dir = 'recorder'; out = 'recorder-base.exe' },
|
||||
@{ dir = 'usage'; out = 'usage-base.exe' },
|
||||
@{ dir = 'proxy'; out = 'proxy.exe' },
|
||||
@{ dir = 'dashboard'; out = 'dashboard.exe' }
|
||||
)
|
||||
Push-Location $srcGo
|
||||
try {
|
||||
foreach ($p in $plugins) {
|
||||
$target = Join-Path $pluginOut $p.out
|
||||
& $goExe build -o $target ('./plugins/' + $p.dir)
|
||||
if ($LASTEXITCODE -ne 0) { throw ("build plugin " + $p.dir + " failed (exit $LASTEXITCODE)") }
|
||||
Write-Host "Built plugin: $target"
|
||||
}
|
||||
} finally {
|
||||
Pop-Location
|
||||
}
|
||||
|
||||
Write-Host "All artifacts built under build/."
|
||||
|
||||
26
scripts/genproto.ps1
Normal file
26
scripts/genproto.ps1
Normal file
@@ -0,0 +1,26 @@
|
||||
# Proto codegen script.
|
||||
# Canonical .proto lives at repo-root proto/ (language-neutral contract).
|
||||
# Generated Go code (*.pb.go / *_grpc.pb.go) is written into src/go/proto/ and
|
||||
# committed to git, so cloning + `go build` works without protoc.
|
||||
# Only re-run this when the .proto contract changes.
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$root = Split-Path $PSScriptRoot -Parent # repo root
|
||||
|
||||
$protoc = 'D:\RJ\Tool\Anaconda3\Library\bin\protoc.exe'
|
||||
$gopath = 'C:\Users\Administrator\go'
|
||||
|
||||
# protoc needs protoc-gen-go / protoc-gen-go-grpc (in GOPATH\bin) on PATH
|
||||
$env:GOPATH = $gopath
|
||||
$env:PATH = "$gopath\bin;$env:PATH"
|
||||
|
||||
$protoRoot = Join-Path $root 'proto' # proto import root
|
||||
$goOut = Join-Path $root 'src\go\proto' # Go output root (module-relative proto/)
|
||||
|
||||
New-Item -ItemType Directory -Force $goOut | Out-Null
|
||||
|
||||
& $protoc "--proto_path=$protoRoot" `
|
||||
"--go_out=$goOut" --go_opt=paths=source_relative `
|
||||
"--go-grpc_out=$goOut" --go-grpc_opt=paths=source_relative `
|
||||
contract/v1/contract.proto
|
||||
if ($LASTEXITCODE -ne 0) { throw "protoc failed (exit $LASTEXITCODE)" }
|
||||
Write-Host "Proto generated: src/go/proto/contract/v1/*.pb.go (from proto/contract/v1/contract.proto)"
|
||||
Reference in New Issue
Block a user