Skip to content

Commit

Permalink
Combined Wasm stats + metadata implementations. (envoyproxy#48)
Browse files Browse the repository at this point in the history
Stats and Metadata support for WASM.
  • Loading branch information
jplevyak authored Apr 12, 2019
1 parent 14a36c2 commit 5aff91e
Show file tree
Hide file tree
Showing 63 changed files with 578,651 additions and 23,132 deletions.
9 changes: 9 additions & 0 deletions api/wasm/cpp/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
all: proxy_wasm_intrinsics.pb.h proxy_wasm_intrinsics_lite.pb.h struct_lite.pb.h

proxy_wasm_intrinsics.pb.h: proxy_wasm_intrinsics.proto
protoc --cpp_out=. proxy_wasm_intrinsics.proto

proxy_wasm_intrinsics_lite.pb.h struct_lite.pb.h: proxy_wasm_intrinsics_lite.proto
protoc --cpp_out=. proxy_wasm_intrinsics_lite.proto
protoc --cpp_out=. struct_lite.proto

6 changes: 3 additions & 3 deletions api/wasm/cpp/Makefile.base
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
CPP_API:=$(shell git rev-parse --show-toplevel)/api/wasm/cpp

ifdef NO_CONTEXT
CONTEXT_LIB =
CPP_CONTEXT_LIB =
else
CONTEXT_LIB = ${CPP_API}/proxy_wasm_intrinsics.cc
CPP_CONTEXT_LIB = ${CPP_API}/proxy_wasm_intrinsics.cc
endif

%.wasm %.wat: %.cc ${CPP_API}/proxy_wasm_intrinsics.h ${CPP_API}/proxy_wasm_intrinsics.js
em++ -s WASM=1 -s LEGALIZE_JS_FFI=0 -s EMIT_EMSCRIPTEN_METADATA=1 --std=c++17 -O3 -g3 -I${CPP_API} --js-library ${CPP_API}/proxy_wasm_intrinsics.js $*.cc ${CONTEXT_LIB} -o $*.js
em++ -s WASM=1 -s LEGALIZE_JS_FFI=0 -s EMIT_EMSCRIPTEN_METADATA=1 --std=c++17 -O3 -g3 -I${CPP_API} -I/usr/local/include --js-library ${CPP_API}/proxy_wasm_intrinsics.js $*.cc ${CPP_API}/proxy_wasm_intrinsics.pb.cc ${CPP_CONTEXT_LIB} ${CPP_API}/libprotobuf.bc -o $*.js
wavm-disas $*.wasm $*.wat
wavm-compile $*.wasm $*.wasm
rm -f $*.js $*.wast
Expand Down
17 changes: 17 additions & 0 deletions api/wasm/cpp/Makefile.base_lite
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
CPP_API:=$(shell git rev-parse --show-toplevel)/api/wasm/cpp

ifdef NO_CONTEXT
CPP_CONTEXT_LIB =
else
CPP_CONTEXT_LIB = ${CPP_API}/proxy_wasm_intrinsics.cc
endif

%.wasm %.wat: %.cc ${CPP_API}/proxy_wasm_intrinsics.h ${CPP_API}/proxy_wasm_intrinsics.js
em++ -s WASM=1 -s LEGALIZE_JS_FFI=0 -s EMIT_EMSCRIPTEN_METADATA=1 --std=c++17 -O3 -g3 -DEMSCRIPTEN_PROTOBUF_LITE=1 -I${CPP_API} -I${CPP_API}/google/protobuf -I/usr/local/include --js-library ${CPP_API}/proxy_wasm_intrinsics.js $*.cc ${CPP_API}/proxy_wasm_intrinsics_lite.pb.cc ${CPP_API}/struct_lite.pb.cc ${CPP_CONTEXT_LIB} ${CPP_API}/libprotobuf-lite.bc -o $*.js
wavm-disas $*.wasm $*.wat
wavm-compile $*.wasm $*.wasm
rm -f $*.js $*.wast
chmod 644 $*.wat

clean:
rm *.wasm *.wat
7 changes: 7 additions & 0 deletions api/wasm/cpp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Dependencies for building WASM modules:

- You must install the version of protobuf on your build system that matches the libprotobuf.bc files (without any patches) so that the generated code matches the .bc library.
Currently this is based on tag v3.6.1 of https://github.com/protocolbuffers/protobuf.

- If want to rebuild the .bc files or use a different version see the instructions at https://github.com/kwonoj/protobuf-wasm (note: this is pinned to git tag v3.6.1)
A pre-patched repo is available at https://github.com/jplevyak/protobuf branch envoy-wasm
Binary file added api/wasm/cpp/libprotobuf-lite.bc
Binary file not shown.
Binary file added api/wasm/cpp/libprotobuf.bc
Binary file not shown.
627 changes: 573 additions & 54 deletions api/wasm/cpp/proxy_wasm_intrinsics.h

Large diffs are not rendered by default.

16 changes: 10 additions & 6 deletions api/wasm/cpp/proxy_wasm_intrinsics.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
mergeInto(LibraryManager.library, {
proxy_log: function () {},
proxy_setTickPeriodMilliseconds: function () {},
proxy_getRequestMetadata: function () {},
proxy_setRequestMetadata: function () {},
proxy_getRequestMetadataPairs: function () {},
proxy_getResponseMetadata: function () {},
proxy_setResponseMetadata: function () {},
proxy_getResponseMetadataPairs: function () {},
proxy_getProtocol: function () {},
proxy_getMetadata: function () {},
proxy_setMetadata: function () {},
proxy_getMetadataPairs: function () {},
proxy_getMetadataStruct: function () {},
proxy_setMetadataStruct: function () {},
proxy_continueRequest: function () {},
proxy_continueResponse: function () {},
proxy_addRequestHeader: function () {},
Expand All @@ -32,4 +32,8 @@ mergeInto(LibraryManager.library, {
proxy_removeResponseTrailer: function () {},
proxy_getResponseBodyBufferBytes: function () {},
proxy_httpCall: function () {},
proxy_defineMetric: function () {},
proxy_incrementMetric: function () {},
proxy_recordMetric: function () {},
proxy_getMetric: function () {},
});
Loading

0 comments on commit 5aff91e

Please sign in to comment.