Rust <-> R interoperability workspace. This repository contains the runtime crates, proc macros, CLI/tooling, an example R package, and the helper package used to scaffold standalone packages and monorepos.
miniextendr-api/- Runtime crate: R FFI bindings, conversions, worker-thread routing, ALTREP, class systems, trait ABI, and macro re-exports.miniextendr-macros/- Proc macros such as#[miniextendr],#[r_ffi_checked],ExternalPtr, andRNativeType.miniextendr-macros-core/- Shared parsing/generation support used by the proc-macro crate.miniextendr-engine/- Standalone R embedding engine for Rust-only binaries and integration tests.miniextendr-cli/- CLI for scaffolding, workflow, vendoring, and cargo operations.miniextendr-bench/- Benchmarks for conversions and feature-gated paths.miniextendr-lint/- Internal linter used during builds.cargo-revendor/- Standalone vendoring tool for hermetic/offline builds. It is intentionally excluded from the main Cargo workspace.
rpkg/- Example R package that exercises the Rust crates and the autoconf/configure flow.minirextendr/- R helper package for scaffolding, configure wiring, vendoring helpers, and cargo wrappers.tests/cross-package/- Producer/consumer R packages used to validate the cross-package trait ABI dispatch flow.
- FFI bindings to R's C API plus safer
SEXP-oriented helpers. - Rust <-> R conversions for common scalars, vectors, lists, matrices, and user-defined types.
- The default worker-thread pattern that keeps panics and Drop behavior safe in the presence of R longjmp.
- ALTREP traits, registration helpers, and iterator-backed ALTREP data types.
- Env, S3, S4, S7, and R6 class generation from Rust impl blocks.
- Type-erased cross-package trait dispatch via tags and vtables.
- Adapter traits such as
RDebug,RDisplay,RHash,ROrd, andRPartialOrd. - Re-exports of the
miniextendr-macrosproc macros so most downstream crates only need one dependency.
Feature families in the runtime crate include:
- Runtime/build:
nonapi,rayon,connections,indicatif,vctrs,worker-thread,default-worker,log - Serialization/data:
serde(native R),serde_json(JSON),borsh,arrow,datafusion - Ecosystem conversions:
either,uuid,regex,url,time,ordered-float,num-bigint,rust_decimal,num-complex,indexmap,bitflags,bitvec,ndarray,nalgebra,tinyvec,bytes,raw_conversions,aho-corasick,toml,tabled,rand,rand_distr,num-traits - Proc-macro defaults and diagnostics:
default-strict,default-coerce,default-r6,default-s7,doc-lint,debug-preserve,growth-debug,macro-coverage,refcount-fast-hash
See miniextendr-api/README.md and docs/FEATURES.md for the current feature
matrix.
rpkg/ is a real R package that vendors Rust crates and builds a shared
library via cargo during R CMD INSTALL.
The high-level flow is:
bootstrap.Rrunsconfigure.configuregeneratessrc/Makevars,src/rust/Cargo.toml, andsrc/rust/.cargo/config.toml, and picks the dev or CRAN/offline source layout.Makevarsbuilds the Rust static library and a temporary cdylib used to writeR/miniextendr-wrappers.R.
Generated artifacts that must stay committed:
rpkg/configurerpkg/R/miniextendr-wrappers.Rrpkg/config.guessrpkg/config.sub
Common workflows from the repo root:
just configure # dev configure + sync vendored workspace crates
just devtools-load # compile Rust, regenerate wrappers, load rpkg
just devtools-test # run rpkg tests
just vendor # build rpkg/inst/vendor.tar.xz for CRAN/offline builds
just configure-cran # configure rpkg against vendored sources only
just r-cmd-check # build tarball and run R CMD checkRequirements:
- Rust toolchain (edition 2024)
- R with headers and
RonPATH autoconffor regeneratingconfigurejustfor the repo task wrappers
Common tasks:
just --list
just check
just check-features
just test
just clippy
just devtools-test
just cross-testdocs/README.md- docs index for architecture, build system, features, and troubleshootingminiextendr-cli/README.md- CLI surface and command groupsminiextendr-api/README.md- runtime crate overview and feature summaryminirextendr/README.md- scaffolding and R-side workflow helperstests/cross-package/README.md- end-to-end trait ABI examplecargo-revendor/README.md- standalone vendoring tool for offline builds
- Do not embed R in the CRAN-facing package shared library.
miniextendr-engineis for standalone binaries/tests, not for R packages. - Keep
nonapidisabled unless you are prepared for CRAN checks to flag non-API symbol usage. - Vendor Rust dependencies into the package tarball and include
inst/vendor.tar.xzwhen building offline/CRAN releases. - Keep
configure,config.guess,config.sub, and the generated wrappers committed. - Run
R CMD checkon the release tarball before submission.
- Regenerate
rpkg/configurewheneverrpkg/configure.acchanges. - Update
config.guessandconfig.subfrom GNU config when needed. - Keep wrapper generation aligned with macro output.
- Run both Rust and R validation paths before cutting releases.
MIT (see LICENSE-MIT).