Skip to content

Commit

Permalink
Go 1.9 support (version bump to GopherJS 1.9-1). (gopherjs#651)
Browse files Browse the repository at this point in the history
Merge pull request gopherjs#651 from branch go1.9.
  • Loading branch information
dmitshur authored Aug 27, 2017
2 parents 95deb33 + fe63fb1 commit f7c5653
Show file tree
Hide file tree
Showing 31 changed files with 664 additions and 1,232 deletions.
47 changes: 35 additions & 12 deletions build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,23 @@ func Import(path string, mode build.ImportMode, installSuffix string, buildTags
}

func importWithSrcDir(path string, srcDir string, mode build.ImportMode, installSuffix string, buildTags []string) (*PackageData, error) {
buildContext := NewBuildContext(installSuffix, buildTags)
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.
buildContext.GOARCH = runtime.GOARCH
buildContext.InstallSuffix = "js"
bctx := NewBuildContext(installSuffix, buildTags)
switch path {
case "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.
bctx.GOARCH = runtime.GOARCH
bctx.InstallSuffix = "js"
if installSuffix != "" {
buildContext.InstallSuffix += "_" + installSuffix
bctx.InstallSuffix += "_" + installSuffix
}
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 := buildContext.Import(path, srcDir, mode)
pkg, err := bctx.Import(path, srcDir, mode)
if err != nil {
return nil, err
}
Expand All @@ -93,17 +101,17 @@ func importWithSrcDir(path string, srcDir string, mode build.ImportMode, install

switch path {
case "os":
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.
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.
case "runtime":
pkg.GoFiles = []string{"error.go"}
case "runtime/internal/sys":
pkg.GoFiles = []string{fmt.Sprintf("zgoos_%s.go", buildContext.GOOS), "zversion.go"}
pkg.GoFiles = []string{fmt.Sprintf("zgoos_%s.go", bctx.GOOS), "zversion.go"}
case "runtime/pprof":
pkg.GoFiles = nil
case "internal/poll":
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 {
Expand Down Expand Up @@ -131,9 +139,9 @@ func importWithSrcDir(path string, srcDir string, mode build.ImportMode, install
return &PackageData{Package: pkg, JSFiles: jsFiles}, nil
}

// stripExecutable strips all executable implementation .go files.
// excludeExecutable excludes all executable implementation .go files.
// They have "executable_" prefix.
func stripExecutable(goFiles []string) []string {
func excludeExecutable(goFiles []string) []string {
var s []string
for _, f := range goFiles {
if strings.HasPrefix(f, "executable_") {
Expand All @@ -144,6 +152,21 @@ func stripExecutable(goFiles []string) []string {
return s
}

// exclude returns files, excluding specified files.
func exclude(files []string, exclude ...string) []string {
var s []string
Outer:
for _, f := range files {
for _, e := range exclude {
if f == e {
continue Outer
}
}
s = append(s, f)
}
return s
}

// ImportDir is like Import but processes the Go package found in the named
// directory.
func ImportDir(dir string, mode build.ImportMode, installSuffix string, buildTags []string) (*PackageData, error) {
Expand Down
9 changes: 7 additions & 2 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ machine:

dependencies:
pre:
- 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
- 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
post:
- mv ./gopherjs $HOME/bin
- npm install --global node-gyp
Expand All @@ -17,8 +17,10 @@ test:
- diff -u <(echo -n) <(gofmt -d .)
- 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 --short --minify
gopherjs test --minify -v --short
github.com/gopherjs/gopherjs/tests
github.com/gopherjs/gopherjs/tests/main
github.com/gopherjs/gopherjs/js
Expand Down Expand Up @@ -96,6 +98,7 @@ test:
io/ioutil
math
math/big
math/bits
math/cmplx
math/rand
mime
Expand All @@ -107,6 +110,7 @@ test:
net/rpc/jsonrpc
net/textproto
net/url
os/user
path
path/filepath
reflect
Expand All @@ -127,3 +131,4 @@ test:
unicode/utf16
unicode/utf8
- go test -v -race ./...
- gopherjs test -v fmt # No minification should work.
6 changes: 3 additions & 3 deletions compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import (
"strings"

"github.com/gopherjs/gopherjs/compiler/prelude"
"github.com/gopherjs/gopherjs/third_party/importer"
"golang.org/x/tools/go/gcimporter15"
)

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

func init() {
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"} {
Expand Down Expand Up @@ -239,7 +239,7 @@ func ReadArchive(filename, path string, r io.Reader, packages map[string]*types.
}

var err error
_, packages[path], err = importer.ImportData(packages, a.ExportData)
_, packages[path], err = gcimporter.BImportData(token.NewFileSet(), packages, a.ExportData, path)
if err != nil {
return nil, err
}
Expand Down
281 changes: 170 additions & 111 deletions compiler/natives/fs_vfsdata.go

Large diffs are not rendered by default.

9 changes: 2 additions & 7 deletions compiler/natives/src/crypto/x509/x509.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@

package x509

import "os"
import "errors"

func loadSystemRoots() (*CertPool, error) {
// no system roots
return NewCertPool(), nil
}

func execSecurityRoots() (*CertPool, error) {
return nil, os.ErrNotExist
return nil, errors.New("crypto/x509: system root pool is not available in GopherJS")
}
8 changes: 8 additions & 0 deletions compiler/natives/src/crypto/x509/x509_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@ package x509

import "testing"

func TestSystemCertPool(t *testing.T) {
t.Skip("no system roots")
}

func TestSystemRoots(t *testing.T) {
t.Skip("no system roots")
}

func TestEnvVars(t *testing.T) {
t.Skip("no system roots")
}

func TestSystemVerify(t *testing.T) {
t.Skip("no system")
}
Expand Down
100 changes: 100 additions & 0 deletions compiler/natives/src/encoding/gob/gob_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// +build js

package gob

import (
"bytes"
"reflect"
"testing"
)

// TODO: TestEndToEnd override can be removed once the bug with Marr field is fixed.
func TestEndToEnd(t *testing.T) {
type T2 struct {
T string
}
type T3 struct {
X float64
Z *int
}
type T1 struct {
A, B, C int
M map[string]*float64
M2 map[int]T3
Mstring map[string]string
Mintptr map[int]*int
Mcomp map[complex128]complex128
Marr map[[2]string][2]*float64
EmptyMap map[string]int // to check that we receive a non-nil map.
N *[3]float64
Strs *[2]string
Int64s *[]int64
RI complex64
S string
Y []byte
T *T2
}
pi := 3.14159
e := 2.71828
two := 2.0
meaning := 42
fingers := 5
s1 := "string1"
s2 := "string2"
var comp1 complex128 = complex(1.0, 1.0)
var comp2 complex128 = complex(1.0, 1.0)
var arr1 [2]string
arr1[0] = s1
arr1[1] = s2
var arr2 [2]string
arr2[0] = s2
arr2[1] = s1
var floatArr1 [2]*float64
floatArr1[0] = &pi
floatArr1[1] = &e
var floatArr2 [2]*float64
floatArr2[0] = &e
floatArr2[1] = &two
t1 := &T1{
A: 17,
B: 18,
C: -5,
M: map[string]*float64{"pi": &pi, "e": &e},
M2: map[int]T3{4: T3{X: pi, Z: &meaning}, 10: T3{X: e, Z: &fingers}},
Mstring: map[string]string{"pi": "3.14", "e": "2.71"},
Mintptr: map[int]*int{meaning: &fingers, fingers: &meaning},
Mcomp: map[complex128]complex128{comp1: comp2, comp2: comp1},
// TODO: Fix this problem:
// TypeError: dst.$set is not a function
// at typedmemmove (/github.com/gopherjs/gopherjs/reflect.go:487:3)
//Marr: map[[2]string][2]*float64{arr1: floatArr1, arr2: floatArr2},
EmptyMap: make(map[string]int),
N: &[3]float64{1.5, 2.5, 3.5},
Strs: &[2]string{s1, s2},
Int64s: &[]int64{77, 89, 123412342134},
RI: 17 - 23i,
S: "Now is the time",
Y: []byte("hello, sailor"),
T: &T2{"this is T2"},
}
b := new(bytes.Buffer)
err := NewEncoder(b).Encode(t1)
if err != nil {
t.Error("encode:", err)
}
var _t1 T1
err = NewDecoder(b).Decode(&_t1)
if err != nil {
t.Fatal("decode:", err)
}
if !reflect.DeepEqual(t1, &_t1) {
t.Errorf("encode expected %v got %v", *t1, _t1)
}
// Be absolutely sure the received map is non-nil.
if t1.EmptyMap == nil {
t.Errorf("nil map sent")
}
if _t1.EmptyMap == nil {
t.Errorf("nil map received")
}
}
57 changes: 57 additions & 0 deletions compiler/natives/src/internal/poll/fd_poll_js.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// +build js

package poll

import "time"

// pollDesc is a no-op implementation of an I/O poller for GOARCH=js.
//
// Its implementation is based on NaCL in gc compiler (see GOROOT/src/internal/poll/fd_poll_nacl.go),
// but it does even less.
type pollDesc struct {
closing bool
}

func (pd *pollDesc) init(fd *FD) error { return nil }

func (pd *pollDesc) close() {}

func (pd *pollDesc) evict() { pd.closing = true }

func (pd *pollDesc) prepare(mode int, isFile bool) error {
if pd.closing {
return errClosing(isFile)
}
return nil
}

func (pd *pollDesc) prepareRead(isFile bool) error { return pd.prepare('r', isFile) }

func (pd *pollDesc) prepareWrite(isFile bool) error { return pd.prepare('w', isFile) }

func (pd *pollDesc) wait(mode int, isFile bool) error {
if pd.closing {
return errClosing(isFile)
}
return ErrTimeout
}

func (pd *pollDesc) waitRead(isFile bool) error { return pd.wait('r', isFile) }

func (pd *pollDesc) waitWrite(isFile bool) error { return pd.wait('w', isFile) }

func (*pollDesc) waitCanceled(mode int) {}

func (*pollDesc) pollable() bool { return true }

func (*FD) SetDeadline(t time.Time) error { return nil }

func (*FD) SetReadDeadline(t time.Time) error { return nil }

func (*FD) SetWriteDeadline(t time.Time) error { return nil }

// PollDescriptor returns the descriptor being used by the poller,
// or ^uintptr(0) if there isn't one. This is only used for testing.
func PollDescriptor() uintptr {
return ^uintptr(0)
}
39 changes: 3 additions & 36 deletions compiler/natives/src/math/big/big.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,6 @@

package big

func mulWW(x, y Word) (z1, z0 Word) {
return mulWW_g(x, y)
}
func divWW(x1, x0, y Word) (q, r Word) {
return divWW_g(x1, x0, y)
}
func addVV(z, x, y []Word) (c Word) {
return addVV_g(z, x, y)
}
func subVV(z, x, y []Word) (c Word) {
return subVV_g(z, x, y)
}
func addVW(z, x []Word, y Word) (c Word) {
return addVW_g(z, x, y)
}
func subVW(z, x []Word, y Word) (c Word) {
return subVW_g(z, x, y)
}
func shlVU(z, x []Word, s uint) (c Word) {
return shlVU_g(z, x, s)
}
func shrVU(z, x []Word, s uint) (c Word) {
return shrVU_g(z, x, s)
}
func mulAddVWW(z, x []Word, y, r Word) (c Word) {
return mulAddVWW_g(z, x, y, r)
}
func addMulVVW(z, x []Word, y Word) (c Word) {
return addMulVVW_g(z, x, y)
}
func divWVW(z []Word, xn Word, x []Word, y Word) (r Word) {
return divWVW_g(z, xn, x, y)
}
func bitLen(x Word) (n int) {
return bitLen_g(x)
}
// TODO: This is a workaround for https://github.com/gopherjs/gopherjs/issues/652.
// Remove after that issue is resolved.
type Word uintptr
Loading

0 comments on commit f7c5653

Please sign in to comment.