diff --git a/R/use_extendr.R b/R/use_extendr.R index c7a1a0c0..bcb07f5a 100644 --- a/R/use_extendr.R +++ b/R/use_extendr.R @@ -68,6 +68,22 @@ use_extendr <- function(path = ".", cli::cli_alert_success("Creating {.file {pretty_rel_path(rust_src_dir, path)}}.") } + use_rextendr_template( + "configure", + save_as = file.path("configure"), + quiet = quiet, + as_executable = TRUE, + overwrite = overwrite + ) + + use_rextendr_template( + "configure.win", + save_as = file.path("configure.win"), + quiet = quiet, + as_executable = TRUE, + overwrite = overwrite + ) + use_rextendr_template( "entrypoint.c", save_as = file.path("src", "entrypoint.c"), @@ -211,6 +227,7 @@ throw_if_invalid_rust_name <- function(name, call = caller_env()) { #' #' @inheritParams usethis::use_template #' @inheritParams use_extendr +#' @param as_executable Logical scalar indicating whether the file should be executable. #' @param overwrite Logical scalar or `NULL` indicating whether the file in the `path` should be overwritten. #' If `FALSE` and the file already exists, the function will do nothing. #' If `NULL` and the `usethis` package is installed, the function will ask the user whether the file should @@ -221,6 +238,7 @@ use_rextendr_template <- function(template, save_as = template, data = list(), quiet = FALSE, + as_executable = FALSE, overwrite = NULL) { local_quiet_cli(quiet) @@ -265,6 +283,10 @@ use_rextendr_template <- function(template, overwrite = overwrite ) + if (isTRUE(as_executable)) { + Sys.chmod(save_as, mode = "755") + } + invisible(TRUE) } diff --git a/inst/templates/configure b/inst/templates/configure new file mode 100755 index 00000000..ba9d0187 --- /dev/null +++ b/inst/templates/configure @@ -0,0 +1,19 @@ +#!/usr/bin/env sh + +export PATH="$PATH:$HOME/.cargo/bin" + +if [ ! "$(command -v cargo)" ]; then + echo "----------------------- [RUST NOT FOUND]---------------------------" + echo "The 'cargo' command was not found on the PATH. Please install rustc" + echo "from: https://www.rust-lang.org/tools/install" + echo "" + echo "Alternatively, you may install cargo from your OS package manager:" + echo " - Debian/Ubuntu: apt-get install cargo" + echo " - Fedora/CentOS: dnf install cargo" + echo " - macOS: brew install rustc" + echo "-------------------------------------------------------------------" + echo "" + exit 1 +fi + +exit 0 diff --git a/inst/templates/configure.win b/inst/templates/configure.win new file mode 100755 index 00000000..f7df64e5 --- /dev/null +++ b/inst/templates/configure.win @@ -0,0 +1,14 @@ +#!/bin/sh + +export PATH="$PATH:$HOME/.cargo/bin" + +if [ ! "$(command -v cargo)" ]; then + echo "----------------------- [RUST NOT FOUND]---------------------------" + echo "The 'cargo' command was not found on the PATH. Please install rustc" + echo "from: https://www.rust-lang.org/tools/install" + echo "-------------------------------------------------------------------" + echo "" + exit 1 +fi + +exit 0 diff --git a/tests/testthat/_snaps/use_extendr.md b/tests/testthat/_snaps/use_extendr.md index 843f532c..201ee65a 100644 --- a/tests/testthat/_snaps/use_extendr.md +++ b/tests/testthat/_snaps/use_extendr.md @@ -7,6 +7,8 @@ i Setting `Config/rextendr/version` to "0.3.1.9000" in the 'DESCRIPTION' file. i Setting `SystemRequirements` to "Cargo (rustc package manager)" in the 'DESCRIPTION' file. v Creating 'src/rust/src'. + v Writing 'configure' + v Writing 'configure.win' v Writing 'src/entrypoint.c' v Writing 'src/Makevars' v Writing 'src/Makevars.win' @@ -203,6 +205,8 @@ Code use_extendr() Message + > File 'configure' already exists. Skip writing the file. + > File 'configure.win' already exists. Skip writing the file. > File 'src/entrypoint.c' already exists. Skip writing the file. > File 'src/Makevars' already exists. Skip writing the file. > File 'src/Makevars.win' already exists. Skip writing the file. @@ -220,6 +224,8 @@ Code use_extendr(crate_name = "foo", lib_name = "bar", overwrite = TRUE) Message + v Writing 'configure' + v Writing 'configure.win' v Writing 'src/entrypoint.c' v Writing 'src/Makevars' v Writing 'src/Makevars.win'