63 lines
2.4 KiB
PowerShell
63 lines
2.4 KiB
PowerShell
param(
|
|
[string]$Protoc = "",
|
|
[string]$IncludePath = $env:PROTOC_INCLUDE,
|
|
[string]$OutputRoot = ""
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
$repositoryRoot = Split-Path -Parent $PSScriptRoot
|
|
$protoRoot = Join-Path $repositoryRoot "api/proto"
|
|
$source = Join-Path $protoRoot "controlplane/v1/controlplane.proto"
|
|
$toolRoot = Join-Path $repositoryRoot ".tmp-proto/tools"
|
|
New-Item -ItemType Directory -Force -Path $toolRoot | Out-Null
|
|
|
|
if ([string]::IsNullOrWhiteSpace($Protoc)) {
|
|
$Protoc = & (Join-Path $PSScriptRoot "install-protoc.ps1")
|
|
}
|
|
|
|
$runningWindows = [System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform(
|
|
[System.Runtime.InteropServices.OSPlatform]::Windows
|
|
)
|
|
$suffix = if ($runningWindows) { ".exe" } else { "" }
|
|
$protocGenGo = Join-Path $toolRoot ("protoc-gen-go" + $suffix)
|
|
$protocGenGoGRPC = Join-Path $toolRoot ("protoc-gen-go-grpc" + $suffix)
|
|
|
|
go build -o $protocGenGo google.golang.org/protobuf/cmd/protoc-gen-go
|
|
if ($LASTEXITCODE -ne 0) { throw "build protoc-gen-go failed" }
|
|
go build -o $protocGenGoGRPC google.golang.org/grpc/cmd/protoc-gen-go-grpc
|
|
if ($LASTEXITCODE -ne 0) { throw "build protoc-gen-go-grpc failed" }
|
|
|
|
$protocCommand = Get-Command $Protoc -ErrorAction Stop
|
|
$protocVersion = (& $protocCommand.Source --version).Trim()
|
|
if ($protocVersion -ne "libprotoc 35.0") { throw "protoc 35.0 is required" }
|
|
|
|
if ([string]::IsNullOrWhiteSpace($IncludePath)) {
|
|
$installationRoot = Split-Path (Split-Path $protocCommand.Source -Parent) -Parent
|
|
$IncludePath = @(
|
|
(Join-Path $installationRoot "include"),
|
|
"/usr/include",
|
|
"/usr/local/include"
|
|
) |
|
|
Where-Object { Test-Path (Join-Path $_ "google/protobuf/timestamp.proto") } |
|
|
Select-Object -First 1
|
|
}
|
|
if ([string]::IsNullOrWhiteSpace($OutputRoot)) { $OutputRoot = $repositoryRoot }
|
|
if ([string]::IsNullOrWhiteSpace($IncludePath) -or
|
|
-not (Test-Path (Join-Path $IncludePath "google/protobuf/timestamp.proto"))) {
|
|
throw "protoc well-known type include directory was not found"
|
|
}
|
|
New-Item -ItemType Directory -Force -Path $OutputRoot | Out-Null
|
|
|
|
& $protocCommand.Source `
|
|
"--proto_path=$protoRoot" `
|
|
"--proto_path=$IncludePath" `
|
|
"--plugin=protoc-gen-go=$protocGenGo" `
|
|
"--plugin=protoc-gen-go-grpc=$protocGenGoGRPC" `
|
|
"--go_out=$OutputRoot" `
|
|
"--go_opt=module=proxy-pool" `
|
|
"--go-grpc_out=$OutputRoot" `
|
|
"--go-grpc_opt=module=proxy-pool" `
|
|
$source
|
|
if ($LASTEXITCODE -ne 0) { throw "protobuf Go generation failed" }
|