rextendr icon indicating copy to clipboard operation
rextendr copied to clipboard

Using a local rust crate with extendr

Open sanghoonio opened this issue 3 months ago • 5 comments

I am working on a Rust tool with this directory structure:

image

I want to add R bindings in bindings/r using rextendr that can call functions from my main Rust crate.

The specific issue I'm running into is with Cargo being unable to find the main crate during package installation. While an absolute path in bindings/r/src/rust/Cargo.toml works:

[dependencies]
gtars = { path = "/Users/sam/Documents/Work/gtars/gtars" }

This obviously isn't suitable for distribution. Using a relative path fails during R package installation:

[dependencies]
gtars = { path = "../../../../gtars" }

Error during installation:

error: failed to get `gtars` as a dependency of package `gtars-r v0.1.0`
Caused by:
  failed to load source for dependency `gtars`

How can I properly set up R bindings that:

  1. Can access my main Rust crate
  2. Works with relative paths
  3. Can be distributed to other users

I've tried:

  • Relative paths in Cargo.toml
  • Using --no-staged-install

Any guidance on the correct way to address this would be appreciated.

sanghoonio avatar Nov 19 '24 21:11 sanghoonio