Skip to content

Instantly share code, notes, and snippets.

@aavogt
Created June 29, 2023 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aavogt/0176120f5cefe935d5c92941d8ca37af to your computer and use it in GitHub Desktop.
Save aavogt/0176120f5cefe935d5c92941d8ca37af to your computer and use it in GitHub Desktop.
library(glue)
library(stringr)
require(rlang)
require(rextendr)
# drop-in replacement for rextendr::rust_source
# use a build directory in the current working directory
# if the source file is lib.rs the build is in lib_build
# code= needed for https://github.com/extendr/rextendr/issues/234
rust_source <- function(file, code= paste0(readLines(file), collapse="\n"), features="ndarray", ...) {
# https://github.com/extendr/rextendr/issues/291
rlang::env_bind(rextendr:::the, build_dir = {
b <- file.path(getwd(), glue("{str_remove(file, '.rs')}_build"))
if (!dir.exists(b)) {
dir.create(b)
dir.create(file.path(b, "src"))
dir.create(file.path(b, "R"))
dir.create(file.path(b, ".cargo"))
}
b
})
rextendr::rust_source(code = code, features=features,
env = parent.frame(), ... )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment