Compile a Rust step once for reuse across branches (worker behind tarpolyglot_map)
Source:R/run-step-rs.R
compile_rs_lib.RdCompiles the #[extendr] functions in a Rust script with rextendr::rust_source() and returns a self-contained bundle (the compiled shared library plus its generated R wrappers) that run_rs_step_prebuilt() can reload in any branch without recompiling. This is the function the companion <name>_rust_lib target built by tar_target_rs(..., pattern = tarpolyglot_map(...)) calls; it is exported so the call resolves at run time, but package users should not call it directly.
Usage
compile_rs_lib(
script,
dependencies = NULL,
features = NULL,
profile = NULL,
toolchain = NULL
)Arguments
- script
Path to the Rust script containing
#[extendr]functions (required).- dependencies, features, profile
Passed to
rextendr::rust_source(): cratedependencies(named list), Cargofeatures, and buildprofile(e.g."dev"or"release").- toolchain
Optional rustup toolchain (e.g.
"stable-x86_64-pc-windows-gnu"); setsRUSTUP_TOOLCHAINfor the build. DefaultNULLuses the rustup default toolchain.
Value
An object of class tp_rust_lib: a list with the library basename, the raw library bytes, and the generated wrapper objs (named list of R functions).
Details
The bundle embeds the library bytes, so it travels with the target's value to any worker or machine, and reloading is a dyn.load() (near-instant) rather than a fresh cargo build. See tarpolyglot_map() for the motivation and run_rs_step() for the per-branch (recompiling) alternative.