rules_go icon indicating copy to clipboard operation
rules_go copied to clipboard

tinygo support

Open edieYoung opened this issue 2 years ago • 7 comments

Hi there, we need to use tinygo for building the WASM module in envoy since standard Go complier doesn't support WASI(WebAssembly System Interface), see details at here, so we wonder if there is a plan or effort for bazel rules_go to support tinygo?

edieYoung avatar Jun 13 '22 22:06 edieYoung

@edieYoung this would be a great contribution to make to the rules_go project! I believe you're the first person to have this need. We do not currently have support, but I would be interested in learning more. How can I help you in the process of adding it as an option to rules_go?

achew22 avatar Jun 14 '22 22:06 achew22

Hey! I'm also interested in adding support to tinygo in rules_go. We are using it to build Envoy Wasm plugins (for Istio).

Our build command looks like:

 tinygo build -o plugin.wasm -scheduler=none -target=wasi main.go

The tinygo compiler is compatible with go.mod and dependency management. The -target=wasi flag indicates for which target are we building the plugin. If you download the tinygo sdk you will find a targets directory with multiple .json definitions, one for each target.

I would say that rules_go could be compatible with tinygo by using go_download_sdk and generating a custom tarball with the same structure as the go sdk (renaming tinigo binary as go, etc). I'm not sure what would happen with the targets.

@achew22 what is your recommendation to add support for tinygo in rules_go ?

pmoncadaisla avatar Aug 01 '22 11:08 pmoncadaisla

I'm not aware of anyone who is using the tinygo compiler at this point in time so firstly this would have to be implemented by someone with some experience in that ecosystem.

That said, the first thing to do would be to build a go_toolchain which would then probably use go_wrap_sdk with a directory structure emulating the standard go tooling package structure. Then you would register that toolchain in the project and I think thing would mostly just work.

WRT targeting wasm, there might need to be some additional work there, but I would start by getting it to compile binaries compatible with your computer.

achew22 avatar Aug 02 '22 00:08 achew22

The file coin virtual machine and wasm cloud both require tiny go compiled programs. We are in the process of supporting both those environments. Therefore, we are very interested in tiny go as a build target for bazel.

ng-druid avatar Mar 12 '23 12:03 ng-druid

We are going to attempt this but are not very comfortable with it. Going to be a challenge…

However, the work is worth the challenge considering the doors it opens without needing to rewrite our code base in r.

Doors opened:

  • wsm cloud deployment wasm cloud
  • fvm (file coin virtual machaine) deployment fmv
  • 10x smaller binary size

All things we are very interested to explore.

https://github.com/rollthecloudinc/rules_go

ng-druid avatar Mar 14 '23 09:03 ng-druid

For further explore on this topics... this article explain very well... in various steps... https://jayconrod.com/posts/106/writing-bazel-rules--simple-binary-rule

josejuanmontiel avatar May 23 '23 08:05 josejuanmontiel