tinygo icon indicating copy to clipboard operation
tinygo copied to clipboard

tinygo cgo compile error

Open halfrost opened this issue 3 years ago • 4 comments

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/[email protected]/xxhash_unsafe.go:32:11: cannot use len(s) (value of type int) as uintptr value in assignment
../../pkg/mod/github.com/cespare/xxhash/[email protected]/xxhash_unsafe.go:33:11: cannot use len(s) (value of type int) as uintptr value in assignment
../../pkg/mod/github.com/cespare/xxhash/[email protected]/xxhash_unsafe.go:43:11: cannot use len(s) (value of type int) as uintptr value in assignment
../../pkg/mod/github.com/cespare/xxhash/[email protected]/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?

halfrost avatar Aug 03 '22 19:08 halfrost

Try building with -tags=appengine to get a safe version of xxhash.

dgryski avatar Aug 03 '22 22:08 dgryski

@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/[email protected]/proto/registry.go:230:16: MapOf not declared by package reflect

halfrost avatar Aug 03 '22 23:08 halfrost

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.

dgryski avatar Aug 03 '22 23:08 dgryski

OK, I'll keep an eye on your patch. You can add a tag to this issue with the patch you mentioned.

halfrost avatar Aug 03 '22 23:08 halfrost

@dgryski same problem here. image https://github.com/XTLS/Xray-core/issues/1473#issuecomment-1367775901

cross-hello avatar Dec 30 '22 08:12 cross-hello