extendr: Failed to generate wrapper functions when calling tokio runtime `block_on` in exposed struct constructor
Hi!
We are building a cross platform tool to work with compact URIs with a core in rust that compiles to many languages, including R: https://github.com/biopragmatics/curies.rs
We managed to get something working for R here: https://github.com/biopragmatics/curies.rs/blob/add-r-bindings/r/src/rust/src/lib.rs
It can be called this way from R:
library(curiesr)
converter <- ConverterR$new()
curie <- converter$compress("http://purl.obolibrary.org/obo/DOID_1234")
print(curie)
But as we try to instantiate our Converter
struct from a document available on the internet as a URL, we are calling an async function.
And to make this function blocking we use the tokio runtime, but as soon as I add the init_converter()
function (which call the runtime) to my Converter new()
constructor I get the cryptic error Error in value[[3L]](): Failed to generate wrapper functions
fn init_converter() -> Converter {
let rt = Runtime::new().unwrap();
rt.block_on(async { get_bioregistry_converter().await.unwrap() })
}
Removing the init_converter
to synchronously build the converter: it works like a charm
Which seems to point at the tokio runtime as the culprit for generating this error at wrap time!
Do you have any idea how we could overcome this? I could not find many issues related to async
and runtimes
in your repo, so maybe we are doing something wrong on our side? Maybe we should use a futures
runtime instead of tokio?
About this issue
- Original URL
- State: closed
- Created 5 months ago
- Comments: 16 (10 by maintainers)
Alrighty then
in
Makevars
solves it for me. I got this idea from this https://stackoverflow.com/a/73898812/63696Let us know what happens on your end.
All right @CGMossa ! It works like a charm with this flag, thanks a lot for the debugging!
I guess we can close this issue then 😃
I just tried to recreate this in my WSL container.
I still believe you should update your local
Cargo.lock
file withcargo update
, but:And in
rextendr
, the code that fails is this:The way these wrappers are generated is very clever. Since Rust knows about its code, then from the Rust code we provide a function, that outputs the wrappers. Then rextendr calls that function! But we don’t want that loading, to affect the loading of symbols onto the current session, so we have a sub-r-process that loads the Rust library, and calls a make-wrappers function in it.
To debug this (for us, not you 😊), we could do the following:
And what happens here is a I get
I then press
.inspect 5
Looking and
cond
And there you have it there is a missing symbol. It means a static/shared library isn’t being linked to in the build process, that make up what the program requires. But now, this is on the Linux side.
SSL_get_error
Right, what does
rlang::last_trace()
say? Also, what aboutrextendr::rust_siterep()
?I am getting this output:
I am trying installing from github:
Now getting the output:
Cool! Thanks, that means it should work, there is just something going on with my setup
I am running this on Ubuntu 22.04, maybe I am missing some linux related dependencies?
I have installed the following R packages:
It was failing with R version 4.1.2, and I think rextendr was 0.3.1
I upgraded to R version 4.3.2, now reinstalling all the packages… takes time apparently
Hmm, I pulled it and tried, but I couldn’t reproduce it. (I had to add
-lcrypt32 -lsecur32
toMakevars.win
, but I guess this is unrelated to your error). Did you try updateing rextendr?