Skip to content

Commit

Permalink
all: set CGO_ENABLED=0 when building snippets
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
toothrot committed Mar 2, 2021
1 parent 94eacb7 commit 6cd0363
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ func sandboxBuild(ctx context.Context, tmpDir string, in []byte, vet bool) (*bui
cmd.Dir = tmpDir
cmd.Env = []string{"GOOS=linux", "GOARCH=amd64", "GOROOT=/usr/local/go-faketime"}
cmd.Env = append(cmd.Env, "GOCACHE="+goCache)
cmd.Env = append(cmd.Env, "CGO_ENABLED=0")
// Create a GOPATH just for modules to be downloaded
// into GOPATH/pkg/mod.
cmd.Args = append(cmd.Args, "-modcacherw")
Expand Down
14 changes: 14 additions & 0 deletions tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,4 +567,18 @@ func main() {
}
`, want: "2012-07-09 05:02:00 +0200 CEST\n2012-07-09 00:00:00 +0200 CEST\n"},
{
name: "cgo_enabled_0",
prog: `
package main
import (
"fmt"
"net"
)
func main() {
fmt.Println(net.ParseIP("1.2.3.4"))
}
`, want: "1.2.3.4\n"},
}

0 comments on commit 6cd0363

Please sign in to comment.