Skip to content

Commit 1e088ea

Browse files
authored
Merge pull request #1015 from gopherjs/go1.16-stdlib
Add support for Go 1.16.3 standard library
2 parents bed99a8 + c9347d8 commit 1e088ea

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+4992
-1355
lines changed

.std_test_pkg_exclusions

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,12 @@
1-
context
2-
crypto
3-
crypto/internal/cipherhw
41
crypto/tls
5-
crypto/x509/pkix
62
debug/gosym
7-
debug/plan9obj
8-
encoding
3+
embed/internal/embedtest
94
go/build
105
go/importer
116
go/internal/gccgoimporter
127
go/internal/gcimporter
138
go/internal/srcimporter
149
go/types
15-
hash
16-
image/color/palette
17-
image/internal/imageutil
18-
internal/cpu
19-
internal/goroot
20-
internal/nettrace
21-
internal/poll
22-
internal/race
23-
internal/singleflight
2410
internal/syscall/unix
2511
internal/syscall/windows
2612
internal/syscall/windows/registry
@@ -29,7 +15,6 @@ internal/testenv
2915
internal/testlog
3016
internal/trace
3117
internal/x/net/nettest
32-
log
3318
log/syslog
3419
net
3520
net/http
@@ -46,7 +31,6 @@ os
4631
os/exec
4732
os/signal
4833
os/signal/internal/pty
49-
os/user
5034
plugin
5135
runtime
5236
runtime/cgo
@@ -59,7 +43,5 @@ runtime/pprof/internal/profile
5943
runtime/race
6044
runtime/trace
6145
syscall
62-
testing
6346
testing/internal/testdeps
64-
testing/iotest
6547
unsafe

README.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,35 @@ GopherJS - A compiler from Go to JavaScript
77

88
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.
99

