Skip to content

Commit f9f0c8e

Browse files
Better vendor experience (#479)
* feat: condition to clean vendor directory after creating tarball * feat: use vendor/ directory if it exists * docs: update NEWS
1 parent 1688f4b commit f9f0c8e

File tree

6 files changed

+52
-11
lines changed

6 files changed

+52
-11
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* Replaces internal `invoke_cargo()` with `run_cargo()` in `rust_source()`
77
* Simplifies handling of macro options in `rust_function(extendr_fn_options = list())`
88
* Unknown macro options in dev and release now throw errors instead of warnings
9+
* `vendor_pkgs()` now has a `clean` argument to remove the `src/rust/vendor` directory after creating the `vendor.tar.xz` file. (#479)
10+
* `Makevars`(.win) now uses the `vendor/`, if it exists, before unzipping the tarball. (#479)
911

1012
# rextendr 0.4.2
1113

R/cran-compliance.R

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
# the vendored dependencies using [`vendor_pkgs()`].
88
#'
99
#' @inheritParams use_extendr
10+
#'
11+
#' @param clean `logical(1)` indicating whether the `vendor/` directory should be removed after
12+
#' creating the `vendor.tar.xz` file. Defaults to `FALSE`.
13+
#'
1014
#' @returns
1115
#'
1216
#' - `vendor_pkgs()` returns a data.frame with two columns `crate` and `version`
@@ -16,7 +20,7 @@
1620
#' vendor_pkgs()
1721
#' }
1822
#' @export
19-
vendor_pkgs <- function(path = ".", quiet = FALSE, overwrite = NULL) {
23+
vendor_pkgs <- function(path = ".", quiet = FALSE, overwrite = NULL, clean = FALSE) {
2024
stderr_line_callback <- function(x, proc) {
2125
if (!cli::ansi_grepl("To use vendored sources", x) && cli::ansi_nzchar(x)) {
2226
cli::cat_bullet(stringi::stri_trim_left(x))
@@ -119,7 +123,7 @@ vendor_pkgs <- function(path = ".", quiet = FALSE, overwrite = NULL) {
119123
}
120124

121125
# clean up vendor directory
122-
if (dir.exists(file.path(src_dir, "vendor"))) {
126+
if (clean && dir.exists(file.path(src_dir, "vendor"))) {
123127
cli::cli_alert_info("Removing {.path src/rust/vendor} directory")
124128
unlink(file.path(src_dir, "vendor"), recursive = TRUE)
125129
}

inst/templates/Makevars.in

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,16 @@ VENDOR_DIR = $(CURDIR)/vendor
1919
# CRAN note: Cargo and Rustc versions are reported during
2020
# configure via tools/msrv.R.
2121
#
22-
# vendor.tar.xz, if present, is unzipped and used for offline compilation.
22+
# If a vendor directory exists, it is used for offline compilation. Otherwise if
23+
# vendor.tar.xz exists, it is unzipped and used for offline compilation.
2324
$(STATLIB):
2425

25-
if [ -f ./rust/vendor.tar.xz ]; then \
26+
if [ -d ./vendor ]; then \
27+
echo "=== Using offline vendor directory ==="; \
28+
mkdir -p $(CARGOTMP) && \
29+
cp rust/vendor-config.toml $(CARGOTMP)/config.toml; \
30+
elif [ -f ./rust/vendor.tar.xz ]; then \
31+
echo "=== Using offline vendor tarball ==="; \
2632
tar xf rust/vendor.tar.xz && \
2733
mkdir -p $(CARGOTMP) && \
2834
cp rust/vendor-config.toml $(CARGOTMP)/config.toml; \

inst/templates/Makevars.win.in

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,14 @@ $(STATLIB):
1818
mkdir -p $(TARGET_DIR)/libgcc_mock
1919
touch $(TARGET_DIR)/libgcc_mock/libgcc_eh.a
2020

21-
if [ -f ./rust/vendor.tar.xz ]; then \
21+
# If a vendor directory exists, it is used for offline compilation. Otherwise if
22+
# vendor.tar.xz exists, it is unzipped and used for offline compilation.
23+
if [ -d ./vendor ]; then \
24+
echo "=== Using offline vendor directory ==="; \
25+
mkdir -p $(CARGOTMP) && \
26+
cp rust/vendor-config.toml $(CARGOTMP)/config.toml; \
27+
elif [ -f ./rust/vendor.tar.xz ]; then \
28+
echo "=== Using offline vendor tarball ==="; \
2229
tar xf rust/vendor.tar.xz && \
2330
mkdir -p $(CARGOTMP) && \
2431
cp rust/vendor-config.toml $(CARGOTMP)/config.toml; \

man/vendor_pkgs.Rd

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/_snaps/use_extendr.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,16 @@
212212
# CRAN note: Cargo and Rustc versions are reported during
213213
# configure via tools/msrv.R.
214214
#
215-
# vendor.tar.xz, if present, is unzipped and used for offline compilation.
215+
# If a vendor directory exists, it is used for offline compilation. Otherwise if
216+
# vendor.tar.xz exists, it is unzipped and used for offline compilation.
216217
$(STATLIB):
217218
218-
if [ -f ./rust/vendor.tar.xz ]; then \
219+
if [ -d ./vendor ]; then \
220+
echo "=== Using offline vendor directory ==="; \
221+
mkdir -p $(CARGOTMP) && \
222+
cp rust/vendor-config.toml $(CARGOTMP)/config.toml; \
223+
elif [ -f ./rust/vendor.tar.xz ]; then \
224+
echo "=== Using offline vendor tarball ==="; \
219225
tar xf rust/vendor.tar.xz && \
220226
mkdir -p $(CARGOTMP) && \
221227
cp rust/vendor-config.toml $(CARGOTMP)/config.toml; \
@@ -273,7 +279,14 @@
273279
mkdir -p $(TARGET_DIR)/libgcc_mock
274280
touch $(TARGET_DIR)/libgcc_mock/libgcc_eh.a
275281
276-
if [ -f ./rust/vendor.tar.xz ]; then \
282+
# If a vendor directory exists, it is used for offline compilation. Otherwise if
283+
# vendor.tar.xz exists, it is unzipped and used for offline compilation.
284+
if [ -d ./vendor ]; then \
285+
echo "=== Using offline vendor directory ==="; \
286+
mkdir -p $(CARGOTMP) && \
287+
cp rust/vendor-config.toml $(CARGOTMP)/config.toml; \
288+
elif [ -f ./rust/vendor.tar.xz ]; then \
289+
echo "=== Using offline vendor tarball ==="; \
277290
tar xf rust/vendor.tar.xz && \
278291
mkdir -p $(CARGOTMP) && \
279292
cp rust/vendor-config.toml $(CARGOTMP)/config.toml; \
@@ -442,10 +455,16 @@
442455
# CRAN note: Cargo and Rustc versions are reported during
443456
# configure via tools/msrv.R.
444457
#
445-
# vendor.tar.xz, if present, is unzipped and used for offline compilation.
458+
# If a vendor directory exists, it is used for offline compilation. Otherwise if
459+
# vendor.tar.xz exists, it is unzipped and used for offline compilation.
446460
$(STATLIB):
447461
448-
if [ -f ./rust/vendor.tar.xz ]; then \
462+
if [ -d ./vendor ]; then \
463+
echo "=== Using offline vendor directory ==="; \
464+
mkdir -p $(CARGOTMP) && \
465+
cp rust/vendor-config.toml $(CARGOTMP)/config.toml; \
466+
elif [ -f ./rust/vendor.tar.xz ]; then \
467+
echo "=== Using offline vendor tarball ==="; \
449468
tar xf rust/vendor.tar.xz && \
450469
mkdir -p $(CARGOTMP) && \
451470
cp rust/vendor-config.toml $(CARGOTMP)/config.toml; \

0 commit comments

Comments
 (0)