code-generator
code-generator copied to clipboard
We should notify the user to pass the GOROOT env when invoking the client-gen
We have noticed the client-gen failed to run sometimes in GitHub Action. After the investigation in https://github.com/mosn/htnn/pull/687, we found that the GOROOT mismatching causes it.
The client-gen imports gengo, and gengo imports go/build. The go/build module will invoke the go toolchain to generate the go code. If the GOROOT is not given as the env var, go/build will use the builtin default GOROOT to look up the go toolchain.
This brings a problem when the client-gen is built with a go compiler A and then executed on a machine that has a go compiler B, the builtin GOROOT is different from the real GOROOT, causes fork/exec xxx/go: no such file or directory error.
To avoid such an error, we should notify the user to pass the GOROOT env when invoking the client-gen, so the environment to build client-gen doesn't impact the environment to use client-gen. For example, GOROOT=$(go env GOROOT) client-gen ....