gopkg
gopkg copied to clipboard
Broken change of golang.org/x/sys causes build failed in go1.16
Question
Current go.mod use go1.16 with golang.org/x/sys v0.0.0-20221010170243-090e33056c14 package which introduced go1.17's unsafe.Slice in 20220910 (see history https://cs.opensource.google/go/x/sys/+/master:unix/syscall.go;bpv=1). This will cause build failed in go1.16 with following error messges.
# golang.org/x/sys/unix
../compile_path/pkg/mod/golang.org/x/[email protected]/unix/syscall.go:83:16: undefined: unsafe.Slice
../compile_path/pkg/mod/golang.org/x/[email protected]/unix/syscall_linux.go:2255:9: undefined: unsafe.Slice
../compile_path/pkg/mod/golang.org/x/[email protected]/unix/syscall_unix.go:118:7: undefined: unsafe.Slice
../compile_path/pkg/mod/golang.org/x/[email protected]/unix/sysvshm_unix.go:33:7: undefined: unsafe.Slice
note: module requires Go 1.17
I can't reproduce this error, could you list a more detailed reproduction process? thanks!
My steps:
> go version
go version go1.16.15 linux/amd64
> git clone https://github.com/bytedance/gopkg.git && cd gopkg && go test ./...
go: downloading golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
go: downloading github.com/stretchr/testify v1.7.0
go: downloading golang.org/x/sys v0.0.0-20221010170243-090e33056c14
go: downloading gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c
go: downloading github.com/davecgh/go-spew v1.1.0
ok github.com/bytedance/gopkg/cache/asynccache 6.819s
ok github.com/bytedance/gopkg/cloud/circuitbreaker 18.233s
ok github.com/bytedance/gopkg/cloud/metainfo 0.002s
ok github.com/bytedance/gopkg/collection/hashset 0.121s
ok github.com/bytedance/gopkg/collection/lscq 0.361s
ok github.com/bytedance/gopkg/collection/skipmap 0.348s
ok github.com/bytedance/gopkg/collection/skipset 0.132s
ok github.com/bytedance/gopkg/collection/zset 0.029s
? github.com/bytedance/gopkg/internal/benchmark/linkedq [no test files]
? github.com/bytedance/gopkg/internal/benchmark/msq [no test files]
? github.com/bytedance/gopkg/internal/hack [no test files]
ok github.com/bytedance/gopkg/internal/runtimex 0.002s
ok github.com/bytedance/gopkg/internal/wyhash 0.205s
ok github.com/bytedance/gopkg/lang/fastrand 0.028s
ok github.com/bytedance/gopkg/lang/mcache 0.002s
ok github.com/bytedance/gopkg/lang/stringx 0.002s
ok github.com/bytedance/gopkg/lang/syncx 0.116s
ok github.com/bytedance/gopkg/util/gctuner 0.025s
ok github.com/bytedance/gopkg/util/gopool 0.015s
? github.com/bytedance/gopkg/util/logger [no test files]
ok github.com/bytedance/gopkg/util/xxhash3 0.369s
? github.com/bytedance/gopkg/util/xxhash3/internal/xxh3_raw [no test files]
This is because bytedance/gopkg doesn't depend on golang.org/x/sys/unix. Let's create a package that depends on it then you will see the problem:
- setup
$ /usr/local/go1.16.15/bin/go version
go version go1.16.15 linux/amd64
$ mkdir -p ~/go/src/test/issue163 && cd ~/go/src/test/issue163
$ touch go.mod
$ touch main.go
- create main.go
//go:build linux
// +build linux
package main
import (
"github.com/bytedance/gopkg/util/gopool"
"golang.org/x/sys/unix"
)
func main() {
_ = gopool.NewPool
_ = unix.Fadvise
}
- create go.mod
module test/issue163
go 1.16
- go mod tidy
$ /usr/local/go1.16.15/bin/go mod tidy
go: finding module for package golang.org/x/sys/unix
go: finding module for package github.com/bytedance/gopkg/util/gopool
go: found github.com/bytedance/gopkg/util/gopool in github.com/bytedance/gopkg v0.0.0-20221122125632-68358b8ecec6
go: found golang.org/x/sys/unix in golang.org/x/sys v0.3.0
after current step our go.mod will look like this:
module test/issue163
go 1.16
require (
github.com/bytedance/gopkg v0.0.0-20221122125632-68358b8ecec6
golang.org/x/sys v0.3.0
)
- go build
$ /usr/local/go1.16.15/bin/go build
# golang.org/x/sys/unix
../../../pkg/mod/golang.org/x/[email protected]/unix/syscall.go:83:16: undefined: unsafe.Slice
../../../pkg/mod/golang.org/x/[email protected]/unix/syscall_linux.go:2256:9: undefined: unsafe.Slice
../../../pkg/mod/golang.org/x/[email protected]/unix/syscall_unix.go:118:7: undefined: unsafe.Slice
../../../pkg/mod/golang.org/x/[email protected]/unix/sysvshm_unix.go:33:7: undefined: unsafe.Slice
note: module requires Go 1.17
- downgrade golang.org/x/sys and test it again
- modify our go.mod
module test/issue163
go 1.16
require (
github.com/bytedance/gopkg v0.0.0-20221122125632-68358b8ecec6
golang.org/x/sys v0.0.0-20220110181412-a018aaa089fe
)
NOTE: a commonly used library in ByteDance use golang.org/x/sys v0.0.0-20220110181412-a018aaa089fe
- go mod tidy
$ /usr/local/go1.16.15/bin/go mod tidy
then our go.mod will look like this:
module test/issue163
go 1.16
require (
github.com/bytedance/gopkg v0.0.0-20221122125632-68358b8ecec6
golang.org/x/sys v0.0.0-20221010170243-090e33056c14
)
the version of golang.org/x/sys will be changed to v0.0.0-20221010170243-090e33056c14 since bytedance/gopkg choose it.
- go build
$ /usr/local/go1.16.15/bin/go build
# golang.org/x/sys/unix
../../../pkg/mod/golang.org/x/[email protected]/unix/syscall.go:83:16: undefined: unsafe.Slice
../../../pkg/mod/golang.org/x/[email protected]/unix/syscall_linux.go:2255:9: undefined: unsafe.Slice
../../../pkg/mod/golang.org/x/[email protected]/unix/syscall_unix.go:118:7: undefined: unsafe.Slice
../../../pkg/mod/golang.org/x/[email protected]/unix/sysvshm_unix.go:33:7: undefined: unsafe.Slice
note: module requires Go 1.17