Skip to content

Commit f7c5653

Browse files
authored
Go 1.9 support (version bump to GopherJS 1.9-1). (#651)
Merge pull request #651 from branch go1.9.
2 parents 95deb33 + fe63fb1 commit f7c5653

File tree

31 files changed

+664
-1232
lines changed

31 files changed

+664
-1232
lines changed

build/build.go

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,23 @@ func Import(path string, mode build.ImportMode, installSuffix string, buildTags
7373
}
7474

7575
func importWithSrcDir(path string, srcDir string, mode build.ImportMode, installSuffix string, buildTags []string) (*PackageData, error) {
76-
buildContext := NewBuildContext(installSuffix, buildTags)
77-
if path == "syscall" { // syscall needs to use a typical GOARCH like amd64 to pick up definitions for _Socklen, BpfInsn, IFNAMSIZ, Timeval, BpfStat, SYS_FCNTL, Flock_t, etc.
78-
buildContext.GOARCH = runtime.GOARCH
79-
buildContext.InstallSuffix = "js"
76+
bctx := NewBuildContext(installSuffix, buildTags)
77+
switch path {
78+
case "syscall":
79+
// syscall needs to use a typical GOARCH like amd64 to pick up definitions for _Socklen, BpfInsn, IFNAMSIZ, Timeval, BpfStat, SYS_FCNTL, Flock_t, etc.
80+
bctx.GOARCH = runtime.GOARCH
81+
bctx.InstallSuffix = "js"
8082
if installSuffix != "" {
81-
buildContext.InstallSuffix += "_" + installSuffix
83+
bctx.InstallSuffix += "_" + installSuffix
8284
}
85+
case "math/big":
86+
// Use pure Go version of math/big; we don't want non-Go assembly versions.
87+
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
8391
}
84-
pkg, err := buildContext.Import(path, srcDir, mode)
92+
pkg, err := bctx.Import(path, srcDir, mode)
8593
if err != nil {
8694
return nil, err
8795
}
@@ -93,17 +101,17 @@ func importWithSrcDir(path string, srcDir string, mode build.ImportMode, install
93101

94102
switch path {
95103
case "os":
96-
pkg.GoFiles = stripExecutable(pkg.GoFiles) // Need to strip executable implementation files, because some of them contain package scope variables that perform (indirectly) syscalls on init.
104+
pkg.GoFiles = excludeExecutable(pkg.GoFiles) // Need to exclude executable implementation files, because some of them contain package scope variables that perform (indirectly) syscalls on init.
97105
case "runtime":
98106
pkg.GoFiles = []string{"error.go"}
99107
case "runtime/internal/sys":
100-
pkg.GoFiles = []string{fmt.Sprintf("zgoos_%s.go", buildContext.GOOS), "zversion.go"}
108+
pkg.GoFiles = []string{fmt.Sprintf("zgoos_%s.go", bctx.GOOS), "zversion.go"}
101109
case "runtime/pprof":
102110
pkg.GoFiles = nil
111+
case "internal/poll":
112+
pkg.GoFiles = exclude(pkg.GoFiles, "fd_poll_runtime.go")
103113
case "crypto/rand":
104114
pkg.GoFiles = []string{"rand.go", "util.go"}
105-
case "crypto/x509":
106-
pkg.CgoFiles = nil
107115
}
108116

109117
if len(pkg.CgoFiles) > 0 {
@@ -131,9 +139,9 @@ func importWithSrcDir(path string, srcDir string, mode build.ImportMode, install
131139
return &PackageData{Package: pkg, JSFiles: jsFiles}, nil
132140
}
133141

134-
// stripExecutable strips all executable implementation .go files.
142+
// excludeExecutable excludes all executable implementation .go files.
135143
// They have "executable_" prefix.
136-
func stripExecutable(goFiles []string) []string {
144+
func excludeExecutable(goFiles []string) []string {
137145
var s []string
138146
for _, f := range goFiles {
139147
if strings.HasPrefix(f, "executable_") {
@@ -144,6 +152,21 @@ func stripExecutable(goFiles []string) []string {
144152
return s
145153
}
146154

155+
// exclude returns files, excluding specified files.
156+
func exclude(files []string, exclude ...string) []string {
157+
var s []string
158+
Outer:
159+
for _, f := range files {
160+
for _, e := range exclude {
161+
if f == e {
162+
continue Outer
163+
}
164+
}
165+
s = append(s, f)
166+
}
167+
return s
168+
}
169+
147170
// ImportDir is like Import but processes the Go package found in the named
148171
// directory.
149172
func ImportDir(dir string, mode build.ImportMode, installSuffix string, buildTags []string) (*PackageData, error) {

circle.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ machine:
66

77
dependencies:
88
pre:
9-
- cd /usr/local && sudo rm -rf go && curl https://storage.googleapis.com/golang/go1.8.linux-amd64.tar.gz | sudo tar -xz && sudo chmod a+w go/src/path/filepath
9+
- cd /usr/local && sudo rm -rf go && curl https://storage.googleapis.com/golang/go1.9.linux-amd64.tar.gz | sudo tar -xz && sudo chmod a+w go/src/path/filepath
1010
post:
1111
- mv ./gopherjs $HOME/bin
1212
- npm install --global node-gyp
@@ -17,8 +17,10 @@ test:
1717
- diff -u <(echo -n) <(gofmt -d .)
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".
20+
- 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).
2022
- >
21-
gopherjs test --short --minify
23+
gopherjs test --minify -v --short
2224
github.com/gopherjs/gopherjs/tests
2325
github.com/gopherjs/gopherjs/tests/main
2426
github.com/gopherjs/gopherjs/js
@@ -96,6 +98,7 @@ test:
9698
io/ioutil
9799
math
98100
math/big
101+
math/bits
99102
math/cmplx
100103
math/rand
101104
mime
@@ -107,6 +110,7 @@ test:
107110
net/rpc/jsonrpc
108111
net/textproto
109112
net/url
113+
os/user
110114
path
111115
path/filepath
112116
reflect
@@ -127,3 +131,4 @@ test:
127131
unicode/utf16
128132
unicode/utf8
129133
- go test -v -race ./...
134+
- gopherjs test -v fmt # No minification should work.

compiler/compiler.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ import (
1212
"strings"
1313

1414
"github.com/gopherjs/gopherjs/compiler/prelude"
15-
"github.com/gopherjs/gopherjs/third_party/importer"
15+
"golang.org/x/tools/go/gcimporter15"
1616
)
1717

1818
var sizes32 = &types.StdSizes{WordSize: 4, MaxAlign: 8}
1919
var reservedKeywords = make(map[string]bool)
20-
var _ = ___GOPHERJS_REQUIRES_GO_VERSION_1_8___ // Compile error on other Go versions, because they're not supported.
20+
var _ = ___GOPHERJS_REQUIRES_GO_VERSION_1_9___ // Compile error on other Go versions, because they're not supported.
2121

2222
func init() {
2323
for _, keyword := range []string{"abstract", "arguments", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue", "debugger", "default", "delete", "do", "double", "else", "enum", "eval", "export", "extends", "false", "final", "finally", "float", "for", "function", "goto", "if", "implements", "import", "in", "instanceof", "int", "interface", "let", "long", "native", "new", "null", "package", "private", "protected", "public", "return", "short", "static", "super", "switch", "synchronized", "this", "throw", "throws", "transient", "true", "try", "typeof", "undefined", "var", "void", "volatile", "while", "with", "yield"} {
@@ -239,7 +239,7 @@ func ReadArchive(filename, path string, r io.Reader, packages map[string]*types.
239239
}
240240

241241
var err error
242-
_, packages[path], err = importer.ImportData(packages, a.ExportData)
242+
_, packages[path], err = gcimporter.BImportData(token.NewFileSet(), packages, a.ExportData, path)
243243
if err != nil {
244244
return nil, err
245245
}

compiler/natives/fs_vfsdata.go

Lines changed: 170 additions & 111 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler/natives/src/crypto/x509/x509.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,8 @@
22

33
package x509
44

5-
import "os"
5+
import "errors"
66

77
func loadSystemRoots() (*CertPool, error) {
8-
// no system roots
9-
return NewCertPool(), nil
10-
}
11-
12-
func execSecurityRoots() (*CertPool, error) {
13-
return nil, os.ErrNotExist
8+
return nil, errors.New("crypto/x509: system root pool is not available in GopherJS")
149
}

compiler/natives/src/crypto/x509/x509_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,18 @@ package x509
44

55
import "testing"
66

7+
func TestSystemCertPool(t *testing.T) {
8+
t.Skip("no system roots")
9+
}
10+
711
func TestSystemRoots(t *testing.T) {
812
t.Skip("no system roots")
913
}
1014

15+
func TestEnvVars(t *testing.T) {
16+
t.Skip("no system roots")
17+
}
18+
1119
func TestSystemVerify(t *testing.T) {
1220
t.Skip("no system")
1321
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// +build js
2+
3+
package gob
4+
5+
import (
6+
"bytes"
7+
"reflect"
8+
"testing"
9+
)
10+
11+
// TODO: TestEndToEnd override can be removed once the bug with Marr field is fixed.
12+
func TestEndToEnd(t *testing.T) {
13+
type T2 struct {
14+
T string
15+
}
16+
type T3 struct {
17+
X float64
18+
Z *int
19+
}
20+
type T1 struct {
21+
A, B, C int
22+
M map[string]*float64
23+
M2 map[int]T3
24+
Mstring map[string]string
25+
Mintptr map[int]*int
26+
Mcomp map[complex128]complex128
27+
Marr map[[2]string][2]*float64
28+
EmptyMap map[string]int // to check that we receive a non-nil map.
29+
N *[3]float64
30+
Strs *[2]string
31+
Int64s *[]int64
32+
RI complex64
33+
S string
34+
Y []byte
35+
T *T2
36+
}
37+
pi := 3.14159
38+
e := 2.71828
39+
two := 2.0
40+
meaning := 42
41+
fingers := 5
42+
s1 := "string1"
43+
s2 := "string2"
44+
var comp1 complex128 = complex(1.0, 1.0)
45+
var comp2 complex128 = complex(1.0, 1.0)
46+
var arr1 [2]string
47+
arr1[0] = s1
48+
arr1[1] = s2
49+
var arr2 [2]string
50+
arr2[0] = s2
51+
arr2[1] = s1
52+
var floatArr1 [2]*float64
53+
floatArr1[0] = &pi
54+
floatArr1[1] = &e
55+
var floatArr2 [2]*float64
56+
floatArr2[0] = &e
57+
floatArr2[1] = &two
58+
t1 := &T1{
59+
A: 17,
60+
B: 18,
61+
C: -5,
62+
M: map[string]*float64{"pi": &pi, "e": &e},
63+
M2: map[int]T3{4: T3{X: pi, Z: &meaning}, 10: T3{X: e, Z: &fingers}},
64+
Mstring: map[string]string{"pi": "3.14", "e": "2.71"},
65+
Mintptr: map[int]*int{meaning: &fingers, fingers: &meaning},
66+
Mcomp: map[complex128]complex128{comp1: comp2, comp2: comp1},
67+
// TODO: Fix this problem:
68+
// TypeError: dst.$set is not a function
69+
// at typedmemmove (/github.com/gopherjs/gopherjs/reflect.go:487:3)
70+
//Marr: map[[2]string][2]*float64{arr1: floatArr1, arr2: floatArr2},
71+
EmptyMap: make(map[string]int),
72+
N: &[3]float64{1.5, 2.5, 3.5},
73+
Strs: &[2]string{s1, s2},
74+
Int64s: &[]int64{77, 89, 123412342134},
75+
RI: 17 - 23i,
76+
S: "Now is the time",
77+
Y: []byte("hello, sailor"),
78+
T: &T2{"this is T2"},
79+
}
80+
b := new(bytes.Buffer)
81+
err := NewEncoder(b).Encode(t1)
82+
if err != nil {
83+
t.Error("encode:", err)
84+
}
85+
var _t1 T1
86+
err = NewDecoder(b).Decode(&_t1)
87+
if err != nil {
88+
t.Fatal("decode:", err)
89+
}
90+
if !reflect.DeepEqual(t1, &_t1) {
91+
t.Errorf("encode expected %v got %v", *t1, _t1)
92+
}
93+
// Be absolutely sure the received map is non-nil.
94+
if t1.EmptyMap == nil {
95+
t.Errorf("nil map sent")
96+
}
97+
if _t1.EmptyMap == nil {
98+
t.Errorf("nil map received")
99+
}
100+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// +build js
2+
3+
package poll
4+
5+
import "time"
6+
7+
// pollDesc is a no-op implementation of an I/O poller for GOARCH=js.
8+
//
9+
// Its implementation is based on NaCL in gc compiler (see GOROOT/src/internal/poll/fd_poll_nacl.go),
10+
// but it does even less.
11+
type pollDesc struct {
12+
closing bool
13+
}
14+
15+
func (pd *pollDesc) init(fd *FD) error { return nil }
16+
17+
func (pd *pollDesc) close() {}
18+
19+
func (pd *pollDesc) evict() { pd.closing = true }
20+
21+
func (pd *pollDesc) prepare(mode int, isFile bool) error {
22+
if pd.closing {
23+
return errClosing(isFile)
24+
}
25+
return nil
26+
}
27+
28+
func (pd *pollDesc) prepareRead(isFile bool) error { return pd.prepare('r', isFile) }
29+
30+
func (pd *pollDesc) prepareWrite(isFile bool) error { return pd.prepare('w', isFile) }
31+
32+
func (pd *pollDesc) wait(mode int, isFile bool) error {
33+
if pd.closing {
34+
return errClosing(isFile)
35+
}
36+
return ErrTimeout
37+
}
38+
39+
func (pd *pollDesc) waitRead(isFile bool) error { return pd.wait('r', isFile) }
40+
41+
func (pd *pollDesc) waitWrite(isFile bool) error { return pd.wait('w', isFile) }
42+
43+
func (*pollDesc) waitCanceled(mode int) {}
44+
45+
func (*pollDesc) pollable() bool { return true }
46+
47+
func (*FD) SetDeadline(t time.Time) error { return nil }
48+
49+
func (*FD) SetReadDeadline(t time.Time) error { return nil }
50+
51+
func (*FD) SetWriteDeadline(t time.Time) error { return nil }
52+
53+
// PollDescriptor returns the descriptor being used by the poller,
54+
// or ^uintptr(0) if there isn't one. This is only used for testing.
55+
func PollDescriptor() uintptr {
56+
return ^uintptr(0)
57+
}

compiler/natives/src/math/big/big.go

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,6 @@
22

33
package big
44

5-
func mulWW(x, y Word) (z1, z0 Word) {
6-
return mulWW_g(x, y)
7-
}
8-
func divWW(x1, x0, y Word) (q, r Word) {
9-
return divWW_g(x1, x0, y)
10-
}
11-
func addVV(z, x, y []Word) (c Word) {
12-
return addVV_g(z, x, y)
13-
}
14-
func subVV(z, x, y []Word) (c Word) {
15-
return subVV_g(z, x, y)
16-
}
17-
func addVW(z, x []Word, y Word) (c Word) {
18-
return addVW_g(z, x, y)
19-
}
20-
func subVW(z, x []Word, y Word) (c Word) {
21-
return subVW_g(z, x, y)
22-
}
23-
func shlVU(z, x []Word, s uint) (c Word) {
24-
return shlVU_g(z, x, s)
25-
}
26-
func shrVU(z, x []Word, s uint) (c Word) {
27-
return shrVU_g(z, x, s)
28-
}
29-
func mulAddVWW(z, x []Word, y, r Word) (c Word) {
30-
return mulAddVWW_g(z, x, y, r)
31-
}
32-
func addMulVVW(z, x []Word, y Word) (c Word) {
33-
return addMulVVW_g(z, x, y)
34-
}
35-
func divWVW(z []Word, xn Word, x []Word, y Word) (r Word) {
36-
return divWVW_g(z, xn, x, y)
37-
}
38-
func bitLen(x Word) (n int) {
39-
return bitLen_g(x)
40-
}
5+
// TODO: This is a workaround for https://github.com/gopherjs/gopherjs/issues/652.
6+
// Remove after that issue is resolved.
7+
type Word uintptr

0 commit comments

Comments
 (0)