TinyGo's development environment setup for VS Code was a little troublesome, so I wrote it down. The official article is here. Please refer to other articles for installation and setup of TinyGo. Author's environment: MacBook Air (Retina, 13-inch, 2020) macOS Catalina 10.15.5
It was pointed out that .vscode / settings.json
is automatically generated when you install and set up the TinyGo extension below.
So you can skip the Creations.json Creation
part below.
~~ TinyGo seems to use GOROOT (?) In a different path from the original Go. [^ 1] ~~
As pointed out by @ sago35, TinyGo solves TinyGo dedicated packages such as machine
package from TinyGo's ROOT, and other import paths use normal Go language (GOPATH is also the original Go) (Same as). Thank you sago35!
Check the GOROOT path for TinyGo at ~~ tinygo info
. ~~
$ tinygo info microbit
//Output result...
// LLVM triple: armv6m-none-eabi
// GOOS: linux
// GOARCH: arm
// build tags: cortexm baremetal linux arm nrf51822 nrf51 nrf microbit tinygo gc.conservative scheduler.tasks
// garbage collector: conservative
// scheduler: tasks
// cached GOROOT: /home/user/.cache/tinygo/goroot-go1.14-f930d5b5f36579e8cbd1c139012b3d702281417fb6bdf67303c4697195b9ef1f-syscall
~~ cached GOROOT: ... The path of the line starting with
is GOROOT for TinyGo. ~~
Lines starting with ~~ build tags: ...
are options to use at build time. ~~
~~ You can mess with VSCode settings directly, but I don't want to affect normal Go development, so create a .vscode
folder in the project folder and create a settings.json
file. Create a.
At that time, it is okay to paste GOROOT
as it is, but GOFLAGS prefixes it with -tags sequentially and separates it with a comma (`,`) instead of a space. For example, in my environment, the result was
build tags: darwin amd64 tinygo gc.extalloc scheduler.coroutines.
-tags = darwin, amd64, tinygo, gc.extalloc, scheduler.coroutines``. ~~
settings.json
{
"go.toolsEnvVars": {
"GOROOT": "GOROOT that I got earlier...",
"GOFLAGS": "-tags=avr,baremetal,linux,arm,atmega328p,atmega,avr5,arduino,tinygo,gc.conservative,scheduler.none"
}
}
Install TinyGo from Extensions.
After installation, select Tiny Go target
from the command palette and select the microcomputer you are using.
In the case of the author, select ʻarduino` because it is an Arduino compatible machine Maruduino. [^ 2]
After making your selection, reload VS Code and if the "machine" package auto-completion works correctly, you're done.
[^ 1]: It seems that GOROOT or GOPATH is replaced with a unique one at the time of build (?), But I don't know the details ... I would appreciate it if anyone could teach me in the comments. [^ 2]: I was kind to myself as a beginner of microcomputers, and I was able to get along with choosing Arduino. Thank you marutsu ...!
Recommended Posts