-
Notifications
You must be signed in to change notification settings - Fork 763
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
TinyGo integration #628
Comments
@aykevl thanks for sharing the extension. It's exciting to see vscode used for tinygo development!
I have a question: why is it necessary to set |
That's good to hear! Tools that hardcode GOROOT would be a problem for TinyGo.
Technically yes. Appending could indeed work but seems far more complicated than overwriting after asking for it. I already leave existing keys intact (I just overwrite GOROOT and GOFLAGS, leaving the rest alone).
In my tests it doesn't, at least not with GOFLAGS. Good to know it's supposed to do this, do you have any hints how I can debug such a thing?
I have, but it's not the right solution (even if it mostly works in this case). More below...
Setting GOROOT is absolutely necessary. I don't have it documented but this is how TinyGo loads dependencies (and supports Go modules) using Before Go modules were supported in TinyGo, there was a different way of loading dependencies. Basically it would do its own dependency resolution and switch the GOROOT/GOPATH depending on which package was being loaded. That was of course rather complex and really hard to support in IDEs. With Go modules I didn't want to implement that all in TinyGo (and I wanted to stay more compatible with the rest of the Go ecosystem) so I came up with a different solution that creates a special GOROOT that is essentially a directory full of symlinks to the actual packages (either in the standard library GOROOT or in the TinyGo root with its custom packages). This is not an ideal situation but it's the best I could come up with. Alternatives I've considered:
And as to why TinyGo needs to replace the runtime package: TinyGo is a new Go compiler and to be able to target small microcontrollers, it needs to be as space-efficient as possible. There is no MMU (often not even an MPU). Incremental GC doesn't add any value in 2kB or 16kB of RAM. These systems are often single-core, so scheduling is just a simple round-robin. In other words: the constraints are so different that using the standard library runtime doesn't work for TinyGo. |
Change https://golang.org/cl/254370 mentions this issue: |
@aykevl Thanks a lot for the detailed explanation. Yeah, convincing Independent of this issue, we've been talking about separating the tools build logic from the target build logic completely. That allows
Currently the extension applies Will there still be any case where tiny go users need to run the go command and other tools without the tinygo specific env variables?
:-) ah, sorry, I meant overwriting the entries. You will need to use other keys intact - for example, some users need to set
I confirm that's a bug. I sent cl/254370 to fix this. |
go.toolsEnvVars setting affects how gopls launches. See src/goEnv.ts toolExecutionEnvironment. Updates #628 Change-Id: I6294af2d4dd1822b7dfbe571532c6f2d18089608 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/254370 Reviewed-by: Rebecca Stambler <[email protected]>
Ignoring TinyGo, it certainly doesn't seem right that if you set GOARCH=arm for cross compiling to a Raspberry Pi, the next gopls update builds a gopls for ARM instead of the host architecture (usually amd64) and fails to execute. So I agree that it makes sense to separate the two. I might even go as far as arguing that you probably shouldn't change such environment variables for the installation of tools: I can't think of a case where the defaults aren't appropriate. For TinyGo specifically, yes I believe this would totally solve the issue with errors when recompiling tools.
Probably yes, but this is something the TinyGo extension already takes care of. It allows reverting all the TinyGo specific settings. After all, you might want to test some functionality for multiple build targets to make sure it still works.
Certainly, the TinyGo extension leaves those fields alone. A variable like
Thanks a lot! That should make the UX of the extension a lot better. (I haven't confirmed the fix yet, though). EDIT: I patched my local |
We saw users who had to configure some settings through the environment variables (network, proxy, etc...) and launching vscode with the necessary environment variables set is sometimes not as easy as it sounds for some cases.
Thanks for being patient. I am currently working on 0.17.0 release, which was originally targeted for yesterday but we are behind schedule obviously. |
Ah, I see. Network configuration in environment variables may indeed be important to configure even for building Go tools. |
Change https://golang.org/cl/264323 mentions this issue: |
@aykevl In cl/264323, I am proposing to unset GOOS/GOARCH/GOROOT/GOENV/GOFLAGS environment variables inherited from (We will still look into a way to get rid of the spurious go tool update request.) |
That should be a solid improvement. If none of those vars (especially GOROOT and GOFLAGS) are passed to the |
Tool installation is to build tools that would run in the host machine. Applying GOOS/GOARCH/GOROOT/GOFLAGS/GOENV set to build a cross-platform project is not the right choice. Unset them and let the `go` command figure out. There could be other environment variables that would affect build (GCCGO, ..), and we will consider unsetting them. Update #628 Change-Id: I295a0ae455aa2624550a16f69686bdf191fe41fd Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/264323 Run-TryBot: Hyang-Ah Hana Kim <[email protected]> TryBot-Result: kokoro <[email protected]> Trust: Hyang-Ah Hana Kim <[email protected]> Reviewed-by: Suzy Mueller <[email protected]>
And not sure if it makes any differences but Moreover, the extension is now exporting API with which the external extensions can also retrieve the location of tools binaries (e.g. I hope this addresses the primary concern from the original report (i.e. |
Awesome! It sounds like this addresses all my concerns, but I need to investigate the new API to be sure. |
I've been looking into proper TinyGo integration for VS Code the last few days. This has resulted in the following experimental extension:
https://github.com/tinygo-org/vscode-tinygo
What it currently does is modify
go.toolsEnvVars
in the workspace for use with TinyGo (GOROOT
andGOFLAGS
) using thevscode.workspace.getConfiguration
API. This works, but has some side effects:GOROOT
changed (Reinstall tools when a GOROOT change is detected microsoft/vscode-go#1286). This won't work as the GOROOT is specifically for TinyGo, not for regular Go (most importantly, the runtime has been replaced).go.toolsEnvVars
. For example, someone might have configured something there, which is then overwritten without even asking.I'm not sure what the best solution for this would be, but one possible solution would be if the new extension could hook into the Go extension to set the new environment variables with some kind of API. The Go extension would then know not to use these environment variables while building tools, for example. It could also immediately reload
gopls
with the new settings after this new API call.This is how such an API could be supported: https://code.visualstudio.com/api/references/vscode-api#extensions
The text was updated successfully, but these errors were encountered: