libR-sys

Low-level R library bindings

Github Actions Build Status crates.io Documentation License: MIT

Installation

The recommended way to build this library is to use precomputed bindings, which are available for Linux, macOS, and Windows (32- and 64-bit).

Alternatively, the library can be built from source, in which case it invokes bindgen crate, which has extra platform-specific dependencies (including msys2 for Windows).

Using precomputed bindings (recommended)

Two components are required to build the library: 1. R: It needs to be installed and available in the search path. 2. rust: It is recommended to install rust using rustup; search path should include rust binaries.

Once R and rust are configured, the library can be easily built: - macOS/Linux Shell cargo build

To test the build, run cargo test.

Building bindings from source (advanced)

The bindings can be generated using bindgen, special rust crate. bindgen usage is enabled via use-bindgen feature flag.

bindgen requires libclang, which should be installed first. This library relies on LIBCLANG_PATH environment variable to determine path to the appropriate version of libclang.

The output folder for bindings can be configured using LIBRSYS_BINDINGS_OUTPUT_PATH environment variable.

Conditional compilation depending on R installation

libR-sys crate provides these environmental variables that you can use in build.rs:

Example build.rs

``` rust use std::env;

fn main() { // Set RHOME envvar, and refer to it on compile time by env!("RHOME") let rhome = env::var("DEPRRHOME").unwrap(); println!("cargo:rustc-env=RHOME={}", rhome);

// Enable cfg setting to conditionally compile a code using a feature
// available only on newer versions of R
let major = env::var("DEP_R_R_VERSION_MAJOR").unwrap();
let minor = env::var("DEP_R_R_VERSION_MINOR").unwrap();
if &*major >= "4" && &*minor >= "1" {
    println!("cargo:rustc-cfg=use_a_feature");
}

} ```