Skip to content

Commit c597089

Browse files
Merge branch 'main' into feature/Support-win-arm64-in-rust-source
2 parents 69af463 + 841b343 commit c597089

File tree

10 files changed

+104
-16
lines changed

10 files changed

+104
-16
lines changed

.github/workflows/R-CMD-check.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ jobs:
4444
toolchain: ${{ matrix.config.rust-version }}
4545
targets: ${{ matrix.config.rust-target }}
4646

47+
# Add rust-cache for faster builds
48+
- name: Cache Rust dependencies
49+
uses: Swatinem/rust-cache@v2
50+
with:
51+
shared-key: ${{ matrix.config.os }}-${{ matrix.config.rust-version }}
52+
cache-on-failure: true
53+
4754
- uses: baptiste0928/cargo-install@v3
4855
if: matrix.config.r == 'release'
4956
with:

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
}

R/find_exports.R

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ find_exports <- function(clean_lns) {
55

66
# start and end may empty
77
if (rlang::is_empty(start) || rlang::is_empty(end)) {
8-
return(data.frame(name = character(0), type = character(0), lifetime = character(0)))
8+
return(data.frame(
9+
name = character(0),
10+
type = character(0),
11+
lifetime = character(0)
12+
))
913
}
1014

1115
map2(start, end, \(.x, .y) extract_meta(clean_lns[.x:.y])) |>
@@ -16,8 +20,9 @@ find_exports <- function(clean_lns) {
1620
}
1721

1822
# Finds lines which contain #[extendr] (allowing additional spaces)
23+
# Excludes #[extendr(default=...)] which is used for function arguments
1924
find_extendr_attrs_ids <- function(lns) {
20-
which(stringi::stri_detect_regex(lns, r"{#\s*\[\s*extendr(\s*\(.*\))?\s*\]}"))
25+
which(stringi::stri_detect_regex(lns, r"{#\s*\[\s*extendr(\s*\((?!.*default\s*=).*\))?\s*\]}"))
2126
}
2227

2328
# Gets function/module metadata from a subset of lines.
@@ -29,7 +34,15 @@ extract_meta <- function(lns) {
2934
"(?:(?<struct>struct)|(?<enum>enum)|(?<fn>fn)|(?<impl>impl)(?:\\s*<(?<lifetime>.+?)>)?)\\s+(?<name>(?:r#)?(?:_\\w+|[A-z]\\w*))" # nolint: line_length_linter
3035
) |>
3136
as.data.frame() |>
32-
rlang::set_names(c("match", "struct", "enum", "fn", "impl", "lifetime", "name")) |>
37+
rlang::set_names(c(
38+
"match",
39+
"struct",
40+
"enum",
41+
"fn",
42+
"impl",
43+
"lifetime",
44+
"name"
45+
)) |>
3346
dplyr::filter(!is.na(.data$match))
3447

3548
# If no matches have been found, then the attribute is misplaced
@@ -38,10 +51,10 @@ extract_meta <- function(lns) {
3851
# meaningful output or source line numbers.
3952
code_sample <- stringi::stri_sub(
4053
glue_collapse(lns, sep = "\n "),
41-
1, 80
54+
1,
55+
80
4256
)
4357

44-
4558
rlang::abort(
4659
cli::cli_fmt({
4760
cli::cli_text(

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/data/test-default-arg.Rmd

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
```{r, include = FALSE}
3+
library(rextendr)
4+
```
5+
6+
7+
```{extendrsrc engine.opts = list(use_dev_extendr=TRUE)}
8+
#[extendr]
9+
fn check_default(#[extendr(default = "NULL")] x: Robj) -> bool {
10+
x.is_null()
11+
}
12+
```
13+
```{r}
14+
testthat::expect_true(check_default())
15+
```

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; \

tests/testthat/test-knitr-engine.R

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,15 @@ test_that("Snapshot test of knitr-engine", {
3434
knitr::knit(input, output)
3535
expect_snapshot(cat_file(output))
3636
})
37+
38+
39+
test_that("knitr-engine for #[extendr(default = )]", {
40+
skip_if_cargo_unavailable()
41+
skip_if_not_installed("knitr")
42+
skip_on_cran()
43+
44+
input <- file.path("../data/test-default-arg.Rmd")
45+
output <- withr::local_file("snapshot-extendr-default.md")
46+
knitr::knit(input, output)
47+
expect_true(check_default())
48+
})

0 commit comments

Comments
 (0)