Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate host functions for using as exportable library or SDK #35

Merged

Conversation

dmvolod
Copy link
Contributor

@dmvolod dmvolod commented Mar 15, 2023

Issue #, if available:

Description of changes:
This PR makes it possible to generate a plugin consisting only of host functions that can be built into other plugins. Allows to create and distribute resusable SDK/library solutions that are compatible with this plugin.

The following changes have been made

  • Able to specify wasm-module name ("env" by default if not specified")
  • Exported Instantiate function for host functions
  • PR specific examle and test
  • README.md file inside for example

Motivation
The wazero library allows you to create host functions and libraries based on them in golang, which can be used in any golang application. However, in some cases, the code that is generated by this plugin must be the source for other plugins, i.e. represent some standard interfaces that need to be implemented and a strict set of specific functions that can or should be used to access the host system.
For example, it can be a plugin that is an extension of the Kubernetes operator functionality that implements some small peace of logic. This plugin already has a simple description and generation of host functions with the described interaction interface in the form of gRPC. Eventually, it will be possible to write wrapper functions to easily interact with host functions and package them as a library or SDK.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@codefromthecrypt
Copy link
Collaborator

in the middle of release again, so if no one else gets back to you and I don't by Saturday.. nag me!

Copy link
Collaborator

@codefromthecrypt codefromthecrypt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy about this, but really think another maintainer should chime in one way or another as it is a major change.

A couple clarifying questions that may help:

  • Can you show a working PR on another open source project that uses this?
  • Do you foresee any issues with multiple plugins?

@dmvolod
Copy link
Contributor Author

dmvolod commented Mar 17, 2023

I'm happy about this, but really think another maintainer should chime in one way or another as it is a major change.

A couple clarifying questions that may help:

  • Can you show a working PR on another open source project that uses this?
  • Do you foresee any issues with multiple plugins?

Yes, sure. I'm working on the Kubernetes client proxy host functions which will utilize current approach. Will try to share soon

@dmvolod
Copy link
Contributor Author

dmvolod commented Mar 18, 2023

@codefromthecrypt build very early and simple draft of the wasm-k8s-host-proxy build on top the current plugin approach and this PR fix

@codefromthecrypt
Copy link
Collaborator

@dmvolod great.. one last request before I nag others to look at this. I'll be at wasmio with others, so it will be easy to get people to look. Can you add a README to your example, reviewing what it is doing, and how to run this (apart from invoking protoc?). I'm assuming you won't be at wasmio to showcase this yourself, so I will be basically doing this for you.

Generally when things are all explained, it is simple to get feedback on a large change from folks a little distant from the project. Thanks for your patience while I try to champion this for you and the project in general!

@dmvolod
Copy link
Contributor Author

dmvolod commented Mar 20, 2023

@dmvolod great.. one last request before I nag others to look at this. I'll be at wasmio with others, so it will be easy to get people to look. Can you add a README to your example, reviewing what it is doing, and how to run this (apart from invoking protoc?). I'm assuming you won't be at wasmio to showcase this yourself, so I will be basically doing this for you.

Thanks a lot, @codefromthecrypt for taking care my contribution.
I would nice to attend an event like a wasmio , but I'm not sure that it will ever be possible

Generally when things are all explained, it is simple to get feedback on a large change from folks a little distant from the project. Thanks for your patience while I try to champion this for you and the project in general!

Added a README.md with approach description and simple example

@codefromthecrypt
Copy link
Collaborator

thank you for this! I will in the next couple days pull feedback besides mine one way or another 🔫 :)

@codefromthecrypt
Copy link
Collaborator

ok taking a close look now

@codefromthecrypt
Copy link
Collaborator

@dmvolod wow this looks very practical. After I have feedback from someone I am tagging below, I'll merge this.

@salaboy I know in the future you may be doing more webassembly + k8s integrations. I know you are new to wazero, but actually being somewhat new makes you a good review candidate. Can you try https://github.com/dmvolod/wasm-k8s-host-proxy and let us know what you think about it? This demonstrates how to make composite plugins based on code in this PR.

@mathetake @evacchi @knqyf263 if any of you can take a look at this, it would be well appreciated. @dmvolod spent a very long time getting this together.

@@ -0,0 +1,43 @@
//go:build tinygo.wasm

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest you also provide an easy way to compile the example by using something like //go:generate tinygo build -o plugin/plugin.wasm -scheduler=none -target=wasi --no-debug plugin/plugin.go

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for idea, @jcchavezs
will fix it for all examples in the plugin

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Np. I did that here to generate the wasm extension to test my code https://github.com/jcchavezs/coraza-exec-action-wasm/blob/main/plugin_test.go#L1

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool I guess this is the only thing before merge. nicely done!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, yes, sure. Added for this example and will fix it for another examples later.
Also, I saw that @jcchavezs is using mage in example, also like it this approach 👍

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah mage is great. Makefiles are painful for me as I was learning it again every time.

@dmvolod
Copy link
Contributor Author

dmvolod commented Mar 28, 2023

Thanks a lot @codefromthecrypt for your review and feedback.
It was very appreciated.
Also thanks to you, @mathetake , @evacchi and other wazero contributors for the best of the WebAssembly runtime 🎉

@mathetake
Copy link
Contributor

looking fantastic 🏅

@salaboy
Copy link

salaboy commented Mar 28, 2023

Folks this looks amazing.. I would love to try this out against my Kubernetes Cluster, I am still a wasm newbie.. but I will definitely give this a try: https://github.com/dmvolod/wasm-k8s-host-proxy, as creating other extensions for consuming Kubernetes resources is a scenario that I see coming

@dmvolod
Copy link
Contributor Author

dmvolod commented Mar 28, 2023

Folks this looks amazing.. I would love to try this out against my Kubernetes Cluster, I am still a wasm newbie.. but I will definitely give this a try: https://github.com/dmvolod/wasm-k8s-host-proxy, as creating other extensions for consuming Kubernetes resources is a scenario that I see coming

Thanks for feedback, @salaboy
Please note, that some adoptions k8s-objects on the which is in progress should be implemented

@knqyf263
Copy link
Owner

Awesome! Thanks for your great contribution.

@codefromthecrypt codefromthecrypt merged commit f89dce6 into knqyf263:main Mar 29, 2023
@codefromthecrypt
Copy link
Collaborator

tagged as v0.7.0 enjoy the fun!

@codefromthecrypt
Copy link
Collaborator

@dmvolod once you polish up https://github.com/dmvolod/wasm-k8s-host-proxy I'll re-write the release notes to highlight the work you've done. It would have to be by tomorrow as I'm out on vacation after.

@dmvolod
Copy link
Contributor Author

dmvolod commented Mar 30, 2023

Yes, sure, @codefromthecrypt I will try to fix it, as Kubewarden team released k8s-objects with first interface implementation having Get functions made easy and useful.
Branch with k8s-objects-v1.24.0-kw7-unreleased already in place, just need to switch from my forks to released versions (both for go-plugin and k8s-objects).

Thanks again for your help and care 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants