Skip to content

Commit 00a3767

Browse files
committed
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.
1 parent 6759a49 commit 00a3767

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

build/build.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ func importWithSrcDir(path string, srcDir string, mode build.ImportMode, install
8585
case "math/big":
8686
// Use pure Go version of math/big; we don't want non-Go assembly versions.
8787
bctx.BuildTags = append(bctx.BuildTags, "math_big_pure_go")
88+
case "crypto/x509", "os/user":
89+
// These stdlib packages have cgo and non-cgo versions (via build tags); we want the latter.
90+
bctx.CgoEnabled = false
8891
}
8992
pkg, err := bctx.Import(path, srcDir, mode)
9093
if err != nil {
@@ -109,8 +112,6 @@ func importWithSrcDir(path string, srcDir string, mode build.ImportMode, install
109112
pkg.GoFiles = exclude(pkg.GoFiles, "fd_poll_runtime.go")
110113
case "crypto/rand":
111114
pkg.GoFiles = []string{"rand.go", "util.go"}
112-
case "crypto/x509":
113-
pkg.CgoFiles = nil
114115
}
115116

116117
if len(pkg.CgoFiles) > 0 {

circle.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ test:
1818
- go tool vet *.go # Go package in root directory.
1919
- for d in */; do echo $d; done | grep -v tests/ | grep -v third_party/ | xargs go tool vet # All subdirectories except "tests", "third_party".
2020
- diff -u <(echo -n) <(go list ./compiler/natives/src/...) # All those packages should have // +build js.
21+
- gopherjs install -v net/http # Should build successfully (can't run tests, since only client is supported).
2122
- >
2223
gopherjs test -v --short
2324
github.com/gopherjs/gopherjs/tests
@@ -108,6 +109,7 @@ test:
108109
net/rpc/jsonrpc
109110
net/textproto
110111
net/url
112+
os/user
111113
path
112114
path/filepath
113115
reflect

0 commit comments

Comments
 (0)