extendr / rextendr

An R package that helps scaffolding extendr-enabled packages or compiling Rust code dynamically
https://extendr.github.io/rextendr/
Other
190 stars 28 forks source link

some function with special name would not compile #356

Closed Neutron3529 closed 2 months ago

Neutron3529 commented 3 months ago

for example, such rust code works fine:

fn r#try(a:i32, b:i32)->i32{a+b}

but rextendr has issue exporting it.

It is nothing more than an edge case. Things might be done with a hand-writting macro.


I'm trying writting a macro about auto exporting function without explictly use the annoying macro:

extendr_module! {
    mod rext;
    fn hello_world;
}

Instead, if I success, just writting :

done!{Yes, it is done!};

is enough.

the trick should be re-define the function with the same name in a new module, for example, _please_do_not_use_rmin_export_interface_as_your_mod_name_, and use the following trick to merge all of the function in a single mod

mod private_foo {
    #[no_mangle]
    extern "C" fn foo(){} // not-so-private function
}
pub mod _please_do_not_use_rmin_export_interface_as_your_mod_name_ {
    pub extern "C" {
        fn foo();
    }
    const FOO_PTR:*const()=foo as *const_; // use pub extern fn foo::foo, which equals to the private_foo::foo thanks to the `#[no_mangle]` attribute.
}

That's all what I have found in the last week. Hope that may help develop a better rextendr:)

I might have several problem for packing R packages in the future (it cost me a day to switch the compile script to a ugly script compiles my crate), wondering is it possible to get some help here.

Ilia-Kosenkov commented 3 months ago

Hi, thanks for reporting this. We already had this issue some time ago, I though it has been addressed. I'll check it.