Skip to content

Add support for Go 1.16.3 standard library #1015

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 81 commits into from
Apr 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
0a0fdc9
Start work on supporting Go 1.16 standard library (issue #989).
nevkontakte Feb 28, 2021
3eb67a4
Run `go generate ./...` to update vfs.
nevkontakte Feb 28, 2021
e1112ef
Support compiling Go 1.16 `runtime` with GopherJS. (#990)
nevkontakte Mar 7, 2021
8f5b191
Support Go 1.13-1.16 changes in the sync package.
nevkontakte Mar 7, 2021
e8b8f83
Fix math package conflict with natives introduced in Go 1.14.
visualfc Feb 8, 2020
03ae6be
Fix `internal/syscall/unix` to compile with Go 1.16.
nevkontakte Mar 8, 2021
9efa6e7
Fix `time` package to compile with Go 1.16.
nevkontakte Mar 8, 2021
fdd3931
Fix `os` and `internal/poll` packages to build with Go 1.16.
nevkontakte Mar 8, 2021
e406c3a
Update the comment to reference the correct issue.
nevkontakte Mar 9, 2021
62ac60c
Add `internal/reflectlite` package support.
nevkontakte Mar 11, 2021
c4c6314
Merge pull request #994 from nevkontakte/go1.16-stdlib
nevkontakte Mar 12, 2021
27f50ea
Fix a new Go vet warning introduced in 1.15.
nevkontakte Mar 12, 2021
92299b8
Support `testing` package with Go 1.16 and re-enable most of its tests.
nevkontakte Mar 11, 2021
9b3d9ea
Merge pull request #995 from nevkontakte/go1.16-stdlib
nevkontakte Mar 12, 2021
99ba27b
Update vfs to include latest changes related to Go 1.16.
nevkontakte Mar 13, 2021
23cd225
Implement `runtime.FuncForPC()` for GopherJS.
nevkontakte Mar 12, 2021
8891253
Add a runtime type check on `return.MakeFunc()` return values.
nevkontakte Mar 12, 2021
970e088
Add missing `reflect.addReflectOff()` function implementation.
nevkontakte Mar 12, 2021
1ac47cc
Provide a working implementation of `reflect.StructOf()` function.
nevkontakte Mar 13, 2021
f4c2b93
Rename `mapitervalue` → `mapiterelem` in the `reflect` package.
nevkontakte Mar 13, 2021
858e670
Fix type string generation for channels and embedded struct fields.
nevkontakte Mar 13, 2021
c25710c
Fix TestConvertNaNs test in the `reflect` package.
nevkontakte Mar 15, 2021
3f703aa
Enable source map support when running tests on CircleCI.
nevkontakte Mar 15, 2021
44fa453
Update generated files with changes to `reflect` and `runtime`.
nevkontakte Mar 13, 2021
f5092bf
Merge pull request #996 from nevkontakte/go1.16-stdlib
nevkontakte Mar 16, 2021
3d1cd28
Avoid double implicit type conversion on deferred built-in arguments.
nevkontakte Mar 17, 2021
163a579
Merge pull request #998 from nevkontakte/go1.16-stdlib
nevkontakte Mar 18, 2021
ef4f86f
Skip memory allocation counter test in the `bufio` package.
nevkontakte Mar 16, 2021
8b4ddd6
Skip an unsupported test in `crypto/x509` added in Go 1.16.
nevkontakte Mar 16, 2021
0f95ecf
Skip embed/internal/embedtest tests which were added in Go 1.16.
nevkontakte Mar 16, 2021
a61ea37
Update `sync` tests for Go 1.16.
nevkontakte Mar 17, 2021
23ae917
Update VFS.
nevkontakte Mar 17, 2021
68158af
Merge pull request #999 from nevkontakte/go1.16-stdlib
nevkontakte Mar 19, 2021
ccebfda
Support Go 1.16 hash/memhash package.
nevkontakte Mar 19, 2021
bfd5355
Update VFS data with hash/maphash changes.
nevkontakte Mar 19, 2021
cb74bce
Merge pull request #1002 from nevkontakte/go1.16-stdlib
nevkontakte Mar 19, 2021
3dce29e
Make runtime panics conform to the error interface.
nevkontakte Mar 18, 2021
5bcafdb
Restore implementation of TypeAssertionError in `runtime`.
nevkontakte Mar 19, 2021
70671c3
Make `internal/fmtsort` tests pass with Go 1.16.
nevkontakte Mar 19, 2021
4a391b4
Skip an unsupported test in `internal/unsafeheader`.
nevkontakte Mar 19, 2021
55cfef1
Skip an `io` package test that fails due to a GopherJS compiler bug.
nevkontakte Mar 21, 2021
d823cd5
Skip an irrelevant `sync/atomic` test that was added in Go 1.16.
nevkontakte Mar 21, 2021
641da0a
`runtime`: treat empty GOROOT environment variables the same as unset.
nevkontakte Mar 22, 2021
b8ef398
Update VFS with the recent changes.
nevkontakte Mar 22, 2021
3f0bf36
Merge pull request #1004 from nevkontakte/go1.16-stdlib
nevkontakte Mar 22, 2021
d8eca05
A minor compiler refactoring and readability improvement.
nevkontakte Mar 24, 2021
1ed3d42
Merge pull request #1005 from nevkontakte/go1.16-stdlib
nevkontakte Mar 27, 2021
73e0929
Add a basic go:linkname directive test case.
nevkontakte Mar 24, 2021
00bd45e
Added GoLinkname and SymName types.
nevkontakte Mar 25, 2021
9970255
Implement go:linkname parsing logic.
nevkontakte Mar 26, 2021
b44c6fe
Implement go:linkname support in the compiler.
nevkontakte Mar 26, 2021
22d6bbd
Move time.runtimeNano() to runtime.nanotime().
nevkontakte Mar 26, 2021
50137e0
Replace runtime.InternalFastrand() with go:linkname now that we have it.
nevkontakte Mar 28, 2021
861b033
Add a documentation page for the go:linkname directive.
nevkontakte Mar 28, 2021
0486ce6
Update VFS.
nevkontakte Mar 26, 2021
c6a2ff3
Merge pull request #1006 from nevkontakte/go1.16-linkname
nevkontakte Mar 28, 2021
ef56a47
Support Go 1.16 `time` package.
nevkontakte Mar 27, 2021
03cb433
Update VFS with changes in the time package.
nevkontakte Mar 28, 2021
c7bc024
Merge pull request #1008 from nevkontakte/go1.16-stdlib
nevkontakte Mar 29, 2021
c69283b
Fix https://github.com/golang/go/issues/15992 for GopherJS.
nevkontakte Mar 27, 2021
e48f089
Change print() built-in to not write a new line under NodeJS.
nevkontakte Mar 27, 2021
354fbbb
Skip fixedbugs/issue24491{a,b}.go tests.
nevkontakte Mar 27, 2021
198685f
Skip fixedbugs/issue29504.go and fixedbugs/issue29735.go.
nevkontakte Mar 27, 2021
b26ad34
Skip fixedbugs/issue30116.go test.
nevkontakte Mar 27, 2021
043d069
Don't initialize blank struct fields.
nevkontakte Mar 27, 2021
e2fc091
Skip fixedbugs/issue34395.go test.
nevkontakte Mar 27, 2021
c534de9
Skip `fixedbugs/issue{35027,35073,40917}.go` tests.
nevkontakte Mar 27, 2021
322ded4
Correctly expand multi-valued returns into separate print/println args.
nevkontakte Mar 27, 2021
8a9b2ad
Only `throw null` in $callDeferred() when called directly from $panic()
nevkontakte Mar 27, 2021
c77ca6b
Re-enable fixedbugs/issue22083.go test.
nevkontakte Mar 28, 2021
74a6fbd
Update minified version of prelude.
nevkontakte Mar 27, 2021
fd18b1a
Skip Go fixedbugs tests when running with --short.
nevkontakte Mar 28, 2021
4c3358a
Bump target Go version to 1.16.2.
nevkontakte Mar 28, 2021
11747e9
Merge pull request #1009 from nevkontakte/go1.16-stdlib
nevkontakte Apr 4, 2021
24ad5c3
Update supported packages list.
nevkontakte Apr 4, 2021
8fc5f0b
Add a detailed compatibility documentation page.
nevkontakte Apr 4, 2021
e9c2dbd
Merge pull request #1012 from nevkontakte/go1.16-stdlib
nevkontakte Apr 5, 2021
0f9c799
Bump target Go version to 1.16.3, which was just released.
nevkontakte Apr 4, 2021
8c2b9f4
Finish support for `runtime.Callers()` and `runtime.CallerFrames()`.
nevkontakte Apr 4, 2021
a223e64
Updated VFS data with changes to runtime, io and testing.
nevkontakte Apr 4, 2021
c9347d8
Merge pull request #1014 from nevkontakte/go1.16-stdlib
nevkontakte Apr 6, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 1 addition & 19 deletions .std_test_pkg_exclusions
Original file line number Diff line number Diff line change
@@ -1,26 +1,12 @@
context
crypto
crypto/internal/cipherhw
crypto/tls
crypto/x509/pkix
debug/gosym
debug/plan9obj
encoding
embed/internal/embedtest
go/build
go/importer
go/internal/gccgoimporter
go/internal/gcimporter
go/internal/srcimporter
go/types
hash
image/color/palette
image/internal/imageutil
internal/cpu
internal/goroot
internal/nettrace
internal/poll
internal/race
internal/singleflight
internal/syscall/unix
internal/syscall/windows
internal/syscall/windows/registry
Expand All @@ -29,7 +15,6 @@ internal/testenv
internal/testlog
internal/trace
internal/x/net/nettest
log
log/syslog
net
net/http
Expand All @@ -46,7 +31,6 @@ os
os/exec
os/signal
os/signal/internal/pty
os/user
plugin
runtime
runtime/cgo
Expand All @@ -59,7 +43,5 @@ runtime/pprof/internal/profile
runtime/race
runtime/trace
syscall
testing
testing/internal/testdeps
testing/iotest
unsafe
22 changes: 15 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,35 @@ GopherJS - A compiler from Go to JavaScript

GopherJS compiles Go code ([golang.org](https://golang.org/)) to pure JavaScript code. Its main purpose is to give you the opportunity to write front-end code in Go which will still run in all browsers.

### What's new?

- 2021-04-04: **Go 1.16 is now officially supported!** 🎉 🎉 🎉

### Playground

Give GopherJS a try on the [GopherJS Playground](http://gopherjs.github.io/playground/).

### What is supported?
Nearly everything, including Goroutines ([compatibility table](https://github.com/gopherjs/gopherjs/blob/master/doc/packages.md)). Performance is quite good in most cases, see [HTML5 game engine benchmark](https://ajhager.github.io/engi/demos/botmark.html). Cgo is not supported.

Nearly everything, including Goroutines ([compatibility documentation](https://github.com/gopherjs/gopherjs/blob/master/doc/compatibility.md)). Performance is quite good in most cases, see [HTML5 game engine benchmark](https://ajhager.github.io/engi/demos/botmark.html). Cgo is not supported.

### Installation and Usage
GopherJS requires Go 1.12 or newer.

GopherJS [requires Go 1.16 or newer](https://github.com/gopherjs/gopherjs/blob/master/doc/compatibility.md#go-version-compatibility). If you need an older Go
version, you can use an [older Gopher release](https://github.com/gopherjs/gopherjs/releases).

Get or update GopherJS and dependencies with:

```
go get -u github.com/gopherjs/gopherjs
```

If your local Go distribution as reported by `go version` is newer than Go 1.12, then you need to set the `GOPHERJS_GOROOT` environment variable to a directory that contains a Go 1.12 distribution. For example:
If your local Go distribution as reported by `go version` is newer than Go 1.16, then you need to set the `GOPHERJS_GOROOT` environment variable to a directory that contains a Go 1.16 distribution. For example:

```
go get golang.org/dl/go1.12.16
go1.12.16 download
export GOPHERJS_GOROOT="$(go1.12.16 env GOROOT)" # Also add this line to your .profile or equivalent.
go get golang.org/dl/go1.16.3
go1.16.3 download
export GOPHERJS_GOROOT="$(go1.16.3 env GOROOT)" # Also add this line to your .profile or equivalent.
```

Now you can use `gopherjs build [package]`, `gopherjs build [files]` or `gopherjs install [package]` which behave similar to the `go` tool. For `main` packages, these commands create a `.js` file and `.js.map` source map in the current directory or in `$GOPATH/bin`. The generated JavaScript file can be used as usual in a website. Use `gopherjs help [command]` to get a list of possible command line flags, e.g. for minification and automatically watching for changes.
Expand Down Expand Up @@ -131,7 +139,7 @@ For more details see [Jason Stone's blog post](http://legacytotheedge.blogspot.d
### Architecture

#### General
GopherJS emulates a 32-bit environment. This means that `int`, `uint` and `uintptr` have a precision of 32 bits. However, the explicit 64-bit integer types `int64` and `uint64` are supported. The `GOARCH` value of GopherJS is "js". You may use it as a build constraint: `// +build js`.
GopherJS emulates a 32-bit environment. This means that `int`, `uint` and `uintptr` have a precision of 32 bits. However, the explicit 64-bit integer types `int64` and `uint64` are supported. The `GOARCH` value of GopherJS is "js". You may use it as a build constraint: `// +build js,-wasm`.

#### Application Lifecycle

Expand Down
12 changes: 10 additions & 2 deletions build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,22 @@ func importWithSrcDir(bctx build.Context, path string, srcDir string, mode build
switch path {
case "os":
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.
// Prefer dirent_js.go version, since it targets a similar environment to
// ours. Arguably this file should be excluded by the build tags (see
// https://github.com/gopherjs/gopherjs/issues/693).
pkg.GoFiles = exclude(pkg.GoFiles, "dirent_linux.go")
case "runtime":
pkg.GoFiles = []string{"error.go"}
pkg.GoFiles = []string{} // Package sources are completely replaced in natives.
case "runtime/internal/sys":
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 "sync":
// GopherJS completely replaces sync.Pool implementation with a simpler one,
// since it always executes in a single-threaded environment.
pkg.GoFiles = exclude(pkg.GoFiles, "pool.go")
case "crypto/rand":
pkg.GoFiles = []string{"rand.go", "util.go"}
pkg.TestGoFiles = exclude(pkg.TestGoFiles, "rand_linux_test.go") // Don't want linux-specific tests (since linux-specific package files are excluded too).
Expand Down Expand Up @@ -398,7 +406,7 @@ func parseAndAugment(bctx *build.Context, pkg *build.Package, isTest bool, fileS
}

switch pkg.ImportPath {
case "crypto/rand", "encoding/gob", "encoding/json", "expvar", "go/token", "log", "math/big", "math/rand", "regexp", "testing", "time":
case "crypto/rand", "encoding/gob", "encoding/json", "expvar", "go/token", "log", "math/big", "math/rand", "regexp", "time":
for _, spec := range file.Imports {
path, _ := strconv.Unquote(spec.Path.Value)
if path == "sync" {
Expand Down
11 changes: 7 additions & 4 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@ jobs:
docker:
- image: ubuntu:18.04
environment:
SOURCE_MAP_SUPPORT: false
SOURCE_MAP_SUPPORT: true
GO111MODULE: "off" # Until issue #855 is fixed, we operate in GOPATH mode.
working_directory: ~/go/src/github.com/gopherjs/gopherjs
steps:
- run: apt-get update && apt-get install -y sudo curl git python make g++
- checkout
- run: git clone https://github.com/creationix/nvm $HOME/.nvm && cd $HOME/.nvm && git checkout v0.33.9 && echo 'export NVM_DIR="$HOME/.nvm"' >> $BASH_ENV && echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"' >> $BASH_ENV
- run: nvm install 10.0.0 && nvm alias default 10.0.0
- run: cd /usr/local && sudo rm -rf go && curl https://storage.googleapis.com/golang/go1.12.17.linux-amd64.tar.gz | sudo tar -xz
- run: echo export "NODE_PATH='$(npm root --global)'" >> $BASH_ENV # Make nodejs able to require globally installed modules from any working path.
- run: env
- run: cd /usr/local && sudo rm -rf go && curl https://storage.googleapis.com/golang/go1.16.3.linux-amd64.tar.gz | sudo tar -xz
- run: echo 'export PATH="$PATH:/usr/local/go/bin:$HOME/go/bin"' >> $BASH_ENV
- run: go get -t -d -v ./...
- run: go install -v
- run: npm install # Install our (dev) dependencies from package.json.
- run: npm install --global source-map-support # Required by standard library tests.
- run: npm install --global node-gyp@5.1.1
- run: cd node-syscall && node-gyp rebuild && mkdir -p ~/.node_libraries && cp build/Release/syscall.node ~/.node_libraries/syscall.node

- run: cd node-syscall && node-gyp rebuild && mkdir -p $NODE_PATH && cp build/Release/syscall.node $NODE_PATH/syscall.node
- run: go generate github.com/gopherjs/gopherjs/compiler/prelude
- run: diff -u <(echo -n) <(git status --porcelain)
- run: diff -u <(echo -n) <(gofmt -d .)
Expand Down
9 changes: 9 additions & 0 deletions compiler/astutil/astutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,12 @@ func IsTypeExpr(expr ast.Expr, info *types.Info) bool {
return false
}
}

func ImportsUnsafe(file *ast.File) bool {
for _, imp := range file.Imports {
if imp.Path.Value == `"unsafe"` {
return true
}
}
return false
}
55 changes: 55 additions & 0 deletions compiler/astutil/astutil_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package astutil

import (
"go/parser"
"go/token"
"testing"
)

func TestImportsUnsafe(t *testing.T) {
tests := []struct {
desc string
imports string
want bool
}{
{
desc: "no imports",
imports: "",
want: false,
}, {
desc: "other imports",
imports: `import "some/other/package"`,
want: false,
}, {
desc: "only unsafe",
imports: `import "unsafe"`,
want: true,
}, {
desc: "multi-import decl",
imports: `import (
"some/other/package"
"unsafe"
)`,
want: true,
}, {
desc: "two import decls",
imports: `import "some/other/package"
import "unsafe"`,
want: true,
},
}
for _, test := range tests {
t.Run(test.desc, func(t *testing.T) {
src := "package testpackage\n\n" + test.imports
fset := token.NewFileSet()
file, err := parser.ParseFile(fset, "test.go", src, parser.ParseComments)
if err != nil {
t.Fatalf("Failed to parse test source: %s", err)
}
got := ImportsUnsafe(file)
if got != test.want {
t.Fatalf("ImportsUnsafe() returned %t, want %t", got, test.want)
}
})
}
}
Loading