tinygo cgo compile error
halfrost opened this issue · 5 comments
halfrost commented
hen I use tinygo to compile wasm plugin:
$ tinygo build -o main.wasm -scheduler=none -target=wasi main.go
compile error. The error log is:
# os/user
../../../../opt/Cellar/go/1.17.2/libexec/src/os/user/cgo_lookup_unix.go:21:6: not implemented: build constraints in #cgo line
../../../../opt/Cellar/go/1.17.2/libexec/src/os/user/cgo_lookup_unix.go:24:10: fatal: 'pwd.h' file not found
../../../../opt/Cellar/go/1.17.2/libexec/src/os/user/getgrouplist_unix.go:15:10: fatal: 'grp.h' file not found
Once I disabled the cgo compile parameters,
$ CGO_ENABLED=0 tinygo build -o main.wasm -scheduler=none -target=wasi main.go
The error log is:
# github.com/cespare/xxhash/v2
../../pkg/mod/github.com/cespare/xxhash/v2@v2.1.1/xxhash_unsafe.go:32:11: cannot use len(s) (value of type int) as uintptr value in assignment
../../pkg/mod/github.com/cespare/xxhash/v2@v2.1.1/xxhash_unsafe.go:33:11: cannot use len(s) (value of type int) as uintptr value in assignment
../../pkg/mod/github.com/cespare/xxhash/v2@v2.1.1/xxhash_unsafe.go:43:11: cannot use len(s) (value of type int) as uintptr value in assignment
../../pkg/mod/github.com/cespare/xxhash/v2@v2.1.1/xxhash_unsafe.go:44:11: cannot use len(s) (value of type int) as uintptr value in assignment
My dependencies include prometheus and etcd. Both of their dependencies include xxhash. Is there any good idea?
dgryski commented
Try building with -tags=appengine to get a safe version of xxhash.
halfrost commented
@dgryski I try this command:
CGO_ENABLED=0 tinygo build -o main.wasm -scheduler=none -tags=appengine -target=wasi main.go
But still error:
# github.com/golang/protobuf/proto
../../pkg/mod/github.com/golang/protobuf@v1.4.3/proto/registry.go:230:16: MapOf not declared by package reflect
dgryski commented
Yup, that's a current limitation of the reflect package. There are patches in progress to fix that, but otherwise no timeline for getting them merged.
halfrost commented
OK, I'll keep an eye on your patch. You can add a tag to this issue with the patch you mentioned.
cross-hello commented
@dgryski same problem here.

XTLS/Xray-core#1473 (comment)