Skip to content

Commit

Permalink
Merge pull request #140 from rebuy-de/allow-using-pgo-flag
Browse files Browse the repository at this point in the history
Add support for using PGO flag
  • Loading branch information
der-eismann authored Feb 3, 2023
2 parents d30e78d + 712500d commit 66c2c25
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions cmd/buildutil/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ type TargetInfo struct {
Outfile string
System SystemInfo
CGO bool
PGO string
}

func CollectBuildInformation(ctx context.Context, p BuildParameters) (BuildInfo, error) {
Expand Down Expand Up @@ -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 {
Expand Down
21 changes: 17 additions & 4 deletions cmd/buildutil/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type BuildParameters struct {
GoCommand string

CGO bool
PGO string
}

type Runner struct {
Expand Down Expand Up @@ -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", "",
"Sets input for PGO option.")
cmd.PersistentFlags().StringVar(
&r.Parameters.GoCommand, "go-command", "go",
"Which Go command to use.")
Expand Down Expand Up @@ -210,11 +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, " "),
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)

Expand Down
2 changes: 1 addition & 1 deletion examples/full/Dockerfile
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion examples/full/go.mod
Original file line number Diff line number Diff line change
@@ -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 => ../..

Expand Down
2 changes: 1 addition & 1 deletion examples/minimal/Dockerfile
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion examples/minimal/go.mod
Original file line number Diff line number Diff line change
@@ -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 => ../..

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 66c2c25

Please sign in to comment.