TinyGo setup with GoLand
After a year-long hiatus from TinyGo, I’ve returned to retrieve the latest release and initiate a new project in my favourite IDE - GoLand. Regrettably, I encountered issues with importing drivers’ libraries, nothing was compiling properly... After grappling with configuration challenges, and grasping information from articles, official documentation and Slack, I decided to document my troubleshooting journey here.
My configuration is the following:
- macOS M1
- tinygo version 0.23.0
- Goland
- TinyGo plugin
If you do not have TinyGo, you can install it using brew. Other installation options are described in TinyGo documentation.
Otherwise, you can just make sure you are upgrade to the latest version:
$ brew upgrade tinygo
Check tinygo installation:
$ tinygo version
tinygo version 0.30.0 darwin/amd64 (using go version go1.21.6 and LLVM version 16.0.1)
1. Setup the GOROOT
You will need several characteristics provided by tinygo info command, firstly the cached GOROOT:
$ tinygo info
LLVM triple: x86_64-apple-macosx10.12.0
GOOS: darwin
GOARCH: amd64
build tags: darwin amd64 tinygo math_big_pure_go gc.precise scheduler.tasks serial.none
garbage collector: precise
scheduler: tasks
cached GOROOT: /Users/doniacld/Library/Caches/tinygo/goroot-889c52474e5e4727a20b14cffb7182045a536d2fabaee64e083c0d4ce847d71e
In your IDE go to GoLand tab > Preferences > Go and choose the path to the GOROOT you just obtained.
2. Setup the GOPATH
Remove the Global GOPATH and add to the Project GOPATH:
- the path to TinyGo
- your usual GOPATH
The idea behind this is to have at the top the TinyGo one.
Note that I removed “Use GOPATH that’s defined in system environment”.
3. Enable Go modules integration
You can setup Go modules integration.
4. Update Build Tags and Vendoring
Setup the constraints corresponding to your OS. You can find all this information again by running tinygo info command.
- OS: darwin
- Arch: amd64
- Custom tags: darwin amd64 tinygo math_big_pure_go gc.precise scheduler.tasks serial.none
5. TinyGo plugin configuration
Choose the path to TinyGo SDK pointing to the latest version you installed.
The target platform corresponds to the microcontroller your code will be running. Setup the Garbage Collector to conservative and the Scheduler to none. Retrieve the build tags from the output tinygo info command.
6. Update dependencies
If you already wrote some code, you might see red imports. Let’s fix this.
Run go mod tidy to download missing dependencies:
$ go mod tidy
go: finding module for package tinygo.org/x/drivers/ws2812
go: finding module for package tinygo.org/x/drivers/st7789
go: downloading tinygo.org/x/drivers v0.27.0
go: found tinygo.org/x/drivers/st7789 in tinygo.org/x/drivers v0.27.0
go: found tinygo.org/x/drivers/ws2812 in tinygo.org/x/drivers v0.27.0
Do not forget to synchronize your dependencies on IDE side and you are good to go.
Now you should be able to see your imports turning green after GoLand ran the indexing!
👏 Congrats! You can now enjoy your setup and start playing with TinyGo!
Want to discover TinyGo? You can watch my talk “TinyGo: Getting the upper Hen” at GopherCon EU 2022.
Follow me for more content:
- GitHub : https://github.com/doniacld
- Twitter : https://twitter.com/doniacld
- LinkedIn : https://www.linkedin.com/in/donia-chaiehloudj/