tinygo-org / tinygo

Go compiler for small places. Microcontrollers, WebAssembly (WASM/WASI), and command-line tools. Based on LLVM.
https://tinygo.org
Other
15.2k stars 892 forks source link

tinygo cgo compile error #3044

Open halfrost opened 2 years ago

halfrost commented 2 years ago

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 2 years ago

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

halfrost commented 2 years ago

@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 2 years ago

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 2 years ago

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 1 year ago

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