Skip to content

Commit

Permalink
Merge branch 'main' into prelude_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilia-Kosenkov authored Nov 29, 2024
2 parents bf70078 + 4217a0e commit 0aff8be
Show file tree
Hide file tree
Showing 65 changed files with 1,738 additions and 1,084 deletions.
32 changes: 19 additions & 13 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@ on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
types:
- opened
- reopened
- synchronize
- ready_for_review

name: test-coverage
name: test-coverage.yaml

permissions: read-all

jobs:
test-coverage:
Expand All @@ -21,36 +17,46 @@ jobs:
REXTENDR_SKIP_DEV_TESTS: TRUE # TODO: Remove this when extendr/libR-sys issue is resolved

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::covr
extra-packages: any::covr, any::xml2
needs: coverage

- name: Test coverage
run: |
covr::codecov(
cov <- covr::package_coverage(
quiet = FALSE,
clean = FALSE,
install_path = file.path(Sys.getenv("RUNNER_TEMP"), "package")
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")
)
covr::to_cobertura(cov)
shell: Rscript {0}

- uses: codecov/codecov-action@v4
with:
# Fail if error if not on PR, or if on PR and token is given
fail_ci_if_error: ${{ github.event_name != 'pull_request' || secrets.CODECOV_TOKEN }}
file: ./cobertura.xml
plugin: noop
disable_search: true
token: ${{ secrets.CODECOV_TOKEN }}

- name: Show testthat output
if: always()
run: |
## --------------------------------------------------------------------
find ${{ runner.temp }}/package -name 'testthat.Rout*' -exec cat '{}' \; || true
find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Upload test results
if: failure()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: coverage-test-failures
path: ${{ runner.temp }}/package
11 changes: 0 additions & 11 deletions .github/workflows/test_pkg_gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,6 @@ jobs:
file.path("tests", "testthat", "test-hello.R")
)
# test NOT_CRAN envvar
brio::write_lines(
c(
"if [ \"$NOT_CRAN\" != \"true\" ]; then",
" exit 1",
"fi"
),
file.path("configure")
)
Sys.chmod("configure", "0755")
# TODO: allow warnings on oldrel (cf., https://stat.ethz.ch/pipermail/r-package-devel/2023q2/009229.html)
if (.Platform$OS.type == "windows" && getRversion() < "4.3.0") {
error_on <- "error"
Expand Down
5 changes: 2 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: rextendr
Title: Call Rust Code from R using the 'extendr' Crate
Version: 0.3.1.9001
Authors@R:
Authors@R:
c(person(given = "Claus O.",
family = "Wilke",
role = "aut",
Expand Down Expand Up @@ -48,7 +48,6 @@ Imports:
jsonlite,
pkgbuild (>= 1.4.0),
processx,
purrr,
rlang (>= 1.0.5),
rprojroot,
stringi,
Expand All @@ -57,10 +56,10 @@ Imports:
withr
Suggests:
devtools,
rcmdcheck,
knitr,
lintr,
rmarkdown,
rstudioapi,
testthat (>= 3.1.7),
usethis
VignetteBuilder:
Expand Down
10 changes: 1 addition & 9 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ export(document)
export(eng_extendr)
export(eng_extendrsrc)
export(make_module_macro)
export(read_cargo_metadata)
export(register_extendr)
export(rust_eval)
export(rust_function)
export(rust_sitrep)
export(rust_source)
export(to_toml)
export(use_cran_defaults)
export(use_crate)
export(use_extendr)
export(use_msrv)
Expand All @@ -30,14 +30,6 @@ importFrom(dplyr,"%>%")
importFrom(dplyr,mutate)
importFrom(glue,glue)
importFrom(glue,glue_collapse)
importFrom(purrr,discard)
importFrom(purrr,every)
importFrom(purrr,flatten_chr)
importFrom(purrr,map)
importFrom(purrr,map2)
importFrom(purrr,map2_chr)
importFrom(purrr,map_if)
importFrom(purrr,map_lgl)
importFrom(rlang,"%||%")
importFrom(rlang,.data)
importFrom(rlang,.env)
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# rextendr (development version)

* `purrr` has been replaced with [`R/standalone-purrr.R`](https://github.com/r-lib/rlang/blob/main/R/standalone-purrr.R) removing `purrr` from `Imports` <https://github.com/extendr/rextendr/pull/408>
* `document()` will no longer try to save all open files using rstudioapi <https://github.com/extendr/rextendr/issues/404> <https://github.com/extendr/rextendr/issues/407>
* `use_cran_default()` has been removed as the default package template is CRAN compatible <https://github.com/extendr/rextendr/pull/394>
* `use_extendr()` now creates `tools/msrv.R`, `configure` and `configure.win`. These have been moved out of `use_cran_defaults()` <https://github.com/extendr/rextendr/pull/393>
* `Makevars` now prints linked static libraries at compile time by adding `--print=native-static-libs` to `RUSTFLAGS` <https://github.com/extendr/rextendr/pull/393>
* `use_extendr()` sets the `DESCRIPTION`'s `SystemRequirements` field according to CRAN policy to `Cargo (Rust's package manager), rustc` (#329)
* Introduces new functions `use_cran_defaults()` and `vendor_pkgs()` to ease the publication of extendr-powered packages on CRAN. See the new article _CRAN compliant extendr packages_ on how to use these (#320).
* `rust_sitrep()` now better communicates the status of the Rust toolchain and available targets. It also guides the user through necessary installation steps to fix Rust setup (#318).
Expand All @@ -16,6 +21,8 @@
* Fixed an issue in `rust_source()` family of functions that prevented usage of `r#` escape sequences in Rust function names (#374)
* `use_cran_defaults()` now checks the `SystemRequirements` field in the `DESCRIPTION` file for cargo and rustc. It will display installation instructions if either is missing or provide the minimum required version if the installed version is outdated.
* Added `use_msrv()` to aid in specifying the minimum supported rust version (MSRV) for an R package
* Added `read_cargo_metadata()` to retrieve Cargo metadata for packages and
workspaces. (#389)

# rextend 0.3.1

Expand Down
91 changes: 42 additions & 49 deletions R/clean.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,76 +4,69 @@
#' invokes `cargo clean` to reset cargo target directory
#' (found by default at `pkg_root/src/rust/target/`).
#' Useful when Rust code should be recompiled from scratch.
#' @param path \[ string \] Path to the package root.
#'
#' @param path character scalar, path to R package root.
#' @param echo logical scalar, should cargo command and outputs be printed to
#' console (default is `TRUE`)
#'
#' @return character vector with names of all deleted files (invisibly).
#'
#' @export
clean <- function(path = ".") {
root <- rprojroot::find_package_root_file(path = path)

rust_folder <- normalizePath(
file.path(root, "src", "rust"),
winslash = "/",
mustWork = FALSE
)
#'
#' @examples
#' \dontrun{
#' clean()
#' }
clean <- function(path = ".", echo = TRUE) {
check_string(path, class = "rextendr_error")
check_bool(echo, class = "rextendr_error")

toml_path <- normalizePath(
file.path(rust_folder, "Cargo.toml"),
winslash = "/",
mustWork = FALSE
)
manifest_path <- find_extendr_manifest(path = path)

# Note: This should be adjusted if `TARGET_DIR` changes in `Makevars`
target_dir <- normalizePath( # nolint: object_usage_linter
file.path(rust_folder, "target"),
winslash = "/",
mustWork = FALSE
target_dir <- rprojroot::find_package_root_file(
"src", "rust", "target",
path = path
)

if (!file.exists(toml_path)) {
cli::cli_abort(c(
"Unable to clean binaries.",
"!" = "{.file Cargo.toml} not found in {.path {rust_folder}}.",
if (!dir.exists(target_dir)) {
cli::cli_abort(
c(
"Could not clean binaries.",
"Target directory not found at {.path target_dir}."
),
call = rlang::caller_call(),
class = "rextendr_error"
))
)
}

cargo_envvars <- get_cargo_envvars()

args <- c(
"clean",
glue("--manifest-path={toml_path}"),
glue("--target-dir={target_dir}"),
glue::glue("--manifest-path={manifest_path}"),
glue::glue("--target-dir={target_dir}"),
if (tty_has_colors()) {
"--color=always"
} else {
"--color=never"
},
"--quiet"
}
)
exec_result <- processx::run(
command = "cargo",
args = args,
echo_cmd = FALSE,
windows_verbatim_args = FALSE,
stderr = "|",
stdout = "|",
error_on_status = FALSE,
env = cargo_envvars

run_cargo(
args,
wd = find_extendr_crate(path = path),
echo = echo
)

if (!isTRUE(exec_result$status == 0)) {
if (!tty_has_colors()) {
err_msg <- cli::ansi_strip(exec_result$stderr)
} else {
err_msg <- exec_result$stderr
}
root <- rprojroot::find_package_root_file(path = path)

if (!dir.exists(root)) {
cli::cli_abort(
c(
"Unable to execute {.code cargo clean}.",
"x" = paste(err_msg, collapse = "\n")
),
call = caller_env(),
"Could not clean binaries.",
"R package directory not found at {.path root}.",
call = rlang::caller_call(),
class = "rextendr_error"
)
}

pkgbuild::clean_dll(path = root)
}
Loading

0 comments on commit 0aff8be

Please sign in to comment.