News for hackers. Stuff that matters.
Re:Tinygo: LLVM-based Go compiler for microcontrollers, WASM... by Sean-Der on Sunday June 05, 2022 @11:28PM (#31637019)
Huge fan of Tinygo. I use it for the reduced WASM sizes. I see ~10x reduction when using it. I am working on a project that does some business logic/text parsing[0] that I want to be available on multiple platforms.

With TinyGo + wasmer[1] I can build a library that is usable in Python, PHP, Javascript and C++. It has been a lot of fun for me. Lots of rough edges still exist when moving between WASM/calling language, but when you get it working it feels amazing.

[0] https://github.com/pion/explainer

[1] https://wasmer.io/

Re:Tinygo: LLVM-based Go compiler for microcontrollers, WASM... by liftm on Monday June 06, 2022 @07:46AM (#31639253)
Tinygo is neat, but the one time I tried to use it in practice, it failed me. The following program will panic when compiled to wasm:

  package main  
  import "encoding/json"  
  func main() {  
          var parsed interface{}  
          json.Unmarshal([]byte(`{"test":42}`), &parsed)  
  }
(It's been a while, so I forgot the problem with it was.)

I'm curious what kind of text parsing you do. I ended up rolling with valyala/fastjson, but that's very much not what I was imagining. Lots of existing libraries don't work either, and finding out what does and what doesn't is pain. Is there some trick to working with it?

Re:Tinygo: LLVM-based Go compiler for microcontrollers, WASM... by maxmcd on Monday June 06, 2022 @12:17PM (#31642361)
I don't think "encoding/json" is fully working yet.

Seems to be importable now, although tests are not passing. See supported packages here: https://tinygo.org/docs/reference/lang-support/stdlib/

Definitely still a ways to go before the full stdlib is usable.

Looks like your code still fails at runtime with the error:

    panic: unimplemented: (reflect.Type).NumMethod()
Tested here: https://play.tinygo.org/
Re:Tinygo: LLVM-based Go compiler for microcontrollers, WASM... by eek2121 on Monday June 06, 2022 @01:06AM (#31637390)
Dunno bro, it doesn't work on the 6502, so... ;)
Re:Tinygo: LLVM-based Go compiler for microcontrollers, WASM... by Joker_vD on Monday June 06, 2022 @11:14AM (#31641549)
By today standards, 6502 is a nanocontroller... or maybe even a picocontroller. Go buy yourself a real microcontroller, y'hear me? /s
Re:Tinygo: LLVM-based Go compiler for microcontrollers, WASM... by connicpu on Monday June 06, 2022 @12:40PM (#31642696)
I mean in a world where a 32-bit microcontroller with flash in the 1-2MB range and a few hundred KiB RAM can cost less than $2 why make things harder on yourself :P

If you're using a chip without the bells and whistles for precise timing reasons, then you're probably gonna program it in assembly too anyways

Re:Tinygo: LLVM-based Go compiler for microcontrollers, WASM... by ThePhysicist on Monday June 06, 2022 @06:16AM (#31638741)
Tinygo is great. I think they could address a much larger "market" by improving support for ARM-based systems, notably iOS and Android. I've experimented with cross-compiling Golang code for these platforms and it works great with tools like gomobile, the binary size and runtime overhead can be prohibitive though. I looked at Tinygo to see if it could help with that but couldn't figure out how to compile code for Android, I think it would have been a perfect solution otherwise. In my understanding it supports most of the TLS stack and many other standard libraries as well, which makes it realistic to use it as a systems language on mobile platforms.

I know that Tailscale keeps their own fork of Golang with some optimizations for mobile as well, and where they try to merge stuff back into the mainline, so maybe in the future binary size and runtime overhead will go down for regular Golang. Tinygo seems to do a much better job at reducing that though, so it would be great to have it work on mobile.

Re:Tinygo: LLVM-based Go compiler for microcontrollers, WASM... by aykevl on Friday June 10, 2022 @11:00AM (#31695136)
Right now we don't have any support for Android and iOS in particular, but we do support Linux/ARM (regular Linux). It's an interesting use case however.

> In my understanding it supports most of the TLS stack and many other standard libraries as well

We don't have a proper net package yet so usage on Android/iOS will be rather limited.

Re:Tinygo: LLVM-based Go compiler for microcontrollers, WASM... by avl999 on Monday June 06, 2022 @03:14AM (#31637983)
Another advantage of tinygo is that unlike "Go proper" FFI with C code is blazingly fast, which makes it a reasonable option for inter-oping with C-library- whereas use of Cgo is actively discouraged in "Go proper" due to performance and other reasons. So using board specific libraries which are very likely to be in C is doable via tinygo.
Re:Tinygo: LLVM-based Go compiler for microcontrollers, WASM... by kyrra on Sunday June 05, 2022 @10:59PM (#31636919)
Aside: the go team maintains frontends for gcc and llvm, though not targeting microcontrollers like this.

https://github.com/golang/gofrontend

https://go.googlesource.com/gollvm/

Re:Tinygo: LLVM-based Go compiler for microcontrollers, WASM... by svnpenn on Sunday June 05, 2022 @11:20PM (#31636991)
do either one of those have builds? I would like to try them out, but not enough to build myself
Re:Tinygo: LLVM-based Go compiler for microcontrollers, WASM... by yjftsjthsd-h on Monday June 06, 2022 @12:43AM (#31637313)
Oof - I clicked through thinking "oh, it can't be that bad", but that looks like it's doing an llvm build which can be a bear in terms of disk/CPU/RAM IIRC.
Re:Tinygo: LLVM-based Go compiler for microcontrollers, WASM... by 4ad on Monday June 06, 2022 @02:48AM (#31637853)
Gccgo is packaged by any reasonable Linux distribution.
Re:Tinygo: LLVM-based Go compiler for microcontrollers, WASM... by svnpenn on Monday June 06, 2022 @08:05AM (#31639410)
I'm using Windows
Re:Tinygo: LLVM-based Go compiler for microcontrollers, WASM... by 4ad on Monday June 06, 2022 @08:39AM (#31639701)
Gccgo does not support windows.
Re:Tinygo: LLVM-based Go compiler for microcontrollers, WASM... by socialdemocrat on Monday June 06, 2022 @09:09AM (#31639972)
I have been very interested in the Zig language for doing micro-controller stuff as I wanted a more modern version of C. But I am beginning to think Tinygo is a better alternative for me. No doubt Zig is a great language but I don't want to always be chasing obscure languages. Go has the benefit of being quite mainstream at this point with a decent size community.

Go is also extremely easy to learn and get going with.

Re:Tinygo: LLVM-based Go compiler for microcontrollers, WASM... by rowanG077 on Thursday June 09, 2022 @05:09AM (#31679115)
Tinygo is honestly extremely niche. Similar to circuitpython or micropython I really wouldn't reccomend anything but hobby toys to be written in it.
Re:Tinygo: LLVM-based Go compiler for microcontrollers, WASM... by dkegel on Saturday June 11, 2022 @12:17AM (#31701876)
Tinygo is supported by several edge computing platforms, and works well for at least one commercial application.

If you need wasm/wasi support, and you're ok with working around the partial support for reflect etc., it's not a bad choice.

Re:Tinygo: LLVM-based Go compiler for microcontrollers, WASM... by mseepgood on Sunday June 05, 2022 @11:32PM (#31637038)
The website: https://tinygo.org/
Re:Tinygo: LLVM-based Go compiler for microcontrollers, WASM... by skybrian on Monday June 06, 2022 @12:35AM (#31637278)
For Arduino-like microcontroller programming, board and device support are pretty important (much like an operating system). Which ones you care about depends on your application.

Looks like they have support listed for lots of boards [1] and lots of devices [2]. It won't work for me yet, though, because I need USB serial and MIDI, and they seem not to be implemented yet, at least for the Teensy and Raspberry Pi Pico.

[1] https://tinygo.org/docs/reference/microcontrollers/ [2] https://tinygo.org/docs/reference/devices/

Re:Tinygo: LLVM-based Go compiler for microcontrollers, WASM... by tony-allan on Monday June 06, 2022 @02:40AM (#31637813)
Is Wi-Fi for ESP32 devices is working yet?

I didn't see anything specific one the supported boards page.

Re:Tinygo: LLVM-based Go compiler for microcontrollers, WASM... by sp33k3rph433k on Monday June 06, 2022 @01:32PM (#31643285)
I was recently working on a project and bumped into this. It's not currently but here are the relevant Github links if you want to learn more (it doesn't look like there's much movement recently):

https://github.com/tinygo-org/tinygo/issues/1427

https://github.com/tinygo-org/drivers/pull/320