Skip to content

Commit

Permalink
use R based configure and MSRV check and add new CI tests from fio fo…
Browse files Browse the repository at this point in the history
…r fedora checks
  • Loading branch information
JosiahParry committed Aug 31, 2024
1 parent 503097b commit 3c34c83
Show file tree
Hide file tree
Showing 7 changed files with 185 additions and 34 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/cran-fedora-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# https://github.com/albersonmiranda/fio/blob/dev/.github/workflows/Rust-fail-check.yaml
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
workflow_dispatch:


name: Rust-check

permissions: read-all

jobs:
no-install:
runs-on: ubuntu-latest
container:
image: fedora:40

steps:
- uses: actions/checkout@v4

- name: Install Fedora dependencies
run: |
sudo dnf install -y libxml2-devel libcurl-devel harfbuzz-devel fribidi-devel openssl-devel freetype-devel libpng-devel libtiff-devel libjpeg-devel qpdf xz devscripts glibc-langpack-en pandoc
- name: Setup R
run: |
sudo dnf install -y R
# install R packages
R -e 'install.packages(c("remotes", "rcmdcheck", "emoji", "Rdpack", "readxl", "clipr", "fs", "miniUI", "shiny", "knitr", "rmarkdown", "spelling", "microbenchmark", "leontief", "ggplot2", "writexl", "testthat"), repos = "http://cloud.r-project.org")'
- name: Build package
run: |
R CMD build .
msrv-lower:
runs-on: ubuntu-latest
container:
image: fedora:40

steps:
- uses: actions/checkout@v4

- name: Install Fedora dependencies
run: |
sudo dnf install -y libxml2-devel libcurl-devel harfbuzz-devel fribidi-devel openssl-devel freetype-devel libpng-devel libtiff-devel libjpeg-devel qpdf xz devscripts glibc-langpack-en pandoc
- name: Install and set Rust toolchain to 1.66.0
run: |
# download and install rust
curl https://sh.rustup.rs -sSf | sh -s -- -y
# add cargo to PATH
. "$HOME/.cargo/env"
# set default toolchain
rustup default 1.66
- name: Setup R
run: |
sudo dnf install -y R
# install R packages
R -e 'install.packages(c("remotes", "rcmdcheck", "emoji", "Rdpack", "readxl", "clipr", "fs", "miniUI", "shiny", "knitr", "rmarkdown", "spelling", "microbenchmark", "leontief", "ggplot2", "writexl", "testthat"), repos = "http://cloud.r-project.org")'
- name: Build package
run: |
R CMD build .
3 changes: 0 additions & 3 deletions CRAN-SUBMISSION

This file was deleted.

