Async ffi and tokio::spawn (or static/tls in general)

I'm trying to make an async plugin utilizing async Rust. With async-ffi and abi-stable crates I made a toy program that works for simple cases, but it's not really sufficient.

Many tokio features use thread local or static variable. tokio::spawn and tokio::task::spawn_blocking use tls to find runtime handle, tokio::task_local uses tls. The main program and the plugin would point at different variable since they "static linked" tokio.

One partial solution would be having a "core" library that wraps all tokio api in a ffi-safe way, then everyone dynamic link "core" and use it's api instead. But 3rd party crate might ruin this pattern, since they call into tokio directly.

I don't need to unload the plugin, so it should be a little bit easier. Is there a clean way to do this? If there's not, I think I will have to resort to subprocess ipc calls, but ser/de in ipc may become the bottleneck...

P.S. I would like to make log or tracing works too, but I think they have (almost) the same problem.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.