Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to run while using Go Toolchain #61

Closed
Zxilly opened this issue Jun 16, 2024 · 13 comments · Fixed by #68
Closed

Failed to run while using Go Toolchain #61

Zxilly opened this issue Jun 16, 2024 · 13 comments · Fixed by #68

Comments

@Zxilly
Copy link
Contributor

Zxilly commented Jun 16, 2024

When running the test with the go toolchain enabled, the GOROOT is set to the path of the go toolchain package.

However, it doesn't contain the misc folder, which leads to an error like

FAIL github.com/Zxilly/go-size-analyzer/internal/disasm 0.071s
open C:\Users\zxilly\go\pkg\mod\golang.org\t[email protected]/misc/wasm/wasm_exec.js: The system cannot find the path specified.

Since this package was the official suggested test runner, I think this situation should be considered.

https://github.com/golang/go/wiki/WebAssembly#running-tests-in-the-browser

@agnivade
Copy link
Owner

How are you installing the toolchain? Are you using go install golang.org/dl/go1.22.4@latest? I am not sure how the GOROOT is pointing to C:\Users\zxilly\go\pkg\mod\golang.org\toolchain, because on my machine (using Linux), it's at $HOME/sdk.

I just ran a fresh test using 1.22.4

GOARCH=wasm GOOS=js go1.22.4 test -v
=== RUN   TestSanity
--- PASS: TestSanity (0.00s)
=== RUN   TestUnicode
--- PASS: TestUnicode (0.00s)
PASS
ok      github.com/agnivade/levenshtein 1.167s
14:38:52-~/play/agnivade/levenshtein] go1.22.4 env GOROOT
/home/agniva/sdk/go1.22.4
14:40:35-~/play/agnivade/levenshtein] ls /home/agniva/sdk/go1.22.4/misc/wasm/wasm_exec.js
/home/agniva/sdk/go1.22.4/misc/wasm/wasm_exec.js

Could you run an env GOROOT on your binary and paste the output?

@Zxilly
Copy link
Contributor Author

Zxilly commented Jun 25, 2024

(gsv-hyTHdi4q-py3.12) E:\Project\CS_Project\gsv\scripts git:[master]
go env GOROOT
C:/Users/zxilly/go/pkg/mod/golang.org/[email protected]

to reproduce, create a dir with the go.mod

module test
go 1.22
toolchain go1.22.4

then run go mod download.

After these, you will see the GOROOT points to the go toolchain dir.

@Zxilly
Copy link
Contributor Author

Zxilly commented Jun 25, 2024

Go Toolchain here means the new feature introduced in Go1.21. Please see https://go.dev/doc/toolchain.

@Zxilly
Copy link
Contributor Author

Zxilly commented Jun 25, 2024

Google's developers decided not to include the misc folder in the toolchain package, which can be found discussed at golang/go#68024.
In this case, we need to figure out how to get the files ourselves. I created my own node.js based wrapper with the logic https://github.com/Zxilly/go_js_wasm_exec/blob/ad3f10d1c513fc1f9a192b7d816d44c2bce4eccd/ensure.go#L61-L101 can be used as a reference.

@agnivade
Copy link
Owner

Ahh I see. Well, that's an interesting one. So in that case, I think the reasonable workaround would be to set the env var for GOROOT to the binary toolchain distribution that you have locally.

@Zxilly
Copy link
Contributor Author

Zxilly commented Jun 26, 2024

But this may break other things use the same logic but read the exist file. They will read the wrong edition.
Also, if wasm_exec.js got a update in new go version, this will make the user still works with the old one.
I think set a workaround for it is reasonable.

@agnivade
Copy link
Owner

Yes, the main binary distribution should atleast be the same minor version as the toolchain distribution. If you are using a newer minor version from the Go toolchain, then of course there will be issues.

But more importantly, this is only while running tests so you have more flexibility in how you run them. You can either choose to avoid using the downloaded toolchain, but instead use the binary distribution. Or you can use the toolchain version, but just vary in patch version from the binary toolchain.

@Zxilly
Copy link
Contributor Author

Zxilly commented Jun 26, 2024

I still think adding additional logic is necessary, toolchain can be implicitly enabled by go.mod and environment variables, and troubleshooting the problem can be very difficult for people who don't know this mechanism.
But this is your project and I respect your opinion.

@Zxilly
Copy link
Contributor Author

Zxilly commented Jun 26, 2024

And does GOROOT affect the go compiler's choice of standard libraries? Some problem that was fixed in the minor version might be reappeared by this operation.

@agnivade
Copy link
Owner

Thanks. On further thoughts, I think the best way is to have the directory included in the toolchain build. I have pinged in the issue for it to be reconsidered. Let's see.

@Zxilly
Copy link
Contributor Author

Zxilly commented Jun 27, 2024

Maybe you can pin this issue to let the users know what happened. Even if the proposal is accepted, we will need to wait for the next release to include these files.
Frankly, I'm not very confident in the efficiency of the Go team.

@agnivade
Copy link
Owner

@Zxilly - I believe this issue can be closed now? Let me know if there is anything else needed.

@Zxilly
Copy link
Contributor Author

Zxilly commented Oct 24, 2024

buf, err := os.ReadFile(path.Join(runtime.GOROOT(), "misc/wasm/wasm_exec.js"))

needs a fallback logic for new file location

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants