Example demonstrating Service compilation error.

This commit is contained in:
projectmoon 2021-06-04 21:53:09 +00:00
commit 666fd9f4f5
11 changed files with 3560 additions and 0 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
node_modules/
target/
dist/
static/
pkg/

1205
crate/Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

24
crate/Cargo.toml Normal file
View File

@ -0,0 +1,24 @@
[package]
name = "service-trait-example"
version = "0.1.0"
authors = ["projectmoon <projectmoon@agnos.is>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
crate-type = ["cdylib", "rlib"]
[build-dependencies]
tonic-build = { git = "https://github.com/hyperium/tonic", branch = "master", default_features = false, features = ["prost"] }
[dependencies]
yew = { version = "0.17", default_features = false }#features = [ "agent", "web-sys" ] }
yewtil = {version = "0.3" }
yew-router = {version = "0.14", default_features = false }
yewdux = {version = "^0.6", default_features = false }
wasm-bindgen = { version = "0.2", default-features = false, features = ["serde-serialize"] }
grpc-web-client = "0.1"
prost = { version = "0.7.0", default-features = false }
tonic = { git = "https://github.com/hyperium/tonic", branch = "master", default-features = false, features = ["codegen", "prost"] }

7
crate/build.rs Normal file
View File

@ -0,0 +1,7 @@
fn main() -> Result<(), Box<dyn std::error::Error>> {
tonic_build::configure()
.build_server(false)
.compile(&["../protos/hello.proto"], &["../protos/"])?;
Ok(())
}

17
crate/src/grpc.rs Normal file
View File

@ -0,0 +1,17 @@
use grpc_web_client::Client as GrpcWebClient;
tonic::include_proto!("hello");
use crate::grpc::hello_world_client::HelloWorldClient;
async fn test_grpc_web() {
let client = GrpcWebClient::new("http://localhost:10000".to_string());
let mut client = HelloWorldClient::new(client);
let request = tonic::Request::new(HelloRequest {
name: "WebTonic".into(),
});
let response = client.say_hello(request).await.unwrap().into_inner();
println!("Hello reply: {:?}", response);
}

36
crate/src/lib.rs Normal file
View File

@ -0,0 +1,36 @@
use wasm_bindgen::prelude::*;
use yew::prelude::*;
pub mod grpc;
struct App;
impl Component for App {
type Message = ();
type Properties = ();
fn create(_: Self::Properties, _link: ComponentLink<Self>) -> Self {
Self
}
fn update(&mut self, _: Self::Message) -> ShouldRender {
false
}
fn change(&mut self, _: Self::Properties) -> ShouldRender {
false
}
fn view(&self) -> Html {
html! {
<div>
{"Hello World"}
</div>
}
}
}
#[wasm_bindgen(start)]
pub fn run_app() {
yew::start_app::<App>();
}

7
index.js Normal file
View File

@ -0,0 +1,7 @@
//The wasm application is compiled as javascript into the /pkg
//directory. Webpack then replaces this import with what is actually
//needed.
import("./pkg").then(runic => {
console.log('module is: ', runic);
runic.run_app();
});

15
package.json Normal file
View File

@ -0,0 +1,15 @@
{
"devDependencies": {
"@wasm-tool/wasm-pack-plugin": "^1.4.0",
"clean-webpack-plugin": "^4.0.0-alpha.0",
"html-webpack-plugin": "^5.3.1",
"webpack": "^5.37.0",
"webpack-cli": "^4.7.0"
},
"name": "service-trait-example",
"version": "1.0.0",
"description": "Stuff",
"main": "index.js",
"author": "projectmoon <projectmoon@agnos.is>",
"license": "MIT"
}

14
protos/hello.proto Normal file
View File

@ -0,0 +1,14 @@
syntax = "proto3";
package hello;
service HelloWorld {
rpc SayHello(HelloRequest) returns (HelloReply);
}
message HelloRequest {
string name = 1;
}
message HelloReply {
string text = 1;
}

27
webpack.config.js Normal file
View File

@ -0,0 +1,27 @@
const path = require("path");
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const WasmPackPlugin = require("@wasm-tool/wasm-pack-plugin");
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
experiments: {
asyncWebAssembly: true
},
entry: './index.js',
mode: "development",
output: {
path: path.resolve(__dirname, './dist'),
filename: 'index_bundle.js',
},
plugins: [
new CleanWebpackPlugin(),
new HtmlWebpackPlugin(),
new WasmPackPlugin({
crateDirectory: path.resolve(__dirname, "crate"),
outDir: path.resolve(__dirname, "pkg"),
args: "--log-level warn",
extraArgs: "--no-typescript",
})
]
};

2203
yarn.lock Normal file

File diff suppressed because it is too large Load Diff