Tinygo, an LLVM-based Go compiler

tinygo

TinyGo: a Go compiler for small places

If you work with microcontrollers and you are a lover of Go, Tinygo may be for you, since this a Go p compiler is developedFor areas that require a compact representation of the resulting code and low resource consumption, such as embedded systems microcontrollers and WebAssembly.

TinyGo is a compiler that aims to bring the Go build to various target platforms which is implemented using LLVM, and the libraries used in the main Go project toolset are used to support the language.

On the Tinygo website, it is described that:

You can compile and run TinyGo programs on over 94 different microcontroller boards, including the BBC micro:bit and Arduino Uno.

TinyGo can also produce WebAssembly (WASM) code that is very compact in size. You can build programs for web browsers, as well as for servers and edge computing environments that support the WebAssembly System Interface (WASI) family of interfaces.

The reason for creating the TinyGO project was the desire to use the Go language common in compact devices- The developers reasoned that if there is a version of Python for microcontrollers, then why not create a similar one for the Go language?

In TinyGo, the compiled program can be run directly on microcontrollers, lor that it makes it possible to use Go as a language for writing automation scripts. TinyGo currently supports 94 microcontroller models, including various boards such as Raspberry Pi Pico, Nordic, SiFive, among others.

TinyGo provides the special drivers to interface with connected external devices and sensors, as well as to support interfaces such as I2C, GPIO, and SPI. Programs can also be compiled in WebAssembly (wasm/wasi) format to run in a browser and as Linux binaries.

Key objectives of the project:

  • The ability to use a subset of the familiar Go language on compact devices. Go was chosen over Rust because it is easier to learn, provides thread-independent support for routine-based parallelization, and offers an extensive standard library.
  • Generation of very compact executable files.
  • Support for the most common models of microcontroller boards.
  • The ability to use for the Web and create stand-alone WebAssembly applications using the WASI (WebAssembly
  • System Interface) to work with files, sockets, and other functions provided by the operating system.
  • CGo support with minimal overhead when calling C language functions.
  • Compatibility with most standard packages and the ability to compile generic existing code without changing it.
  • Unlike the similar deprecated emgo compiler, Tinygo retains Go's original memory management model through a garbage collector and uses LLVM instead of compiling into a C representation to generate efficient native code.

It is worth mentioning that Tinygo recently received a new version, which is 0.28 and in this new version it stands out that reflection support is significantly improved and offers its own implementation of the reflection library, which made it possible to achieve compatibility with many standard library packages that had problems before.

In addition, the new version adds support for the "//go:wasmimport" directive for importing features from WebAssembly, plus support for new cards like Gopher Badges.

Finally If you are interested in knowing more about it, you can check the details in the following link

How to install Tinygo on Linux?

For those who are interested in being able to install Tinygo, on Debian, Raspbian, Ubuntu and derivatives. They should open a terminal and in it we are going to execute the following command:

wget https://github.com/tinygo-org/tinygo/releases/download/v0.28.1/tinygo_0.28.1_amd64.deb sudo dpkg -i tinygo_0.28.1_amd64.deb

For the special case of systems for ARM devices (Raspbian and Ubuntu versions)

We are going to type the following:

wget https://github.com/tinygo-org/tinygo/releases/download/v0.28.1/tinygo_0.28.1_arm64.deb sudo dpkg -i tinygo_0.28.1_arm64.deb

In the case of those who are users of Arch Linux and derivatives, they must execute the following command:

sudo pacman -S tinygo

Now for the case of Fedora users:

sudo dnf install tinygo

After you have completed the installation, they should make sure the tinygo's path is in their PATH.

export PATH=$PATH:/usr/local/tinygo/bin

Finally for verify installation we are going to type the following command:

tinygo version

And he must throw us something like that

tinygo version 0.28.1 linux/amd64

To learn more about it, you can consult the following link. 


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.