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

Retarget SDK to upstream Go toolchain 1.24 #1

Merged
merged 25 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
dd6bbfc
bugfix: fix Errorf without a format string
leonm1 Nov 14, 2024
843a4d5
feat: rework API to support full upstream Go compiler v1.24
leonm1 Nov 14, 2024
1d67b2b
chore: byte slice conversion functions to stdlib implementations
leonm1 Nov 14, 2024
51748e5
Revert "more updates"
leonm1 Dec 10, 2024
e4f2bb8
Revert "Deletes unnecessary components: part 2 (#453)"
leonm1 Dec 10, 2024
d05ab8f
Revert "Deletes unnecessary components (#452)"
leonm1 Dec 10, 2024
c0c31f9
Revert "Updates README to reflect the project direction (#451)"
leonm1 Dec 10, 2024
683e3d3
owners: update for full Go version maintainer
leonm1 Dec 10, 2024
6a778c9
doc: update OVERVIEW for full Go compiler features and limitations
leonm1 Dec 12, 2024
279a7c0
doc: modernize README with full Go instructions
leonm1 Dec 13, 2024
3eb9622
chore: update issue template to ask which compiler is in use
leonm1 Dec 13, 2024
8aaaea4
chore: update Makefile with full Go instructions
leonm1 Dec 13, 2024
eab4a12
chore: update workflows with full go sdk version 1.24
leonm1 Dec 13, 2024
efea0d3
chore: update required go.mod versions
leonm1 Dec 13, 2024
0a14044
chore: fix lint errors
leonm1 Dec 13, 2024
f1d031b
doc: document alpha status in README
leonm1 Dec 17, 2024
62ad74b
chore: update references from tetratelabs repo to proxy-wasm repo
leonm1 Dec 17, 2024
8344c08
doc: update docs with feedback on PR#1
leonm1 Dec 17, 2024
3599270
ci: rename workflow to "Presubmit checks"
leonm1 Dec 18, 2024
b0148c7
doc: update overview with review comments
leonm1 Dec 18, 2024
0184d68
doc: replace tabs with spaces
leonm1 Dec 18, 2024
fc55ddf
doc: replace tabs with spaces in README.md
leonm1 Dec 18, 2024
1e3aa56
ci: fix workflow file syntax
leonm1 Dec 18, 2024
d8dbefb
chore: fix import ordering post rename
leonm1 Dec 18, 2024
69b79fb
chore: add martijneken to CODEOWNERS
leonm1 Dec 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @leonm1 @martijneken
22 changes: 22 additions & 0 deletions .github/ISSUE_TEMPLATE/bug-error-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
name: Bug / Error report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''

---

<!-- PLEASE FILL IN THE FOLLOWINGS for EVERY ISSUE you make. -->

## Describe the bug / error

## What is your Envoy/Istio version?

## What is the SDK version?

## What compiler are you using, and what is the version?

## URL or snippet of your code including Envoy configuration

## Additional context (Optional)
73 changes: 73 additions & 0 deletions .github/workflows/workflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Presubmit checks
on:
pull_request:
branches:
- main
push:
branches:
- main
martijneken marked this conversation as resolved.
Show resolved Hide resolved
schedule:
- cron: '0 0 * * *'

env:
GO_VERSION: 1.24.0-rc.1

jobs:
style:
name: Code style check
runs-on: ubuntu-latest
steps:
- name: install Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}

- name: checkout
uses: actions/checkout@v3

- name: run lint
run: make lint

- name: run format check
run: make check

sdk-tests:
name: SDK tests
runs-on: ubuntu-latest
steps:
- name: install Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}

- name: checkout
uses: actions/checkout@v3

- name: run tests
run: make test

examples:
name: Examples Tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Build cache
uses: actions/cache@v3
with:
path: |
~/go/pkg/mod
~/go/bin
key: examples-${{ hashFiles('**/go.mod', '**/go.sum') }}-{{ env.GO_VERSION }}

- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}

- name: Build examples
run: make build.examples

- name: Test examples
run: make test.examples
14 changes: 11 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
goimports := golang.org/x/tools/cmd/goimports@v0.21.0
golangci_lint := github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59.0
golangci_lint := github.com/golangci/golangci-lint/cmd/golangci-lint@v1.62.2


