1+ # Copyright 2025 Google LLC
2+ #
3+ # Licensed under the Apache License, Version 2.0 (the "License");
4+ # you may not use this file except in compliance with the License.
5+ # You may obtain a copy of the License at
6+ #
7+ # http://www.apache.org/licenses/LICENSE-2.0
8+ #
9+ # Unless required by applicable law or agreed to in writing, software
10+ # distributed under the License is distributed on an "AS IS" BASIS,
11+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ # See the License for the specific language governing permissions and
13+ # limitations under the License.
14+
15+ # ################################################################################
16+ # The build tooling from this repo is designed to be run on Linux. Eventually
17+ # we will be able to do cross-platform builds for the Ops Agent, but for now
18+ # we are still running in a Windows container. This script exists as a stop-gap
19+ # until proper cross-platform builds are possible.
20+ # ################################################################################
21+ # This script builds the otelopscol binary with a particular name and path to
22+ # match the expectations of our build tooling. It will do the same thing as
23+ # our Makefiles in this repo do, mainly to ensure there is one source of truth
24+ # in this repo for exactly what version of Go is used to build the binary.
25+ # ################################################################################
26+
27+ param (
28+ [string ]$jmxHash = " " ,
29+ [string ]$outDir = " ."
30+ )
31+
32+ # Set up tools directory.
33+ $toolsDir = " " + (Get-Location ) + " \.tools" # Powershell moment
34+ New-Item - ItemType Directory - Force - Path $toolsDir | Out-Null
35+
36+ # Download Go.
37+ $goZipPath = " ./go.windows-amd64.zip"
38+ $goDownloadURL = " https://go.dev/dl/go1.23.2.windows-amd64.zip"
39+ Invoke-WebRequest $goDownloadURL - OutFile $goZipPath
40+ Expand-Archive - Path $goZipPath - DestinationPath $toolsDir
41+ Remove-Item $goZipPath
42+ $goBinDir = " $toolsDir \go\bin"
43+ $goBin = " $goBinDir \go"
44+
45+ # Download OCB.
46+ $installOcbCommand = " `$ env:GOBIN='$toolsDir '; `$ env:CGO_ENABLED=0; $goBin install -trimpath -ldflags='-s -w' go.opentelemetry.io/collector/cmd/[email protected] " 47+ powershell.exe - Command $installOcbCommand
48+ $ocbBin = " $toolsDir \builder.exe"
49+
50+ # Generate the collector source.
51+ $ocbGenerateCommand = " `$ env:PATH='${goBinDir} ;${PATH} '; `$ env:CGO_ENABLED=0; $ocbBin --skip-compilation --verbose --config manifest.yaml"
52+ powershell.exe - Command $ocbGenerateCommand
53+
54+ # Build the collector.
55+ $ldFlags = " -s -w"
56+ if ($jmxHash -ne " " ) {
57+ $ldFlags += " github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jmxreceiver.MetricsGathererHash=$jmxHash "
58+ }
59+ $collectorBinPath = " ${outDir} /bin/google-cloud-metrics-agent_windows_amd64.exe"
60+ $buildCollectorCommand = " `$ env:GOWORK='off'; cd _build; $goBin build -p 32 -buildvcs=false -o='${collectorBinPath} ' --ldflags='$ldFlags ' ."
61+ powershell.exe - Command $buildCollectorCommand
0 commit comments