2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Language: en
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
Config/rextendr/version: 0.3.1.9000
SystemRequirements: Cargo (Rust's package manager), rustc
SystemRequirements: Cargo (Rust's package manager), rustc >= 1.69
Suggests:
httr2,
sf,
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# arcpbf 0.1.5

* Addresses CRAN removal for failing to compile on Fedora.

# arcpbf 0.1.4

* Addresses MSRV requirement by replacing `std::cell::OnceCell` with `once_cell::sync::OnceCell`
Expand Down
18 changes: 3 additions & 15 deletions configure
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
#!/bin/sh

# https://github.com/eitsupi/prqlr/blob/main/configure.win
export PATH="$PATH:$HOME/.cargo/bin"

if [ ! "$(command -v cargo)" ]; then
echo "----------------------- [RUST NOT FOUND]---------------------------"
echo "The 'cargo' command was not found on the PATH. Please install rustc"
echo "from: https://www.rust-lang.org/tools/install"
echo "-------------------------------------------------------------------"
echo ""
exit 1
fi

exit 0
#!/usr/bin/env sh
: "${R_HOME=`R RHOME`}"
"${R_HOME}/bin/Rscript" tools/msrv.R
17 changes: 2 additions & 15 deletions configure.win
Original file line number Diff line number Diff line change
@@ -1,15 +1,2 @@
#!/bin/sh

# https://github.com/eitsupi/prqlr/blob/main/configure.win
export PATH="$PATH:$HOME/.cargo/bin"

if [ ! "$(command -v cargo)" ]; then
echo "----------------------- [RUST NOT FOUND]---------------------------"
echo "The 'cargo' command was not found on the PATH. Please install rustc"
echo "from: https://www.rust-lang.org/tools/install"
echo "-------------------------------------------------------------------"
echo ""
exit 1
fi

exit 0
#!/usr/bin/env sh
"${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" tools/msrv.R
116 changes: 116 additions & 0 deletions tools/msrv.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# read the DESCRIPTION file
desc <- read.dcf("DESCRIPTION")

if (!"SystemRequirements" %in% colnames(desc)) {
fmt <- c(
"`SystemRequirements` not found in `DESCRIPTION`.",
"Please specify `SystemRequirements: Cargo (Rust's package manager), rustc`"
)
stop(paste(fmt, collapse = "\n"))
}

# extract system requirements
sysreqs <- desc[, "SystemRequirements"]

# check that cargo and rustc is found
if (!grepl("cargo", sysreqs, ignore.case = TRUE)) {
stop("You must specify `Cargo (Rust's package manager)` in your `SystemRequirements`")
}

if (!grepl("rustc", sysreqs, ignore.case = TRUE)) {
stop("You must specify `Cargo (Rust's package manager), rustc` in your `SystemRequirements`")
}

# split into parts
parts <- strsplit(sysreqs, ", ")[[1]]

# identify which is the rustc
rustc_ver <- parts[grepl("rustc", parts)]

# perform checks for the presence of rustc and cargo on the OS
no_cargo_msg <- c(
"----------------------- [CARGO NOT FOUND]--------------------------",
"The 'cargo' command was not found on the PATH. Please install Cargo",
"from: https://www.rust-lang.org/tools/install",
"",
"Alternatively, you may install Cargo from your OS package manager:",
" - Debian/Ubuntu: apt-get install cargo",
" - Fedora/CentOS: dnf install cargo",
" - macOS: brew install rustc",
"-------------------------------------------------------------------"
)

no_rustc_msg <- c(
"----------------------- [RUST NOT FOUND]---------------------------",
"The 'rustc' compiler was not found on the PATH. Please install",
paste(rustc_ver, "or higher from:"),
"https://www.rust-lang.org/tools/install",
"",
"Alternatively, you may install Rust from your OS package manager:",
" - Debian/Ubuntu: apt-get install rustc",
" - Fedora/CentOS: dnf install rustc",
" - macOS: brew install rustc",
"-------------------------------------------------------------------"
)

# Add {user}/.cargo/bin to path before checking
new_path <- paste0(
Sys.getenv("PATH"),
":",
paste0(Sys.getenv("HOME"), "/.cargo/bin")
)

# set the path with the new path
Sys.setenv("PATH" = new_path)

# check for rustc installation
rustc_version <- tryCatch(
system("rustc --version", intern = TRUE),
error = function(e) {
stop(paste(no_rustc_msg, collapse = "\n"))
}
)

# check for cargo installation
cargo_version <- tryCatch(
system("cargo --version", intern = TRUE),
error = function(e) {
stop(paste(no_cargo_msg, collapse = "\n"))
}
)

# helper function to extract versions
extract_semver <- function(ver) {
if (grepl("\\d+\\.\\d+(\\.\\d+)?", ver)) {
sub(".*?(\\d+\\.\\d+(\\.\\d+)?).*", "\\1", ver)
} else {
NA
}
}

# get the MSRV
msrv <- extract_semver(rustc_ver)

# extract current version
current_rust_version <- extract_semver(rustc_version)

# perform check
if (!is.na(msrv)) {
# -1 when current version is later
# 0 when they are the same
# 1 when MSRV is newer than current
is_msrv <- utils::compareVersion(msrv, current_rust_version)
if (is_msrv == 1) {
fmt <- paste0(
"\n------------------ [UNSUPPORTED RUST VERSION]------------------\n",
"- Minimum supported Rust version is %s.\n",
"- Installed Rust version is %s.\n",
"---------------------------------------------------------------"
)
stop(sprintf(fmt, msrv, current_rust_version))
}
}

# print the versions
versions_fmt <- "Using %s\nUsing %s"
message(sprintf(versions_fmt, cargo_version, rustc_version))

0 comments on commit 3c34c83

Please sign in to comment.