Honor CGO_ENABLED environment variable (fix #17)

This commit is contained in:
Matthew Holt 2020-05-22 10:31:34 -06:00
parent 4ce3d1db07
commit a1e17ca9b9
No known key found for this signature in database
GPG key ID: 2A349DD577D586A5
3 changed files with 13 additions and 1 deletions

View file

@ -83,7 +83,7 @@ func (b Builder) Build(ctx context.Context, outputFile string) error {
env = setEnv(env, "GOOS="+b.OS)
env = setEnv(env, "GOARCH="+b.Arch)
env = setEnv(env, "GOARM="+b.ARM)
env = setEnv(env, fmt.Sprintf("CGO_ENABLED=%t", b.Cgo))
env = setEnv(env, fmt.Sprintf("CGO_ENABLED=%s", b.Compile.CgoEnabled()))
log.Println("[INFO] Building Caddy")

View file

@ -109,6 +109,9 @@ func runBuild(ctx context.Context, args []string) error {
// perform the build
builder := xcaddy.Builder{
Compile: xcaddy.Compile{
Cgo: os.Getenv("CGO_ENABLED") == "1",
},
CaddyVersion: caddyVersion,
Plugins: plugins,
Replacements: replacements,

View file

@ -11,6 +11,15 @@ type Compile struct {
Cgo bool `json:"cgo,omitempty"`
}
// CgoEnabled returns "1" if c.Cgo is true, "0" otherwise.
// This is used for setting the CGO_ENABLED env variable.
func (c Compile) CgoEnabled() string {
if c.Cgo {
return "1"
}
return "0"
}
// Platform represents a build target.
type Platform struct {
OS string `json:"os,omitempty"`