@@ -294,6 +294,54 @@ func (Build) GenerateConfig() error {
294294 return sh .Copy (filepath .Join (buildDir , configFile ), filepath .Join (metaDir , configFile ))
295295}
296296
297+ // WindowsArchiveRootBinary compiles a binary to be placed at the root of the windows elastic-agent archive. This binary
298+ // is a thin proxy to the actual elastic-agent binary that resides in the data/elastic-agent-{commit-short-sha}
299+ // directory of the archive.
300+ func (Build ) WindowsArchiveRootBinary () error {
301+ fmt .Println ("--- Compiling root binary for windows archive" )
302+ hashShort , err := devtools .CommitHashShort ()
303+ if err != nil {
304+ return fmt .Errorf ("error getting commit hash: %w" , err )
305+ }
306+
307+ outputName := "elastic-agent-archive-root"
308+ if runtime .GOOS != "windows" {
309+ // add the .exe extension on non-windows platforms
310+ outputName += ".exe"
311+ }
312+
313+ args := devtools.BuildArgs {
314+ Name : outputName ,
315+ OutputDir : filepath .Join (buildDir , "windows-archive-root-binary" ),
316+ InputFiles : []string {"hack/windows/archive-proxy/main.go" },
317+ CGO : false ,
318+ WinMetadata : true ,
319+ ExtraFlags : []string {
320+ "-buildmode" , "pie" , // windows versions inside the support matrix do support position independent code
321+ "-trimpath" , // Remove all file system paths from the compiled executable, to improve build reproducibility
322+ },
323+ Vars : map [string ]string {
324+ "main.CommitSHA" : hashShort ,
325+ },
326+ Env : map [string ]string {
327+ "GOOS" : "windows" ,
328+ "GOARCH" : "amd64" ,
329+ },
330+ LDFlags : []string {
331+ "-s" , // Strip all debug symbols from binary (does not affect Go stack traces).
332+ },
333+ }
334+
335+ if devtools .FIPSBuild {
336+ // there is no actual FIPS relevance for this particular binary
337+ // but better safe than sorry
338+ args .ExtraFlags = append (args .ExtraFlags , "-tags=requirefips" )
339+ args .CGO = true
340+ }
341+
342+ return devtools .Build (args )
343+ }
344+
297345// GolangCrossBuildOSS build the Beat binary inside of the golang-builder.
298346// Do not use directly, use crossBuild instead.
299347func GolangCrossBuildOSS () error {
@@ -1022,6 +1070,15 @@ func packageAgent(ctx context.Context, platforms []string, dependenciesVersion s
10221070 log .Println ("--- Running post packaging " )
10231071 mg .Deps (Update )
10241072 mg .Deps (agentBinaryTarget , CrossBuildGoDaemon )
1073+
1074+ // compile the elastic-agent.exe proxy binary for the windows archive
1075+ for _ , platform := range platforms {
1076+ if platform == "windows/amd64" {
1077+ mg .Deps (Build .WindowsArchiveRootBinary )
1078+ break
1079+ }
1080+ }
1081+
10251082 mg .SerialDeps (devtools .Package , TestPackages )
10261083 return nil
10271084}
0 commit comments