Comments (8)
I've figured out what the problem is. The code of extendr_macros
on crates.io doesn't match the code in the git repo. To show this, I've copied the entire lib.rs
file from crates.io below, in the details. You can see that it defines a macro export_function
but no macro extendr
. I also note that the version of extendr_macros
on crates.io (and in the github repo) is listed as 0.1.2, when the version of extendr_api
is 0.1.3. Maybe all that is needed to fix this is to update the version of extendr_macros
and re-publish on crates.io?
extern crate proc_macro;
use proc_macro::TokenStream;
use syn::{parse_macro_input, parse_quote, ItemFn, FnArg, Expr};
use syn::punctuated::Punctuated;
//use syn::parse::Parse;
use syn::Token;
use quote::{quote, format_ident};
//type CompileError = Box<dyn std::error::Error>;
// All arguments are SEXP for .Call in R.
fn translate_formal(input : &FnArg) -> FnArg {
match input {
FnArg::Typed(ref pattype) => {
let pat = &pattype.pat.as_ref();
return parse_quote!{ #pat : extendr_api::SEXP };
},
_ => ()
}
panic!("Exported function argument must be a primitive or Robj.");
}
// Convert SEXP arguments into native types if we can.
fn translate_actual(input : &FnArg) -> Expr {
match input {
FnArg::Typed(ref pattype) => {
let pat = &pattype.pat.as_ref();
let ty = &pattype.ty.as_ref();
return parse_quote!{ extendr_api::unwrap_or_throw(from_robj::<#ty>(&new_borrowed(#pat))) };
},
_ => ()
}
panic!("Exported function argument must be a primitive or Robj.");
}
#[proc_macro_attribute]
/// Generate bindings for a single function.
pub fn export_function(_attr: TokenStream, item: TokenStream) -> TokenStream {
let func = parse_macro_input!(item as ItemFn);
let func_name = &func.sig.ident;
let wrap_name = format_ident!("__wrap__{}", func_name);
let formal_args : Punctuated<FnArg, Token![,]> = func.sig.inputs.iter()
.map(|input| {
translate_formal(input)
}).collect();
let actual_args : Punctuated<Expr, Token![,]> = func.sig.inputs.iter()
.map(|input| {
translate_actual(input)
}).collect();
//println!("export_function func: {:#?}", func);
let expanded = quote! {
// #[allow(dead_code)]
#func
#[no_mangle]
pub extern "C" fn #wrap_name(#formal_args) -> extendr_api::SEXP {
use extendr_api::{from_robj, new_borrowed};
unsafe {
extendr_api::Robj::from(#func_name(#actual_args)).get()
}
}
};
//println!("res: {}", expanded);
TokenStream::from(expanded)
}
from extendr.
Thinking about the right order of doing things, so we end up with fully functioning crates on crates.io: Maybe first merge the libR-sys PR (extendr/libR-sys#7), which will increase the version of libR-sys. Then publish that on crates.io. Then increase the version dependency in extendr, and then increase extendr-{api, macros} versions to 0.1.4.
from extendr.
Thanks for your hard work, @clauswilke and others.
from extendr.
I've updated some of the documentation and switched the docs to docs.rs.
Please let me know if this work for everyone.
A CI test on Appveyor or Azure would be a useful thing to keep this working.
from extendr.
Sounds good to me.
from extendr.
Just to be sure it doesn't fall through the cracks: extendr-macros needs a version bump also, here:
extendr/extendr-macros/Cargo.toml
Line 3 in 8114138
and here:
extendr/extendr-api/Cargo.toml
Line 13 in 8114138
from extendr.
I've created a PR for this and will publish the crate.
from extendr.
I believe this is fixed now.
from extendr.
Related Issues (20)
- make type error for ARM aarch64 u8/i8 HOT 7
- extendr-macro should propagate syn::Error, not panic!()
- Clarify design: NA checking HOT 1
- The `result_list` feature seems broken HOT 3
- Demacrofy `extendr-api` as much as possible
- add `return_list` and `return_condition` to `#[extendr]`
- Should `extendr-api` be thread safe? HOT 1
- Add multithreaded tests to extendr
- OBJSXP
- Sporadic crash in `serializer_test`
- Feature: Minimal feature to reduce size HOT 4
- File `device_driver` isn't included anywhere
- Rethink GitHub Actions
- Drop graphics device support?
- `@docType "package"` is deprecated in roxygen2 7.3.0
- Raw Robj does not inherit the "raw" class HOT 5
- feature: support exporting traits
- Support basic Date and Date-Time objects
- include `AsTypedSlice` in the prelude HOT 4
- Failed to generate wrapper functions when calling tokio runtime `block_on` in exposed struct constructor HOT 16
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from extendr.