From 61467ca436eced749e0991f1fdf5b82fd8931627 Mon Sep 17 00:00:00 2001 From: Philipp Trulson Date: Fri, 3 Feb 2023 14:20:10 +0100 Subject: [PATCH 1/2] Add support for using PGO flag --- .github/workflows/ci.yaml | 2 +- cmd/buildutil/info.go | 2 ++ cmd/buildutil/runner.go | 5 +++++ examples/full/Dockerfile | 2 +- examples/full/go.mod | 2 +- examples/minimal/Dockerfile | 2 +- examples/minimal/go.mod | 2 +- go.mod | 2 +- 8 files changed, 13 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 208671e..c886fb3 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -19,7 +19,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v3 with: - go-version: '1.19' + go-version: '1.20' - name: Checkout code uses: actions/checkout@v3 with: diff --git a/cmd/buildutil/info.go b/cmd/buildutil/info.go index c618b7c..6a05aa1 100644 --- a/cmd/buildutil/info.go +++ b/cmd/buildutil/info.go @@ -207,6 +207,7 @@ type TargetInfo struct { Outfile string System SystemInfo CGO bool + PGO string } func CollectBuildInformation(ctx context.Context, p BuildParameters) (BuildInfo, error) { @@ -311,6 +312,7 @@ func CollectBuildInformation(ctx context.Context, p BuildParameters) (BuildInfo, Name: path.Base(pkg.PkgPath), System: targetSystem, CGO: p.CGO, + PGO: p.PGO, } if pkg.PkgPath == info.Go.Module { diff --git a/cmd/buildutil/runner.go b/cmd/buildutil/runner.go index 461bba6..fff5c54 100644 --- a/cmd/buildutil/runner.go +++ b/cmd/buildutil/runner.go @@ -48,6 +48,7 @@ type BuildParameters struct { GoCommand string CGO bool + PGO string } type Runner struct { @@ -81,6 +82,9 @@ func (r *Runner) Bind(cmd *cobra.Command) error { cmd.PersistentFlags().BoolVar( &r.Parameters.CGO, "cgo", false, "Enable CGO.") + cmd.PersistentFlags().StringVar( + &r.Parameters.PGO, "pgo", "off", + "Sets input for PGO option.") cmd.PersistentFlags().StringVar( &r.Parameters.GoCommand, "go-command", "go", "Which Go command to use.") @@ -214,6 +218,7 @@ func (r *Runner) RunBuild(ctx context.Context, cmd *cobra.Command, args []string call(ctx, r.Parameters.GoCommand, "build", "-o", r.dist(target.Outfile), "-ldflags", "-s -w "+strings.Join(ldFlags, " "), + "-pgo", target.PGO, target.Package) r.Inst.ReadSize(target.Outfile) diff --git a/examples/full/Dockerfile b/examples/full/Dockerfile index 357b52b..4ea13a3 100644 --- a/examples/full/Dockerfile +++ b/examples/full/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.19-alpine as builder +FROM golang:1.20-alpine as builder RUN apk add --no-cache git openssl diff --git a/examples/full/go.mod b/examples/full/go.mod index 56228c3..1956331 100644 --- a/examples/full/go.mod +++ b/examples/full/go.mod @@ -1,6 +1,6 @@ module github.com/rebuy-de/rebuy-go-sdk/v4/examples/full -go 1.19 +go 1.20 replace github.com/rebuy-de/rebuy-go-sdk/v4 => ../.. diff --git a/examples/minimal/Dockerfile b/examples/minimal/Dockerfile index 357b52b..4ea13a3 100644 --- a/examples/minimal/Dockerfile +++ b/examples/minimal/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.19-alpine as builder +FROM golang:1.20-alpine as builder RUN apk add --no-cache git openssl diff --git a/examples/minimal/go.mod b/examples/minimal/go.mod index 484357a..49625cb 100644 --- a/examples/minimal/go.mod +++ b/examples/minimal/go.mod @@ -1,6 +1,6 @@ module github.com/rebuy-de/rebuy-go-sdk/v4/examples/minimal -go 1.19 +go 1.20 replace github.com/rebuy-de/rebuy-go-sdk/v4 => ../.. diff --git a/go.mod b/go.mod index 23b7981..c781bfe 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/rebuy-de/rebuy-go-sdk/v4 -go 1.19 +go 1.20 require ( github.com/afiskon/promtail-client v0.0.0-20190305142237-506f3f921e9c From 712500d4bc1bbf308115132ed3beb3d16247901b Mon Sep 17 00:00:00 2001 From: Philipp Trulson Date: Fri, 3 Feb 2023 15:16:01 +0100 Subject: [PATCH 2/2] Only set PGO flag if value is set --- cmd/buildutil/runner.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/cmd/buildutil/runner.go b/cmd/buildutil/runner.go index fff5c54..fab6a8c 100644 --- a/cmd/buildutil/runner.go +++ b/cmd/buildutil/runner.go @@ -83,7 +83,7 @@ func (r *Runner) Bind(cmd *cobra.Command) error { &r.Parameters.CGO, "cgo", false, "Enable CGO.") cmd.PersistentFlags().StringVar( - &r.Parameters.PGO, "pgo", "off", + &r.Parameters.PGO, "pgo", "", "Sets input for PGO option.") cmd.PersistentFlags().StringVar( &r.Parameters.GoCommand, "go-command", "go", @@ -214,12 +214,20 @@ func (r *Runner) RunBuild(ctx context.Context, cmd *cobra.Command, args []string cmdutil.Must(os.Setenv("CGO_ENABLED", "0")) } - sw := r.Inst.Durations.Building.Stopwatch(target.Outfile) - call(ctx, r.Parameters.GoCommand, "build", + buildArgs := []string{ + "build", "-o", r.dist(target.Outfile), - "-ldflags", "-s -w "+strings.Join(ldFlags, " "), - "-pgo", target.PGO, - target.Package) + "-ldflags", "-s -w " + strings.Join(ldFlags, " "), + } + + if target.PGO != "" { + buildArgs = append(buildArgs, "-pgo", target.PGO) + } + + buildArgs = append(buildArgs, target.Package) + + sw := r.Inst.Durations.Building.Stopwatch(target.Outfile) + call(ctx, r.Parameters.GoCommand, buildArgs...) r.Inst.ReadSize(target.Outfile)