Skip to content

Commit a1e17ca

Browse files
committed
Honor CGO_ENABLED environment variable (fix #17)
1 parent 4ce3d1d commit a1e17ca

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

builder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func (b Builder) Build(ctx context.Context, outputFile string) error {
8383
env = setEnv(env, "GOOS="+b.OS)
8484
env = setEnv(env, "GOARCH="+b.Arch)
8585
env = setEnv(env, "GOARM="+b.ARM)
86-
env = setEnv(env, fmt.Sprintf("CGO_ENABLED=%t", b.Cgo))
86+
env = setEnv(env, fmt.Sprintf("CGO_ENABLED=%s", b.Compile.CgoEnabled()))
8787

8888
log.Println("[INFO] Building Caddy")
8989

cmd/xcaddy/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ func runBuild(ctx context.Context, args []string) error {
109109

110110
// perform the build
111111
builder := xcaddy.Builder{
112+
Compile: xcaddy.Compile{
113+
Cgo: os.Getenv("CGO_ENABLED") == "1",
114+
},
112115
CaddyVersion: caddyVersion,
113116
Plugins: plugins,
114117
Replacements: replacements,

platforms.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ type Compile struct {
1111
Cgo bool `json:"cgo,omitempty"`
1212
}
1313

14+
// CgoEnabled returns "1" if c.Cgo is true, "0" otherwise.
15+
// This is used for setting the CGO_ENABLED env variable.
16+
func (c Compile) CgoEnabled() string {
17+
if c.Cgo {
18+
return "1"
19+
}
20+
return "0"
21+
}
22+
1423
// Platform represents a build target.
1524
type Platform struct {
1625
OS string `json:"os,omitempty"`

0 commit comments

Comments
 (0)