.PHONY: build.example
build.example:
@find ./examples -type f -name "main.go" | grep ${name}\
| xargs -I {} bash -c 'dirname {}' \
| xargs -I {} bash -c 'cd {} && tinygo build -o main.wasm -scheduler=none -target=wasi ./main.go'
| xargs -I {} bash -c 'cd {} && env GOOS=wasip1 GOARCH=wasm go build -buildmode=c-shared -o main.wasm ./main.go'


.PHONY: build.examples
build.examples:
@find ./examples -mindepth 1 -type f -name "main.go" \
| xargs -I {} bash -c 'dirname {}' \
| xargs -I {} bash -c 'cd {} && tinygo build -o main.wasm -scheduler=none -target=wasi ./main.go'
| xargs -I {} bash -c 'cd {} && env GOOS=wasip1 GOARCH=wasm go build -buildmode=c-shared -o main.wasm ./main.go'

.PHONY: test
test:
Expand All @@ -26,6 +26,14 @@ test.examples:
| xargs -I {} bash -c 'dirname {}' \
| xargs -I {} bash -c 'cd {} && go test ./...'
martijneken marked this conversation as resolved.
Show resolved Hide resolved

.PHONY: test.e2e
test.e2e:
@go test -v ./e2e -count=1

.PHONY: test.e2e.single
test.e2e.single:
@go test -v ./e2e -run '/${name}' -count=1

