Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# rextendr (development version)

* Sets the `extendr-api` version to the latest stable version instead of `"*"` when creating a new package. This is fetched from https://crates.io/api/v1/crates/extendr-api and will fall back to `"*"` if not available <https://github.com/extendr/rextendr/pull/467>
* Adds `xz` to `SystemRequirements` to ensure extendr based packages build on Posit Package Manager <https://github.com/extendr/rextendr/pull/467>
* Sets the release profile to use `lto=true` and `codegen-units=1` to ensure compatible builds with WebR as well as reduce the overall compiled package size <https://github.com/extendr/rextendr/pull/465>.
* Fixes compatibility with WebR by adding `CARGO_PROFILE_DEV_PANIC="abort" CARGO_PROFILE_RELEASE_PANIC="abort"` when targeting `wasm32-unknown-emsacripten` target <https://github.com/extendr/rextendr/pull/461>

Expand Down
18 changes: 13 additions & 5 deletions R/setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ update_rextendr_version <- function(desc_path, cur_version = NULL) {
cur <- cur_version %||% as.character(utils::packageVersion("rextendr"))
prev <- rextendr_version(desc_path = desc_path)

if (!is.na(cur) && !is.na(prev) && package_version(cur) < package_version(prev)) {
if (
!is.na(cur) && !is.na(prev) && package_version(cur) < package_version(prev)
) {
cli::cli_alert_warning(c(
"Installed rextendr is older than the version used with this package",
"You have {.str {cur}} but you need {.str {prev}}"
Expand All @@ -34,8 +36,10 @@ update_rextendr_version <- function(desc_path, cur_version = NULL) {
}

update_sys_reqs <- function(desc_path) {
cur <- "Cargo (Rust's package manager), rustc"
prev <- stringi::stri_trim_both(desc::desc_get("SystemRequirements", file = desc_path)[[1]])
cur <- "Cargo (Rust's package manager), rustc >= 1.65.0, xz"
prev <- stringi::stri_trim_both(
desc::desc_get("SystemRequirements", file = desc_path)[[1]]
)

if (is.na(prev)) {
update_description("SystemRequirements", cur, desc_path = desc_path)
Expand All @@ -50,10 +54,14 @@ update_sys_reqs <- function(desc_path) {
}

update_description <- function(field, value, desc_path) {
cli::cli_alert_info("Setting {.var {field}} to {.str {value}} in the {.file DESCRIPTION} file.")
cli::cli_alert_info(
"Setting {.var {field}} to {.str {value}} in the {.file DESCRIPTION} file."
)
desc::desc_set(field, value, file = desc_path)
}

rextendr_version <- function(desc_path = ".") {
stringi::stri_trim_both(desc::desc_get("Config/rextendr/version", desc_path)[[1]])
stringi::stri_trim_both(desc::desc_get("Config/rextendr/version", desc_path)[[
1
]])
}
10 changes: 9 additions & 1 deletion R/use_extendr.R
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ use_extendr <- function(
)

edition <- match.arg(edition, several.ok = FALSE)

# fetch extendr-api version from options
# this is defined in zzz.R
# defaults to latest stable version or falls back to "*"
extendr_api_version <- options("rextendr.extendr_deps")[[1]][["extendr-api"]]

cargo_toml_content <- to_toml(
package = list(
name = crate_name,
Expand All @@ -136,7 +142,9 @@ use_extendr <- function(
`rust-version` = "1.65"
),
lib = list(`crate-type` = array("staticlib", 1), name = lib_name),
dependencies = list(`extendr-api` = "*"),
dependencies = list(
`extendr-api` = extendr_api_version
),
`profile.release` = list(
lto = TRUE,
`codegen-units` = 1
Expand Down
24 changes: 22 additions & 2 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,27 @@
)
}

# fetch most recent stable release version instead of setting it to "*"
# fall back to "*" when internet or API fails
extendr_api_version <- suppressWarnings(
rlang::try_fetch(
{
res <- jsonlite::read_json(
"https://crates.io/api/v1/crates/extendr-api"
)[[c("crate", "max_stable_version")]]

if (is.null(res)) {
"*"
} else {
res
}
},
error = function(cnd) {
"*"
}
)
)

# Setting default options
# If rextendr options are already set, do not override
# NULL values are present for reference and may later be replaced
Expand All @@ -25,14 +46,13 @@

# Version of 'extendr_api' to be used
rextendr.extendr_deps = list(
`extendr-api` = "*"
`extendr-api` = extendr_api_version
),
rextendr.extendr_dev_deps = list(
`extendr-api` = list(git = "https://github.com/extendr/extendr")
)
)


id_opts_to_set <- !(names(rextendr_opts) %in% names(options()))

options(rextendr_opts[id_opts_to_set])
Expand Down
12 changes: 11 additions & 1 deletion tests/testthat/setup.R
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
withr::local_options(usethis.quiet = TRUE, .local_envir = teardown_env())
withr::local_options(
usethis.quiet = TRUE,
.local_envir = teardown_env()
)

# use "*" as version for CI and tests
options(
"rextendr.extendr_deps" = list(
`extendr-api` = "*"
)
)
26 changes: 21 additions & 5 deletions tests/testthat/test-use_extendr.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,19 @@ test_that("use_extendr() sets up extendr files correctly", {
use_extendr()

# DESCRITION file
version_in_desc <- stringi::stri_trim_both(desc::desc_get("Config/rextendr/version", path)[[1]])
sysreq_in_desc <- stringi::stri_trim_both(desc::desc_get("SystemRequirements", path)[[1]])
version_in_desc <- stringi::stri_trim_both(desc::desc_get(
"Config/rextendr/version",
path
)[[1]])
sysreq_in_desc <- stringi::stri_trim_both(desc::desc_get(
"SystemRequirements",
path
)[[1]])
expect_identical(version_in_desc, as.character(packageVersion("rextendr")))
expect_identical(sysreq_in_desc, "Cargo (Rust's package manager), rustc")
expect_identical(
sysreq_in_desc,
"Cargo (Rust's package manager), rustc >= 1.65.0, xz"
)

# directory structure
expect_true(dir.exists("src"))
Expand Down Expand Up @@ -60,7 +69,11 @@ test_that("use_extendr() can overwrite files in non-interactive sessions", {
path <- local_package("testpkg")
use_extendr()
withr::local_options(usethis.quiet = FALSE)
expect_snapshot(use_extendr(crate_name = "foo", lib_name = "bar", overwrite = TRUE))
expect_snapshot(use_extendr(
crate_name = "foo",
lib_name = "bar",
overwrite = TRUE
))
expect_snapshot(cat_file("src", "rust", "Cargo.toml"))
})

Expand Down Expand Up @@ -91,7 +104,10 @@ test_that("use_rextendr_template() works when usethis not available", {
is_installed = function(...) FALSE
)

expect_identical(brio::read_file(file.path("installed")), brio::read_file(file.path("not_installed")))
expect_identical(
brio::read_file(file.path("installed")),
brio::read_file(file.path("not_installed"))
)
})

test_that("use_rextendr_template() can overwrite existing files", {
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-use_msrv.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ test_that("use_msrv() modifies the MSRV in the DESCRIPTION", {
withr::local_options(usethis.quiet = FALSE)

use_extendr(path, quiet = TRUE)
expect_no_error(use_msrv("1.70", path))
expect_no_error(use_msrv("1.70", path, TRUE))

d <- desc::desc("DESCRIPTION")

Expand All @@ -16,9 +16,9 @@ test_that("use_msrv() modifies the MSRV in the DESCRIPTION", {
d$get_field("SystemRequirements")
)

expect_error(use_msrv("adksfghu", path))
expect_error(use_msrv("adksfghu", path, TRUE))

expect_error(use_msrv("1.70", path = "../doesntexist"))
expect_error(use_msrv("1.70", path = "../doesntexist", TRUE))

# when overwrite is FALSE and SystemRequirements is already set
expect_message(
Expand Down
Loading