From 6b12f28bdc37b629adcdc04e4ba654e529378adf Mon Sep 17 00:00:00 2001 From: Alberson Miranda Date: Wed, 1 Oct 2025 15:11:51 -0300 Subject: [PATCH 1/3] feat: condition to clean vendor directory after creating tarball --- R/cran-compliance.R | 8 ++++++-- man/vendor_pkgs.Rd | 5 ++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/R/cran-compliance.R b/R/cran-compliance.R index 20fdf0ea..f992fae5 100644 --- a/R/cran-compliance.R +++ b/R/cran-compliance.R @@ -7,6 +7,10 @@ # the vendored dependencies using [`vendor_pkgs()`]. #' #' @inheritParams use_extendr +#' +#' @param clean `logical(1)` indicating whether the `vendor/` directory should be removed after +#' creating the `vendor.tar.xz` file. Defaults to `FALSE`. +#' #' @returns #' #' - `vendor_pkgs()` returns a data.frame with two columns `crate` and `version` @@ -16,7 +20,7 @@ #' vendor_pkgs() #' } #' @export -vendor_pkgs <- function(path = ".", quiet = FALSE, overwrite = NULL) { +vendor_pkgs <- function(path = ".", quiet = FALSE, overwrite = NULL, clean = FALSE) { stderr_line_callback <- function(x, proc) { if (!cli::ansi_grepl("To use vendored sources", x) && cli::ansi_nzchar(x)) { cli::cat_bullet(stringi::stri_trim_left(x)) @@ -119,7 +123,7 @@ vendor_pkgs <- function(path = ".", quiet = FALSE, overwrite = NULL) { } # clean up vendor directory - if (dir.exists(file.path(src_dir, "vendor"))) { + if (clean && dir.exists(file.path(src_dir, "vendor"))) { cli::cli_alert_info("Removing {.path src/rust/vendor} directory") unlink(file.path(src_dir, "vendor"), recursive = TRUE) } diff --git a/man/vendor_pkgs.Rd b/man/vendor_pkgs.Rd index 8e133c19..e2928f5d 100644 --- a/man/vendor_pkgs.Rd +++ b/man/vendor_pkgs.Rd @@ -4,7 +4,7 @@ \alias{vendor_pkgs} \title{Vendor Rust dependencies} \usage{ -vendor_pkgs(path = ".", quiet = FALSE, overwrite = NULL) +vendor_pkgs(path = ".", quiet = FALSE, overwrite = NULL, clean = FALSE) } \arguments{ \item{path}{File path to the package for which to generate wrapper code.} @@ -17,6 +17,9 @@ If \code{NULL} (default), the function will ask the user whether each file shoul be overwritten in an interactive session or do nothing in a non-interactive session. If \code{FALSE} and each file already exists, the function will do nothing. If \code{TRUE}, all files will be overwritten.} + +\item{clean}{\code{logical(1)} indicating whether the \verb{vendor/} directory should be removed after +creating the \code{vendor.tar.xz} file. Defaults to \code{FALSE}.} } \value{ \itemize{ From 4a60bfc9adf87f8534f78cffdeac46dd32c26b6f Mon Sep 17 00:00:00 2001 From: Alberson Miranda Date: Wed, 1 Oct 2025 15:15:25 -0300 Subject: [PATCH 2/3] feat: use vendor/ directory if it exists --- inst/templates/Makevars.in | 10 ++++++++-- inst/templates/Makevars.win.in | 9 ++++++++- tests/testthat/_snaps/use_extendr.md | 29 +++++++++++++++++++++++----- 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/inst/templates/Makevars.in b/inst/templates/Makevars.in index 47bb954b..8a9d7540 100644 --- a/inst/templates/Makevars.in +++ b/inst/templates/Makevars.in @@ -19,10 +19,16 @@ VENDOR_DIR = $(CURDIR)/vendor # CRAN note: Cargo and Rustc versions are reported during # configure via tools/msrv.R. # -# vendor.tar.xz, if present, is unzipped and used for offline compilation. +# If a vendor directory exists, it is used for offline compilation. Otherwise if +# vendor.tar.xz exists, it is unzipped and used for offline compilation. $(STATLIB): - if [ -f ./rust/vendor.tar.xz ]; then \ + if [ -d ./vendor ]; then \ + echo "=== Using offline vendor directory ==="; \ + mkdir -p $(CARGOTMP) && \ + cp rust/vendor-config.toml $(CARGOTMP)/config.toml; \ + elif [ -f ./rust/vendor.tar.xz ]; then \ + echo "=== Using offline vendor tarball ==="; \ tar xf rust/vendor.tar.xz && \ mkdir -p $(CARGOTMP) && \ cp rust/vendor-config.toml $(CARGOTMP)/config.toml; \ diff --git a/inst/templates/Makevars.win.in b/inst/templates/Makevars.win.in index 4fe0d219..077bf062 100644 --- a/inst/templates/Makevars.win.in +++ b/inst/templates/Makevars.win.in @@ -18,7 +18,14 @@ $(STATLIB): mkdir -p $(TARGET_DIR)/libgcc_mock touch $(TARGET_DIR)/libgcc_mock/libgcc_eh.a - if [ -f ./rust/vendor.tar.xz ]; then \ + # If a vendor directory exists, it is used for offline compilation. Otherwise if + # vendor.tar.xz exists, it is unzipped and used for offline compilation. + if [ -d ./vendor ]; then \ + echo "=== Using offline vendor directory ==="; \ + mkdir -p $(CARGOTMP) && \ + cp rust/vendor-config.toml $(CARGOTMP)/config.toml; \ + elif [ -f ./rust/vendor.tar.xz ]; then \ + echo "=== Using offline vendor tarball ==="; \ tar xf rust/vendor.tar.xz && \ mkdir -p $(CARGOTMP) && \ cp rust/vendor-config.toml $(CARGOTMP)/config.toml; \ diff --git a/tests/testthat/_snaps/use_extendr.md b/tests/testthat/_snaps/use_extendr.md index 20327066..901e87d0 100644 --- a/tests/testthat/_snaps/use_extendr.md +++ b/tests/testthat/_snaps/use_extendr.md @@ -212,10 +212,16 @@ # CRAN note: Cargo and Rustc versions are reported during # configure via tools/msrv.R. # - # vendor.tar.xz, if present, is unzipped and used for offline compilation. + # If a vendor directory exists, it is used for offline compilation. Otherwise if + # vendor.tar.xz exists, it is unzipped and used for offline compilation. $(STATLIB): - if [ -f ./rust/vendor.tar.xz ]; then \ + if [ -d ./vendor ]; then \ + echo "=== Using offline vendor directory ==="; \ + mkdir -p $(CARGOTMP) && \ + cp rust/vendor-config.toml $(CARGOTMP)/config.toml; \ + elif [ -f ./rust/vendor.tar.xz ]; then \ + echo "=== Using offline vendor tarball ==="; \ tar xf rust/vendor.tar.xz && \ mkdir -p $(CARGOTMP) && \ cp rust/vendor-config.toml $(CARGOTMP)/config.toml; \ @@ -273,7 +279,14 @@ mkdir -p $(TARGET_DIR)/libgcc_mock touch $(TARGET_DIR)/libgcc_mock/libgcc_eh.a - if [ -f ./rust/vendor.tar.xz ]; then \ + # If a vendor directory exists, it is used for offline compilation. Otherwise if + # vendor.tar.xz exists, it is unzipped and used for offline compilation. + if [ -d ./vendor ]; then \ + echo "=== Using offline vendor directory ==="; \ + mkdir -p $(CARGOTMP) && \ + cp rust/vendor-config.toml $(CARGOTMP)/config.toml; \ + elif [ -f ./rust/vendor.tar.xz ]; then \ + echo "=== Using offline vendor tarball ==="; \ tar xf rust/vendor.tar.xz && \ mkdir -p $(CARGOTMP) && \ cp rust/vendor-config.toml $(CARGOTMP)/config.toml; \ @@ -442,10 +455,16 @@ # CRAN note: Cargo and Rustc versions are reported during # configure via tools/msrv.R. # - # vendor.tar.xz, if present, is unzipped and used for offline compilation. + # If a vendor directory exists, it is used for offline compilation. Otherwise if + # vendor.tar.xz exists, it is unzipped and used for offline compilation. $(STATLIB): - if [ -f ./rust/vendor.tar.xz ]; then \ + if [ -d ./vendor ]; then \ + echo "=== Using offline vendor directory ==="; \ + mkdir -p $(CARGOTMP) && \ + cp rust/vendor-config.toml $(CARGOTMP)/config.toml; \ + elif [ -f ./rust/vendor.tar.xz ]; then \ + echo "=== Using offline vendor tarball ==="; \ tar xf rust/vendor.tar.xz && \ mkdir -p $(CARGOTMP) && \ cp rust/vendor-config.toml $(CARGOTMP)/config.toml; \ From ea9de03891e893d7771b3da520b6ba7c283606ac Mon Sep 17 00:00:00 2001 From: Alberson Miranda Date: Wed, 1 Oct 2025 15:30:21 -0300 Subject: [PATCH 3/3] docs: update NEWS --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index b7922939..698d04f0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -6,6 +6,8 @@ * Replaces internal `invoke_cargo()` with `run_cargo()` in `rust_source()` * Simplifies handling of macro options in `rust_function(extendr_fn_options = list())` * Unknown macro options in dev and release now throw errors instead of warnings +* `vendor_pkgs()` now has a `clean` argument to remove the `src/rust/vendor` directory after creating the `vendor.tar.xz` file. (#479) +* `Makevars`(.win) now uses the `vendor/`, if it exists, before unzipping the tarball. (#479) # rextendr 0.4.2