.PHONY: run
run:
@envoy -c ./examples/${name}/envoy.yaml --concurrency 2 --log-format '%v'
Expand Down
109 changes: 98 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,98 @@
> [!WARNING]
> We are no longer recommending this SDK or Wasm in general for anyone due to the fundamental memory issue of TinyGo (See [the detailed explanation](https://github.com/tetratelabs/proxy-wasm-go-sdk/issues/450#issuecomment-2253729297) by a long-time community member)
> as well as [the project state of Proxy-Wasm in general](https://github.com/envoyproxy/envoy/issues/35420).
> If you are not in a position where you have to run untrusted binaries (like for example, you run Envoy proxies while your client gives you the binaries to run), we recommend using other extension mechanism
> such as Lua or External Processing which should be comparable or better or worse depending on the use case.
>
> If you are already using this SDK, but still want to continue using Wasm for some reason instead of Lua or External Processing,
> we strongly recommend migrating to the Rust or C++ SDK due to the memory issue of TinyGo described in the link above.
>
> We keep this repository open and not archived for the existing users, but we cannot provide any support or guarantee for the future development of this SDK.
> However, at any time, we may decide to archive this repository if we see no reason to keep it open.
# WebAssembly for Proxies (Go SDK) [![Build](https://github.com/proxy-wasm/proxy-wasm-go-sdk/workflows/Test/badge.svg)](https://github.com/proxy-wasm/proxy-wasm-go-sdk/actions) [![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](LICENSE)

The Go SDK for
[Proxy-Wasm](https://github.com/proxy-wasm/spec), enabling developers to write Proxy-Wasm plugins in Go.
martijneken marked this conversation as resolved.
Show resolved Hide resolved

Note: This SDK targets the upstream Go compiler, version 1.24 or later. This is different than the forked github.com/tetratelabs/proxy-wasm-go-sdk, which targets the TinyGo compiler.

## Project Status

This SDK is based off of github.com/tetratelabs/proxy-wasm-go-sdk; however, it is effectively a new SDK targeting a completely different toolchain. It relies on the not-yet-released Go 1.24 and hasn't seen extensive prod testing by end-users. This SDK is an alpha product.

## Getting Started

- [examples](examples) directory contains the example codes on top of this SDK.
- [OVERVIEW.md](doc/OVERVIEW.md) the overview of Proxy-Wasm, the API of this SDK, and the things you should know when writing plugins.

## Requirements

- \[Required] [Go](https://go.dev/): v1.24+ - This SDK leverages Go 1.24's support for [WASI](https://github.com/WebAssembly/WASI) (WebAssembly System Interface) reactors. You can grab a release candidate from the [Go unstable releases page](https://go.dev/dl/#unstable). A stable release of Go 1.24 is [expected in February 2025](https://tip.golang.org/doc/go1.24).
- \[Required] A host environment supporting this toolchain - This SDK leverages additional host imports added to the proxy-wasm-cpp-host in [PR#427](https://github.com/proxy-wasm/proxy-wasm-cpp-host/pull/427). This has yet to be merged, let alone make its way downstream to Envoy, ATS, nginx, or managed environments.
- \[Optional] [Envoy](https://www.envoyproxy.io) - To run end-to-end tests, you need to have an Envoy binary. You can use [func-e](https://func-e.io) as an easy way to get started with Envoy or follow [the official instruction](https://www.envoyproxy.io/docs/envoy/latest/start/install).

## Installation

```
go get github.com/proxy-wasm/proxy-wasm-go-sdk
```

## Minimal Example Plugin

A minimal plugin:

```go
package main

import (
"github.com/proxy-wasm/proxy-wasm-go-sdk/proxywasm"
"github.com/proxy-wasm/proxy-wasm-go-sdk/proxywasm/types"
)

func init() {
proxywasm.SetVMContext(&vmContext{})
}
type vmContext struct {
types.DefaultVMContext
}
type pluginContext struct {
types.DefaultPluginContext
}
func (*context) NewPluginContext(contextID uint32) types.PluginContext {
return &context{}
}
func main() {}
```

It can be compiled with `env GOOS=wasip1 GOARCH=wasm go build -buildmode=c-shared -o my-plugin.wasm main.go`.

## Build and run Examples

```bash
# Build all examples.
make build.examples

# Build a specific example using the `go` tool.
cd examples/helloworld
env GOOS=wasp1 GOARCH=wasm go build -buildmode=c-shared -o main.wasm main.go

# Test the built wasm module using `go test`.
go test

# Build and test a specific example from the repo root using `make`.
make build.example name=helloworld
make run name=helloworld
```
martijneken marked this conversation as resolved.
Show resolved Hide resolved

## Compatible Envoy builds

Envoy is the first host side implementation of Proxy-Wasm ABI,
and we run end-to-end tests with multiple versions of Envoy and Envoy-based [istio/proxy](https://github.com/istio/proxy) in order to verify Proxy-Wasm Go SDK works as expected.

Please refer to [workflow.yaml](.github/workflows/workflow.yaml) for which version is used for End-to-End tests.

## Build tags

The following build tags can be used to customize the behavior of the built plugin. Build tags [can be specified in the `go build` command via the `-tags` flag](https://pkg.go.dev/cmd/go#:~:text=tags):

- `proxywasm_timing`: Enables logging of time spent in invocation of the plugin's exported functions. This can be useful for debugging performance issues.

## Contributing

We welcome contributions from the community! See [CONTRIBUTING.md](doc/CONTRIBUTING.md) for how to contribute to this repository.

## External links

- [WebAssembly for Proxies (ABI specification)](https://github.com/proxy-wasm/spec)
- [WebAssembly for Proxies (C++ SDK)](https://github.com/proxy-wasm/proxy-wasm-cpp-sdk)
- [WebAssembly for Proxies (Rust SDK)](https://github.com/proxy-wasm/proxy-wasm-rust-sdk)
- [WebAssembly for Proxies (AssemblyScript SDK)](https://github.com/solo-io/proxy-runtime)
46 changes: 46 additions & 0 deletions doc/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Contributing
martijneken marked this conversation as resolved.
Show resolved Hide resolved

We welcome contributions from the community. Please read the following guidelines carefully to maximize the chances of your PR being merged.

## Coding Style

The code is linted using a stringent golang-ci. To run this linter (and a few others) use run `make check`. To format your files, you can run `make format`.

## Running tests

```
# Run local tests without running envoy processes.
make test

# Run all e2e tests.
# This requires you to have Envoy binary locally.
make test.e2e

# Run e2e tests for a specific example.
# This requires you to have Envoy binary locally.
make test.e2e.single name=helloworld
```

## Contributor License Agreement

Contributions to this project must be accompanied by a Contributor License
Agreement. You (or your employer) retain the copyright to your contribution;
this simply gives us permission to use and redistribute your contributions as
part of the project. Head over to <https://cla.developers.google.com/> to see
your current agreements on file or to sign a new one.

You generally only need to submit a CLA once, so if you've already submitted one
(even if it was for a different project), you probably don't need to do it
again.

## Code reviews

All submissions, including submissions by project members, require review. We
use GitHub pull requests for this purpose. Consult
[GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
information on using pull requests.

## Community Guidelines

This project follows [Google's Open Source Community
Guidelines](https://opensource.google/conduct/).
Loading