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

WIP: add gRPC sample #21

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft

Conversation

bacongobbler
Copy link
Contributor

@bacongobbler bacongobbler commented Sep 10, 2024

Does not work; using this as a test bed for upstream changes in wasi-http.

Signed-off-by: Matthew Fisher <[email protected]>
Signed-off-by: Matthew Fisher <[email protected]>
Signed-off-by: Matthew Fisher <[email protected]>
@bacongobbler
Copy link
Contributor Author

bacongobbler commented Sep 11, 2024

Steps to get this sample working:

  1. Compile the .NET runtime off [NativeAOT-LLVM] support System.Net.Http.HttpClient on WASIp2 dotnet/runtimelab#2614, with one additional change to force incoming responses to respond as HTTP/2 (necessary because the incoming response handler currently downgrades the response to HTTP/1.1):
diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpHandler.cs b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpHandler.cs
index 1e5dc53e02c..8e8e78bfb5b 100644
--- a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpHandler.cs
+++ b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpHandler.cs
@@ -58,6 +58,22 @@ public async Task<HttpResponseMessage> SendRequestAsync(HttpRequestMessage reque

                 var response = new HttpResponseMessage((HttpStatusCode)incomingResponse.Status());

+                // Force inbound response to use HTTP/2 if TE=trailers is set
+                //
+                // No System.Linq support =(
+                IEnumerable<string>? values = null;
+                if (request.Headers.TryGetValues("TE", out values))
+                {
+                    foreach (var value in values)
+                    {
+                        if (value == "trailers")
+                        {
+                            response.Version = HttpVersion.Version20;
+                            break;
+                        }
+                    }
+                }
+
                 // request body could be still streaming after response headers are received and started streaming response
                 // we will leave scope of this method
                 // we need to pass the ownership of the request and this wrapper to the response (via response content stream)

You'll also want to compile LLVM and the latest version of the wasi-sdk:

https://github.com/llvm/llvm-project/releases/tag/llvmorg-18.1.8
https://github.com/WebAssembly/wasi-sdk/releases/tag/wasi-sdk-24

Rough steps to compile runtimelab:

git clone [email protected]:dicej/runtimelab
cd runtimelab
git checkout system-net-http-wasi
export WASI_SDK_PATH=/tmp/wasi-sdk-24.0-x86_64-linux
export LLVM_CMAKE_CONFIG=/tmp/llvm-project/build
./build.sh clr.aot+libs -c Release -a wasm -os wasi
./build.sh clr.wasmjit+clr.aot+libs -c Release
./build.sh nativeaot.packages -c Release
./build.sh nativeaot.packages -a wasm -os wasi -c Release -rf CoreCLR
  1. Use @dicej's grpc-hacks branch for wasmtime:
git clone [email protected]:dicej/wasmtime
cd wasmtime
git checkout grpc-hacks
cargo install .

Use GrpcGreeter as the server:

git clone [email protected]:bacongobbler/GrpcGreeter
cd GrpcGreeter
dotnet run

Then in another terminal, build and run the sample:

cd samples/http-grpc
spin build
wasmtime serve -S cli --addr 0.0.0.0:3000 build/App.wasm

Then issue a request.

><> curl localhost:3000
Hello, gRPC!

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.

1 participant