{"id":20285423,"url":"https://github.com/mramshaw/tinygo","last_synced_at":"2026-05-08T05:54:58.005Z","repository":{"id":92906604,"uuid":"187383983","full_name":"mramshaw/TinyGo","owner":"mramshaw","description":"Experimenting with TinyGo","archived":false,"fork":false,"pushed_at":"2019-05-28T11:03:44.000Z","size":134,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-14T08:12:17.955Z","etag":null,"topics":["go","golang","microprocessor","raspberry-pi"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mramshaw.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-05-18T17:02:18.000Z","updated_at":"2019-05-28T11:03:45.000Z","dependencies_parsed_at":"2023-04-25T17:03:01.510Z","dependency_job_id":null,"html_url":"https://github.com/mramshaw/TinyGo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mramshaw%2FTinyGo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mramshaw%2FTinyGo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mramshaw%2FTinyGo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mramshaw%2FTinyGo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mramshaw","download_url":"https://codeload.github.com/mramshaw/TinyGo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241780512,"owners_count":20019061,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","golang","microprocessor","raspberry-pi"],"created_at":"2024-11-14T14:26:35.260Z","updated_at":"2025-12-02T08:00:57.191Z","avatar_url":"https://github.com/mramshaw.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TinyGo\n\n![TinyGo logo](images/TinyGo.png)\n\nAs a longtime [Golang](http://github.com/mramshaw/Golang) fan, I have cross-compiled\nGo programs against [MUSL](#musl) and experimented with\n[MQTT](https://github.com/mramshaw/MQTT_and_mosquitto)\n(an IoT protocol for sensors and devices such as the Arduino or Raspberry Pi).\nI have also experimented with the\n[Raspberry Pi](https://github.com/mramshaw/Speech-Recognition#raspberry-pi)\n(a single-board microcomputer) so TinyGo sounded like it was worth a look.\n\n## Contents\n\nThe contents are as follows:\n\n* [What is TinyGo?](#what-is-tinygo)\n* [Prerequisites](#prerequisites)\n* [Installation](#installation)\n* [Building](#building)\n* [Options](#options)\n* [Targets](#targets)\n    * [ARM](#arm)\n    * [AVR](#avr)\n* [Running](#running)\n    * [Compile WASM](#compile-wasm)\n    * [Run webserver](#run-webserver)\n    * [Open browser](#open-browser)\n* [Reference](#reference)\n    * [TinyGo references](#tinygo-references)\n    * [LLVM](#llvm)\n    * [MUSL](#musl)\n    * [WebAssembly](#webassembly)\n* [Alternatives](#alternatives)\n    * [EMBD](#embd)\n    * [MicroPython](#micropython)\n    * [periph](#periph)\n* [Credits](#credits)\n* [To Do](#to-do)\n\n## What is TinyGo?\n\n\u003e TinyGo is a Go compiler intended for use in small places such as microcontrollers,\n\u003e WebAssembly (WASM), and command-line tools.\n\nAnd:\n\n\u003e TinyGo is a project to bring Go to microcontrollers and small systems with a single processor core.\n\nBoth of the above quotes are from:\n\n    http://github.com/tinygo-org/tinygo\n\nTinyGo was originally started by Ayke van Laëthem, who was a contributor to [MicroPython](http://github.com/micropython/micropython/)\n(a version of Python that runs on microcontrollers) and other projects in the embedded space.\n\n## Prerequisites\n\nRequires __Go v1.11__ or greater.\n\nVerify as follows:\n\n```bash\n$ go version\ngo version go1.11 linux/amd64\n$\n```\n\nRequires libstdc++6 __3.4.22__ or greater. Verify this as follows:\n\n```bash\n$ strings /usr/lib/x86_64-linux-gnu/libstdc++.so.6 | grep GLIBCXX\n```\n\nIf `GLIBCXX_3.4.22` is not listed, then libstdc++6 must be installed or upgraded.\n\nOn Ubuntu, this can be done as follows:\n\n```bash\n$ sudo add-apt-repository ppa:ubuntu-toolchain-r/test\n...\n$ sudo apt-get update\n...\n$ sudo apt-get upgrade libstdc++6\n...\n$\n```\n\n## Installation\n\nAs per the instructions, download and install as follows:\n\n```bash\n$ wget https://github.com/tinygo-org/tinygo/releases/download/v0.5.0/tinygo_0.5.0_amd64.deb\n...\n$ sudo dpkg -i tinygo_0.5.0_amd64.deb\n...\n$\n```\n\nNote that the version number is subject to change. Check for the latest release here:\n\n    http://github.com/tinygo-org/tinygo/releases\n\nVerify the installation as follows:\n\n```bash\n$ /usr/local/tinygo/bin/tinygo version\ntinygo version 0.5.0 linux/amd64\n$\n```\n\n[By default TinyGo is installed in __/usr/local/tinygo/__ with __root__ permissions but globally executable.]\n\n## Building\n\nBuilding TinyGo is straightforward, but on Ubuntu will require __cmake__ \u0026 __cmake-data__ as well as __ninja-build__.\n\n## Options\n\nFind out more about TinyGo and its capabilities as follows:\n\n```bash\n$ /usr/local/tinygo/bin/tinygo help\nTinyGo is a Go compiler for small places.\nversion: 0.5.0\nusage: /usr/local/tinygo/bin/tinygo command [-printir] [-target=\u003ctarget\u003e] -o \u003coutput\u003e \u003cinput\u003e\n\ncommands:\n  build: compile packages and dependencies\n  run:   compile and run immediately\n  flash: compile and flash to the device\n  gdb:   run/flash and immediately enter GDB\n  clean: empty cache directory (/home/owner/.cache/tinygo)\n  help:  print this help text\n\nflags:\n  -cflags string\n        additional cflags for compiler\n  -dumpssa\n        dump internal Go SSA\n  -gc string\n        garbage collector to use (none, dumb, marksweep)\n  -ldflags string\n        additional ldflags for linker\n  -no-debug\n        disable DWARF debug symbol generation\n  -o string\n        output filename\n  -ocd-output\n        print OCD daemon output during debug\n  -opt string\n        optimization level: 0, 1, 2, s, z (default \"z\")\n  -port string\n        flash port (default \"/dev/ttyACM0\")\n  -printir\n        print LLVM IR\n  -size string\n        print sizes (none, short, full)\n  -target string\n        LLVM target\n  -wasm-abi string\n        WebAssembly ABI conventions: js (no i64 params) or generic (default \"js\")\n$\n```\n\n## Targets\n\nStraight out of the box, TinyGo can be used to compile to [WebAssembly](#webassembly).\n\nFor hardware platforms such as ARM or AVR there are additional requirements.\n\nThe full list of supported boards is provided here:\n\n    http://github.com/tinygo-org/tinygo#supported-boardstargets\n\n#### ARM\n\nARM processors are apparently well supported.\n\nFrom:\n\n    https://tinygo.org/compiler-internals/microcontrollers/\n\n\u003e ARM Cortex-M processors are well supported.\n\nARM devices apparently require __clang-8__.\n\n#### AVR\n\nArduino (AVR) devices apparently require __gcc-avr__, __avr-libc__ and __avrdude__.\n\n## Running\n\nWe will try it out for WASM as follows:\n\n1. [Compile WASM](#compile-wasm)\n2. [Run webserver](#run-webserver)\n3. [Open browser](#open-browser)\n\n#### Compile WASM\n\nCompile our Golang code to WASM as follows:\n\n```bash\n$ cd src\n$ /usr/local/tinygo/bin/tinygo build -o ./wasm.wasm -target wasm ./wasm.go\n$\n```\n\n#### Run webserver\n\nLaunch a web server to serve up our WASM-enriched HTML:\n\n```bash\n$ cd ..\n$ go run server.go\n2019/05/18 16:42:41 Serving './src' on http://localhost:8080\n^Csignal: interrupt\n$\n```\n\nThis is important as our WASM needs to be properly MIME-encoded.\n\nAs usual, \u003ckbd\u003eCtrl-C\u003c/kbd\u003e to terminate once testing is complete.\n\n#### Open browser\n\nOpen a javascript-enabled browser to the following URL:\n\n    http://localhost:8080/\n\nAnd test. The results should look as follows:\n\n![WASM working](images/WASM_working.png)\n\n## Reference\n\nSome useful references are listed below.\n\n#### TinyGo references\n\nThe TinyGo repo can be found here:\n\n    http://github.com/tinygo-org/tinygo\n\nGetting started with TinyGo:\n\n    http://tinygo.org/getting-started/linux/\n\nUsing TinyGo for WebAssembly:\n\n    http://tinygo.org/webassembly/webassembly/\n\n[It appears to be late-compiled, as you can mix and match JavaScript and TinyGo function calls.]\n\nHeap Allocation:\n\n    http://tinygo.org/compiler-internals/heap-allocation/\n\nHow much of Go is implemented in TinyGo:\n\n    http://tinygo.org/lang-support/\n\n[Personal testing also indicates that __runes__ are not yet fully supported in TinyGo.]\n\n#### LLVM\n\nLLVM is designed for compile-time, link-time, run-time, and \"idle-time\" optimization of programs written\nin arbitrary programming languages (among them are Kotlin, Lua, Rust and Swift). Despite its name, it has\nnothing to do with virtual machines.\n\nTinyGo takes the Golang [SSA](http://en.wikipedia.org/wiki/Static_single_assignment_form) and passes it\nto the LLVM toolchain. For more details the following article is worth a look:\n\n    http://aykevl.nl/2019/04/llvm-from-go\n\nProbably the definitive site for learning about LLVM:\n\n    http://llvm.org/\n\n#### MUSL\n\nProbably the definitive site for learning about MUSL:\n\n    http://www.musl-libc.org/\n\nMUSL is used as the standard C library by the Alpine Linux distribution.\n\nAccording to Wikipedia:\n\n\u003e Musl was designed from scratch to allow efficient static linking and to have realtime-quality robustness\n\u003e by avoiding races, internal failures on resource exhaustion and various other bad worst-case behaviors\n\u003e present in existing implementations\n\nAnd:\n\n\u003eIt also implements most of the widely used non-standard Linux, BSD, and glibc functions.\n\nBoth of the above quotes are from:\n\n    http://en.wikipedia.org/wiki/Musl\n\nThe second quote is particularly important; MUSL only implements ***most*** of the standard\nglibc functions, which means it cannot be simply used as a drop-in replacement for glibc.\n\nNevertheless, if used carefully it can be used as a replacement for ***most*** uses.\n\nFor more information, please refer to the following link:\n\n    http://wiki.musl-libc.org/compatibility.html\n\n#### WebAssembly\n\nFor those familiar with [Java applet](http://en.wikipedia.org/wiki/Java_applet) fundamentals,\nWebAssembly looks very much like the portable [Java bytecode](http://en.wikipedia.org/wiki/Java_bytecode)\nthat enabled Java applets to run in Java-enabled browsers.\n\n\u003e WebAssembly (abbreviated Wasm) is a binary instruction format for a stack-based virtual machine.\n\u003e Wasm is designed as a portable target for compilation of high-level languages like C/C++/Rust,\n\u003e enabling deployment on the web for client and server applications.\n\n    http://webassembly.org\n\nWebAssembly seems to be primarily associated with Rust but has been a topic of interest in the\nGolang community for some time. For instance:\n\n    http://changelog.com/gotime/bonus-77\n\n[At various Go meetups I have attended, WASM has been discussed.]\n\n## Alternatives\n\nAs usual, there are alternative solutions - some of which are listed below.\n\n#### EMBD\n\nEMBD supports the Raspberry Pi, BeagleBone Black, and CHIP. There are (possibly) other options.\n\nEMBD is sponsored by [Thoughtworks](http://www.thoughtworks.com/).\n\n[It appears to be defunct, but is probably still worth a look.]\n\nHome page:\n\n    http://embd.kidoman.io/\n\nSource code (Last updated 7 May 2017):\n\n    http://github.com/kidoman/embd\n\nGo Doc:\n\n    http://godoc.org/github.com/kidoman/embd\n\n#### MicroPython\n\nIt's Python-like (Python 3 specifically) rather than Golang-like, but may be useful.\n\nHome page:\n\n    http://micropython.org/\n\nSource code:\n\n    http://github.com/micropython/micropython/\n\n#### periph\n\nIt's a Google project.\n\nHome page:\n\n    http://periph.io/\n\nSource code:\n\n    https://github.com/google/periph/\n\nSupported devices:\n\n    http://periph.io/device/\n\n## Credits\n\nInspired by this podcast:\n\n    http://changelog.com/gotime/84\n\n## To Do\n\n- [x] Add Alternatives\n- [x] Add notes on compiling TinyGo\n- [x] Add string reversal code\n- [ ] More testing\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmramshaw%2Ftinygo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmramshaw%2Ftinygo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmramshaw%2Ftinygo/lists"}