Skip to content

Commit

Permalink
feat: Fill in CC and CXX environment variables for package comm…
Browse files Browse the repository at this point in the history
…and (#1637)

Based on cloudquery/cloudquery#17693 as well as our `gencc.sh` & `gencpp.sh` files.

Reasoning: previously we used GoReleaser to call the `gencc.sh` & `gencpp.sh` scripts to determine the `CC` & `CXX` variables values. Now we have to fill this info manually during packaging.
  • Loading branch information
candiduslynx authored Apr 19, 2024
1 parent 91c7a55 commit c0282e1
Showing 1 changed file with 32 additions and 11 deletions.
43 changes: 32 additions & 11 deletions plugin/plugin_package.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package plugin

import "errors"
import (
"errors"
)

const (
GoOSLinux = "linux"
Expand Down Expand Up @@ -41,17 +43,36 @@ type BuildTarget struct {
}

func (t BuildTarget) EnvVariables() []string {
cgo := "CGO_ENABLED="
if t.CGO {
cgo += "1"
} else {
cgo += "0"
variables := append(t.cgoEnvVariables(), "GOOS="+t.OS, "GOARCH="+t.Arch)
return append(variables, t.Env...)
}

func (t BuildTarget) cgoEnvVariables() []string {
// default is to tool at the param. Can be overridden by adding `CGO_ENABLED=1` to BuildTarget.Env
if !t.CGO {
return []string{"CGO_ENABLED=0"}
}

switch t.OS {
case GoOSWindows:
return []string{"CGO_ENABLED=1", "CC=x86_64-w64-mingw32-gcc", "CXX=x86_64-w64-mingw32-g++"}
case GoOSDarwin:
return []string{"CGO_ENABLED=1", "CC=o64-clang", "CXX=o64-clang++"}
case GoOSLinux:
// nop, see below
default:
return []string{"CGO_ENABLED=1"}
}

// linux
switch t.Arch {
case GoArchAmd64:
return []string{"CGO_ENABLED=1", "CC=gcc", "CXX=g++"}
case GoArchArm64:
return []string{"CGO_ENABLED=1", "CC=aarch64-linux-gnu-gcc", "CXX=aarch64-linux-gnu-g++"}
default:
return []string{"CGO_ENABLED=1"}
}
return append([]string{
"GOOS=" + t.OS,
"GOARCH=" + t.Arch,
cgo, // default is to tool at the param. Can be overridden by adding `CGO_ENABLED=1` to BuildTarget.Env
}, t.Env...)
}

var DefaultBuildTargets = []BuildTarget{
Expand Down

1 comment on commit c0282e1

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⏱️ Benchmark results

  • Glob-8 ns/op: 92.25

Please sign in to comment.