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

Make library compile for wasm32-wasi #122

Closed
ctaggart opened this issue Jul 29, 2020 · 3 comments
Closed

Make library compile for wasm32-wasi #122

ctaggart opened this issue Jul 29, 2020 · 3 comments

Comments

@ctaggart
Copy link

ctaggart commented Jul 29, 2020

It would be great to be able to build a JSON-RPC 2.0 server that targets wasm32-wasi. The use case I'd like to support is the same as https://github.com/paritytech/jsonrpc/tree/master/stdio where the transport is stdio.

Today, if you try to cargo build --target=wasm32-wasi this project, socket2 fails to build. It would be nice to make that an optional dependency that is not included when a wasm32-wasi target.

I first looked at https://paritytech.github.io/jsonrpc/jsonrpc_core/index.html, but it is still using futures 0.1. paritytech/jsonrpc#485 mentioned having a look at this project instead. It would be nice if the transport agnostic "core" was still possible.

It is okay if this feature does not match this project's roadmap. I'm just trying to find out what can be reused and where collaborations can be made. Due to chemotherapy, my personal time investment may be low over the next three months. I'm hoping I can spark some ideas for others.

@ctaggart
Copy link
Author

ctaggart commented Aug 8, 2020

I figured it out. I was able to used the latest jsonrpc-core.

jsonrpc-core = { git = "https://github.com/paritytech/jsonrpc" }

This works from wasi too.

use jsonrpc_core::{IoHandler, Params, Value};
use std::{io, io::prelude::*};

pub type Error = Box<dyn std::error::Error + Send + Sync>;
pub type Result<T> = std::result::Result<T, Error>;

pub fn main() -> Result<()> {
    let mut handler = IoHandler::new();
    handler.add_sync_method("say_hello", |_: Params| Ok(Value::String("Hello World!".to_owned())));

    for req in io::stdin().lock().lines() {
        if let Some(rsp) = handler.handle_request_sync(&req?) {
            println!("{}", rsp);
        }
    }
    Ok(())
}

@ctaggart ctaggart closed this as completed Aug 8, 2020
@tomaka tomaka reopened this Aug 11, 2020
@tomaka tomaka changed the title looking for json-rpc wasm32-wasi target Make library compile for wasm32-wasi Aug 11, 2020
@niklasad1
Copy link
Member

This is blocked on async-rs/async-std#505 and tokio-rs/tokio#1597 unless someone has any clever ideas on how to replace the current runtimes.

@jsdw
Copy link
Collaborator

jsdw commented Aug 17, 2022

Given that I think the above is still true, and it's not a priority for us internally, I'll close this, but if anybody comes across this and is keen to have a play and finds a way to make it work, I'd be interested to know more!

@jsdw jsdw closed this as completed Aug 17, 2022
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

No branches or pull requests

4 participants