From 33c2df5485707f60ddfd12b0b5cb40a5516f5bb2 Mon Sep 17 00:00:00 2001 From: CN-JS-HuiBai Date: Wed, 15 Apr 2026 20:37:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=92=8C=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E7=BC=96=E8=AF=91=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- building-windows.ps1 | 74 ++++++++++++++++++++++++++++- dns/transport/local/local_darwin.go | 17 +++++++ dns/transport/local/local_shared.go | 2 +- 3 files changed, 90 insertions(+), 3 deletions(-) diff --git a/building-windows.ps1 b/building-windows.ps1 index 5a760766..2988ff1f 100644 --- a/building-windows.ps1 +++ b/building-windows.ps1 @@ -5,6 +5,8 @@ param( [string]$GoBin = "", [string]$DistDir = "", + [string]$GoCacheDir = "", + [string]$GoModCacheDir = "", [string]$CgoEnabledValue = "0", [string]$BuildJobs = "", [string]$Version = "", @@ -40,6 +42,8 @@ Usage: Optional parameters: -GoBin Go binary path -DistDir Output directory, default: .\dist + -GoCacheDir Go build cache directory, default: .\.cache\go-build + -GoModCacheDir Go module cache directory, default: .\.cache\gomod -CgoEnabledValue <0|1> CGO_ENABLED value, default: 0 -BuildJobs Go build parallel jobs, default: GO_BUILD_JOBS or CPU core count -Version Embedded version, default: git describe --tags --always @@ -130,6 +134,19 @@ function Resolve-BuildJobs { return [string][Environment]::ProcessorCount } +function Resolve-CachePath { + param( + [string]$RequestedPath, + [string]$DefaultRelativePath + ) + + if ($RequestedPath) { + return [System.IO.Path]::GetFullPath($RequestedPath) + } + + return [System.IO.Path]::GetFullPath((Join-Path $RootDir $DefaultRelativePath)) +} + function Get-TargetConfig { param([string]$Target) @@ -226,6 +243,8 @@ function Invoke-BuildTarget { $env:CGO_ENABLED = $CgoEnabledValue $env:GOOS = $config.GOOS $env:GOARCH = $config.GOARCH + $env:GOCACHE = $script:ResolvedGoCacheDir + $env:GOMODCACHE = $script:ResolvedGoModCacheDir if ($config.ContainsKey("GOARM")) { $env:GOARM = $config.GOARM @@ -240,7 +259,27 @@ function Invoke-BuildTarget { $MainPkg if ($LASTEXITCODE -ne 0) { - throw "Build failed: $Target" + return [pscustomobject]@{ + Target = $Target + Success = $false + OutputPath = $outputPath + Error = "go build exited with code $LASTEXITCODE" + } + } + + return [pscustomobject]@{ + Target = $Target + Success = $true + OutputPath = $outputPath + Error = "" + } + } + catch { + return [pscustomobject]@{ + Target = $Target + Success = $false + OutputPath = $outputPath + Error = $_.Exception.Message } } finally { @@ -269,6 +308,8 @@ Require-File -Path $releaseLdflagsPath $script:ResolvedGoBin = Resolve-GoBinary -RequestedGoBin $GoBin $script:ResolvedDistDir = if ($DistDir) { $DistDir } else { Join-Path $RootDir "dist" } $script:ResolvedDistDir = [System.IO.Path]::GetFullPath($script:ResolvedDistDir) +$script:ResolvedGoCacheDir = Resolve-CachePath -RequestedPath $GoCacheDir -DefaultRelativePath ".cache\go-build" +$script:ResolvedGoModCacheDir = Resolve-CachePath -RequestedPath $GoModCacheDir -DefaultRelativePath ".cache\gomod" $script:ResolvedBuildJobs = Resolve-BuildJobs -RequestedBuildJobs $BuildJobs $script:ResolvedVersion = Resolve-Version -RequestedVersion $Version -RepoRoot $RootDir $script:ResolvedBuildTagsOthers = if ($BuildTagsOthers) { $BuildTagsOthers } else { Read-TrimmedFile -Path $releaseTagsOthersPath } @@ -276,6 +317,8 @@ $script:ResolvedBuildTagsWindows = if ($BuildTagsWindows) { $BuildTagsWindows } $script:ResolvedLdflagsShared = Read-TrimmedFile -Path $releaseLdflagsPath New-Item -ItemType Directory -Force -Path $script:ResolvedDistDir | Out-Null +New-Item -ItemType Directory -Force -Path $script:ResolvedGoCacheDir | Out-Null +New-Item -ItemType Directory -Force -Path $script:ResolvedGoModCacheDir | Out-Null $resolvedTargets = @() if ($Targets.Count -eq 0 -or ($Targets.Count -eq 1 -and $Targets[0] -eq "all")) { @@ -284,10 +327,37 @@ if ($Targets.Count -eq 0 -or ($Targets.Count -eq 1 -and $Targets[0] -eq "all")) $resolvedTargets = $Targets } +$results = @() foreach ($target in $resolvedTargets) { - Invoke-BuildTarget -Target $target + $results += Invoke-BuildTarget -Target $target } Write-Host "" Write-Host "Build completed." -ForegroundColor Green Write-Host "Output directory: $script:ResolvedDistDir" +Write-Host "Go build cache: $script:ResolvedGoCacheDir" +Write-Host "Go module cache: $script:ResolvedGoModCacheDir" + +$successfulResults = @($results | Where-Object { $_.Success }) +$failedResults = @($results | Where-Object { -not $_.Success }) + +Write-Host "" +Write-Host "Succeeded targets:" -ForegroundColor Green +if ($successfulResults.Count -eq 0) { + Write-Host " (none)" +} else { + foreach ($result in $successfulResults) { + Write-Host " $($result.Target) -> $($result.OutputPath)" + } +} + +Write-Host "" +Write-Host "Failed targets:" -ForegroundColor Yellow +if ($failedResults.Count -eq 0) { + Write-Host " (none)" +} else { + foreach ($result in $failedResults) { + Write-Host " $($result.Target) -> $($result.Error)" + } + exit 1 +} diff --git a/dns/transport/local/local_darwin.go b/dns/transport/local/local_darwin.go index eb33d64f..db155b9d 100644 --- a/dns/transport/local/local_darwin.go +++ b/dns/transport/local/local_darwin.go @@ -90,3 +90,20 @@ func (t *Transport) Reset() { t.dhcpTransport.Reset() } } + +func (t *Transport) Exchange(ctx context.Context, message *mDNS.Msg) (*mDNS.Msg, error) { + question := message.Question[0] + if question.Qtype == mDNS.TypeA || question.Qtype == mDNS.TypeAAAA { + addresses := t.hosts.Lookup(dns.FqdnToDomain(question.Name)) + if len(addresses) > 0 { + return dns.FixedResponse(message.Id, question, addresses, C.DefaultDNSTTL), nil + } + } + if t.fallback && t.dhcpTransport != nil { + dhcpServers := t.dhcpTransport.Fetch() + if len(dhcpServers) > 0 { + return t.dhcpTransport.Exchange0(ctx, message, dhcpServers) + } + } + return t.exchange(ctx, message, question.Name) +} diff --git a/dns/transport/local/local_shared.go b/dns/transport/local/local_shared.go index 64a23a9f..307524b6 100644 --- a/dns/transport/local/local_shared.go +++ b/dns/transport/local/local_shared.go @@ -1,4 +1,4 @@ -//go:build !darwin +//go:build !windows package local