Skip to content

Commit

Permalink
Honor CGO_ENABLED environment variable (fix #17)
Browse files Browse the repository at this point in the history
  • Loading branch information
mholt committed May 22, 2020
1 parent 4ce3d1d commit a1e17ca
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
3 changes: 3 additions & 0 deletions cmd/xcaddy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions platforms.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down

0 comments on commit a1e17ca

Please sign in to comment.