0chain / gosdk

A client SDK in Go to interface the blockchain and storage platform, and other smart contracts
MIT License
32 stars 29 forks source link

make gosdk compilable to wasm (go-ethereum not compatible with wasm) #128

Closed mallochine closed 3 years ago

mallochine commented 3 years ago

@moldis please fix this since go-ethereum package is your responsibility.

You can reproduce the compile error by doing this:

  1. git checkout jssdk branch
  2. cd $TOP/_sdkver
  3. GOOS=js GOARCH=wasm go build -o proxy.wasm proxy.go ethwallet.go
  4. produces this error message:
../../../go/pkg/mod/github.com/ethereum/go-ethereum@v1.10.3/metrics/cpu_enabled.go:40:79: undefined: "github.com/shirou/gopsutil/cpu".ClocksPerSec
../../../go/pkg/mod/github.com/ethereum/go-ethereum@v1.10.3/metrics/cpu_enabled.go:41:47: undefined: "github.com/shirou/gopsutil/cpu".ClocksPerSec
../../../go/pkg/mod/github.com/ethereum/go-ethereum@v1.10.3/metrics/cpu_syscall.go:30:12: undefined: syscall.Getrusage
../../../go/pkg/mod/github.com/ethereum/go-ethereum@v1.10.3/metrics/cpu_syscall.go:30:30: undefined: syscall.RUSAGE_SELF

The temporary workaround that I'm using (in order to build the wasm taht Hau can use) is to edit those go-ethereum files locally and fix the golang errors by nuking the CPU stat collection.

In order to fix this, Artem you need to do either one of the following two:

@moldis also this is way outside the scope of my responsibilities, so I'm assigning to you

Rizary commented 3 years ago

there is an active PR https://github.com/ethereum/go-ethereum/pull/23046 that solves the above error. I have tried it in my local machine.

mallochine commented 3 years ago

hey nice find

Rizary commented 3 years ago

@mallochine sorry for taking this too long. I ask the go-ethereum devs but it seems they still not review the above PR. I tried to update our mod using go get github.com/certifaction/go-ethereum@BP-3079-clien-compile-wasm, and get this error when I try to update using go mod tidy:

go: github.com/certifaction/go-ethereum@v1.10.3-wasm: parsing go.mod:
    module declares its path as: github.com/ethereum/go-ethereum
            but was required as: github.com/certifaction/go-ethereum

turns out, it happened because it is still use github.com/ethereum/go-ethereum as module name in here: https://github.com/certifaction/go-ethereum/blob/BP-3079-clien-compile-wasm/go.mod#L1

Do you have any other suggestion?

cnlangzi commented 3 years ago

use go replace on go.mod , and git clone it on ci job first

Rizary commented 3 years ago

closed as #141