Skip to content

Commit 6cd0363

Browse files
committed
all: set CGO_ENABLED=0 when building snippets
GCC has never been available to our build step of the Playground. Historically, the Playground always built programs with faketime, and relied on patches for sandboxing in NaCL. In the future, we could enable CGO programs to be built and run safely in the gVisor sandbox. In the meantime, this fixes trivial snippets that rely on CGO parts of std. Fixes golang/go#44714 Change-Id: If0e8b89f3c47bc080954dbd504d9de38295c16e2 Reviewed-on: https://go-review.googlesource.com/c/playground/+/297636 Trust: Alexander Rakoczy <[email protected]> Run-TryBot: Alexander Rakoczy <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]>
1 parent 94eacb7 commit 6cd0363

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

sandbox.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ func sandboxBuild(ctx context.Context, tmpDir string, in []byte, vet bool) (*bui
468468
cmd.Dir = tmpDir
469469
cmd.Env = []string{"GOOS=linux", "GOARCH=amd64", "GOROOT=/usr/local/go-faketime"}
470470
cmd.Env = append(cmd.Env, "GOCACHE="+goCache)
471+
cmd.Env = append(cmd.Env, "CGO_ENABLED=0")
471472
// Create a GOPATH just for modules to be downloaded
472473
// into GOPATH/pkg/mod.
473474
cmd.Args = append(cmd.Args, "-modcacherw")

tests.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,4 +567,18 @@ func main() {
567567
568568
}
569569
`, want: "2012-07-09 05:02:00 +0200 CEST\n2012-07-09 00:00:00 +0200 CEST\n"},
570+
{
571+
name: "cgo_enabled_0",
572+
prog: `
573+
package main
574+
575+
import (
576+
"fmt"
577+
"net"
578+
)
579+
580+
func main() {
581+
fmt.Println(net.ParseIP("1.2.3.4"))
582+
}
583+
`, want: "1.2.3.4\n"},
570584
}

0 commit comments

Comments
 (0)