Skip to content

Commit

Permalink
feat: add wasm-rust sdk with say-hello simple extension (alibaba#350)
Browse files Browse the repository at this point in the history
  • Loading branch information
jizhuozhi authored Jun 19, 2023
1 parent ea7b581 commit 32c2ace
Show file tree
Hide file tree
Showing 17 changed files with 1,332 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ bazel-testlogs
bazel-wasm-cpp
tools/bin/
helm/**/charts/**.tgz
target/
tools/hack/cluster.conf
1 change: 1 addition & 0 deletions plugins/wasm-rust/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target/
131 changes: 131 additions & 0 deletions plugins/wasm-rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions plugins/wasm-rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "higress-wasm-rust"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
proxy-wasm = "0.2.1"
serde = "1.0"
serde_json = "1.0"
uuid = { version = "1.3.3", features = ["v4"] }
12 changes: 12 additions & 0 deletions plugins/wasm-rust/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM rust:1.69 as builder
WORKDIR /workspace
RUN rustup target add wasm32-wasi
ARG PLUGIN_NAME="say-hello"
ARG BUILD_OPTS="--release"
COPY . .
WORKDIR /workspace/extensions/$PLUGIN_NAME
RUN cargo build --target wasm32-wasi $BUILD_OPTS \
&& cp target/wasm32-wasi/release/*.wasm /main.wasm

FROM scratch
COPY --from=builder /main.wasm plugin.wasm
16 changes: 16 additions & 0 deletions plugins/wasm-rust/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
PLUGIN_NAME ?= say-hello
REGISTRY ?= higress-registry.cn-hangzhou.cr.aliyuncs.com/plugins/
BUILD_TIME := $(shell date "+%Y%m%d-%H%M%S")
COMMIT_ID := $(shell git rev-parse --short HEAD 2>/dev/null)
IMAGE_TAG = $(if $(strip $(PLUGIN_VERSION)),${PLUGIN_VERSION},${BUILD_TIME}-${COMMIT_ID})
IMG ?= ${REGISTRY}${PLUGIN_NAME}:${IMAGE_TAG}

.DEFAULT:
build:
DOCKER_BUILDKIT=1 docker build \
--build-arg PLUGIN_NAME=${PLUGIN_NAME} \
-t ${IMG} \
--output extensions/${PLUGIN_NAME} \
.
@echo ""
@echo "output wasm file: extensions/${PLUGIN_NAME}/plugin.wasm"
3 changes: 3 additions & 0 deletions plugins/wasm-rust/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 介绍

此 SDK 用于使用 Rust 语言开发 Higress 的 Wasm 插件。
187 changes: 187 additions & 0 deletions plugins/wasm-rust/extensions/say-hello/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions plugins/wasm-rust/extensions/say-hello/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "say-hello"
version = "0.1.0"
edition = "2021"
publish = false

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
crate-type = ["cdylib"]

[dependencies]
higress-wasm-rust = { path = "../../", version = "0.1.0" }
proxy-wasm = "0.2.1"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Loading

0 comments on commit 32c2ace

Please sign in to comment.