10+
### What's new?
11+
12+
- 2021-04-04: **Go 1.16 is now officially supported!** 🎉 🎉 🎉
13+
1014
### Playground
15+
1116
Give GopherJS a try on the [GopherJS Playground](http://gopherjs.github.io/playground/).
1217

1318
### What is supported?
14-
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.
19+
20+
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.
1521

1622
### Installation and Usage
17-
GopherJS requires Go 1.12 or newer.
23+
24+
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
25+
version, you can use an [older Gopher release](https://github.com/gopherjs/gopherjs/releases).
1826

1927
Get or update GopherJS and dependencies with:
2028

2129
```
2230
go get -u github.com/gopherjs/gopherjs
2331
```
2432

25-
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:
33+
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:
2634

2735
```
28-
go get golang.org/dl/go1.12.16
29-
go1.12.16 download
30-
export GOPHERJS_GOROOT="$(go1.12.16 env GOROOT)" # Also add this line to your .profile or equivalent.
36+
go get golang.org/dl/go1.16.3
37+
go1.16.3 download
38+
export GOPHERJS_GOROOT="$(go1.16.3 env GOROOT)" # Also add this line to your .profile or equivalent.
3139
```
3240

3341
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.
@@ -131,7 +139,7 @@ For more details see [Jason Stone's blog post](http://legacytotheedge.blogspot.d
131139
### Architecture
132140

133141
#### General
134-
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`.
142+
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`.
135143

136144
#### Application Lifecycle
137145

build/build.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,14 +175,22 @@ func importWithSrcDir(bctx build.Context, path string, srcDir string, mode build
175175
switch path {
176176
case "os":
177177
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.
178+
// Prefer dirent_js.go version, since it targets a similar environment to
179+
// ours. Arguably this file should be excluded by the build tags (see
180+
// https://github.com/gopherjs/gopherjs/issues/693).
181+
pkg.GoFiles = exclude(pkg.GoFiles, "dirent_linux.go")
178182
case "runtime":
179-
pkg.GoFiles = []string{"error.go"}
183+
pkg.GoFiles = []string{} // Package sources are completely replaced in natives.
180184
case "runtime/internal/sys":
181185
pkg.GoFiles = []string{fmt.Sprintf("zgoos_%s.go", bctx.GOOS), "zversion.go"}
182186
case "runtime/pprof":
183187
pkg.GoFiles = nil
184188
case "internal/poll":
185189
pkg.GoFiles = exclude(pkg.GoFiles, "fd_poll_runtime.go")
190+
case "sync":
191+
// GopherJS completely replaces sync.Pool implementation with a simpler one,
192+
// since it always executes in a single-threaded environment.
193+
pkg.GoFiles = exclude(pkg.GoFiles, "pool.go")
186194
case "crypto/rand":
187195
pkg.GoFiles = []string{"rand.go", "util.go"}
188196
pkg.TestGoFiles = exclude(pkg.TestGoFiles, "rand_linux_test.go") // Don't want linux-specific tests (since linux-specific package files are excluded too).
@@ -398,7 +406,7 @@ func parseAndAugment(bctx *build.Context, pkg *build.Package, isTest bool, fileS
398406
}
399407

400408
switch pkg.ImportPath {
401-
case "crypto/rand", "encoding/gob", "encoding/json", "expvar", "go/token", "log", "math/big", "math/rand", "regexp", "testing", "time":
409+
case "crypto/rand", "encoding/gob", "encoding/json", "expvar", "go/token", "log", "math/big", "math/rand", "regexp", "time":
402410
for _, spec := range file.Imports {
403411
path, _ := strconv.Unquote(spec.Path.Value)
404412
if path == "sync" {

circle.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,24 @@ jobs:
44
docker:
55
- image: ubuntu:18.04
66
environment:
7-
SOURCE_MAP_SUPPORT: false
7+
SOURCE_MAP_SUPPORT: true
8+
GO111MODULE: "off" # Until issue #855 is fixed, we operate in GOPATH mode.
89
working_directory: ~/go/src/github.com/gopherjs/gopherjs
910
steps:
1011
- run: apt-get update && apt-get install -y sudo curl git python make g++
1112
- checkout
1213
- 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
1314
- run: nvm install 10.0.0 && nvm alias default 10.0.0
14-
- run: cd /usr/local && sudo rm -rf go && curl https://storage.googleapis.com/golang/go1.12.17.linux-amd64.tar.gz | sudo tar -xz
15+
- run: echo export "NODE_PATH='$(npm root --global)'" >> $BASH_ENV # Make nodejs able to require globally installed modules from any working path.
16+
- run: env
17+
- run: cd /usr/local && sudo rm -rf go && curl https://storage.googleapis.com/golang/go1.16.3.linux-amd64.tar.gz | sudo tar -xz
1518
- run: echo 'export PATH="$PATH:/usr/local/go/bin:$HOME/go/bin"' >> $BASH_ENV
1619
- run: go get -t -d -v ./...
1720
- run: go install -v
1821
- run: npm install # Install our (dev) dependencies from package.json.
22+
- run: npm install --global source-map-support # Required by standard library tests.
1923
- run: npm install --global node-gyp@5.1.1
20-
- run: cd node-syscall && node-gyp rebuild && mkdir -p ~/.node_libraries && cp build/Release/syscall.node ~/.node_libraries/syscall.node
21-
24+
- run: cd node-syscall && node-gyp rebuild && mkdir -p $NODE_PATH && cp build/Release/syscall.node $NODE_PATH/syscall.node
2225
- run: go generate github.com/gopherjs/gopherjs/compiler/prelude
2326
- run: diff -u <(echo -n) <(git status --porcelain)
2427
- run: diff -u <(echo -n) <(gofmt -d .)

compiler/astutil/astutil.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,12 @@ func IsTypeExpr(expr ast.Expr, info *types.Info) bool {
4646
return false
4747
}
4848
}
49+
50+
func ImportsUnsafe(file *ast.File) bool {
51+
for _, imp := range file.Imports {
52+
if imp.Path.Value == `"unsafe"` {
53+
return true
54+
}
55+
}
56+
return false
57+
}

compiler/astutil/astutil_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package astutil
2+
3+
import (
4+
"go/parser"
5+
"go/token"
6+
"testing"
7+
)
8+
9+
func TestImportsUnsafe(t *testing.T) {
10+
tests := []struct {
11+
desc string
12+
imports string
13+
want bool
14+
}{
15+
{
16+
desc: "no imports",
17+
imports: "",
18+
want: false,
19+
}, {
20+
desc: "other imports",
21+
imports: `import "some/other/package"`,
22+
want: false,
23+
}, {
24+
desc: "only unsafe",
25+
imports: `import "unsafe"`,
26+
want: true,
27+
}, {
28+
desc: "multi-import decl",
29+
imports: `import (
30+
"some/other/package"
31+
"unsafe"
32+
)`,
33+
want: true,
34+
}, {
35+
desc: "two import decls",
36+
imports: `import "some/other/package"
37+
import "unsafe"`,
38+
want: true,
39+
},
40+
}
41+
for _, test := range tests {
42+
t.Run(test.desc, func(t *testing.T) {
43+
src := "package testpackage\n\n" + test.imports
44+
fset := token.NewFileSet()
45+
file, err := parser.ParseFile(fset, "test.go", src, parser.ParseComments)
46+
if err != nil {
47+
t.Fatalf("Failed to parse test source: %s", err)
48+
}
49+
got := ImportsUnsafe(file)
50+
if got != test.want {
51+
t.Fatalf("ImportsUnsafe() returned %t, want %t", got, test.want)
52+
}
53+
})
54+
}
55+
}

0 commit comments

Comments
 (0)