Permalink
Browse files

build: Don't use cgo for "os/user", "crypto/x509".

This changes fixes GopherJS ability to build os/user package. In turn,
this change also fixes crypto/x509 and net/http on darwin. The goal is
to ensure that os/user builds without errors, because it may end up
being imported by some stdlib packages (e.g., crypto/x509 on darwin
in Go 1.9).

This is accomplished by disabling cgo for these standard library
packages. Normally, GopherJS build context enables cgo for the purpose
of catching when a user package uses cgo and reporting that:

	CgoEnabled: true, // detect `import "C"` to throw proper error
	...
	if len(pkg.CgoFiles) > 0 {
		return nil, &ImportCError{path}
	}

But we don't want to use cgo for standard library packages. They have
support for building without cgo by using !cgo build constraints, which
we want to activate. Setting bctxt.CgoEnabled to false achieves that.

Add to CI a test of os/user package for gopherjs, as well as ensure
net/http builds successfully. We can't run its tests because there
are too many and they require the HTTP server, but only client is
implemented in GopherJS.

Fixes #664.
  • Loading branch information...
dmitshur committed Jul 27, 2017
1 parent 6759a49 commit 00a3767085dffc9baa5e1c320b28e3629a56d323
Showing with 5 additions and 2 deletions.
  1. +3 −2 build/build.go
  2. +2 −0 circle.yml
View
@@ -85,6 +85,9 @@ func importWithSrcDir(path string, srcDir string, mode build.ImportMode, install
case "math/big":
// Use pure Go version of math/big; we don't want non-Go assembly versions.
bctx.BuildTags = append(bctx.BuildTags, "math_big_pure_go")
case "crypto/x509", "os/user":
// These stdlib packages have cgo and non-cgo versions (via build tags); we want the latter.
bctx.CgoEnabled = false
}
pkg, err := bctx.Import(path, srcDir, mode)
if err != nil {
@@ -109,8 +112,6 @@ func importWithSrcDir(path string, srcDir string, mode build.ImportMode, install
pkg.GoFiles = exclude(pkg.GoFiles, "fd_poll_runtime.go")
case "crypto/rand":
pkg.GoFiles = []string{"rand.go", "util.go"}
case "crypto/x509":
pkg.CgoFiles = nil
}
if len(pkg.CgoFiles) > 0 {
View
@@ -18,6 +18,7 @@ test:
- go tool vet *.go # Go package in root directory.
- for d in */; do echo $d; done | grep -v tests/ | grep -v third_party/ | xargs go tool vet # All subdirectories except "tests", "third_party".
- diff -u <(echo -n) <(go list ./compiler/natives/src/...) # All those packages should have // +build js.
- gopherjs install -v net/http # Should build successfully (can't run tests, since only client is supported).
- >
gopherjs test -v --short
github.com/gopherjs/gopherjs/tests
@@ -108,6 +109,7 @@ test:
net/rpc/jsonrpc
net/textproto
net/url
os/user
path
path/filepath
reflect

0 comments on commit 00a3767

Please sign in to comment.