Skip to content

Commit

Permalink
add cran compliance / vendor and add gha
Browse files Browse the repository at this point in the history
  • Loading branch information
JosiahParry committed Jan 13, 2024
1 parent 26549e3 commit 637cbba
Show file tree
Hide file tree
Showing 19 changed files with 170 additions and 20 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
^src/\.cargo$
^README\.Rmd$
^LICENSE\.md$
^src/rust/vendor$
^\.github$
1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.html
49 changes: 49 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# 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:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: R-CMD-check

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
needs: check

- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.Rproj.user
src/rust/vendor
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export(decode_file)
export(encode)
export(encode_file)
export(engine)
export(new_alphabet)
export(new_config)
export(new_engine)
importFrom(blob,blob)
Expand Down
1 change: 1 addition & 0 deletions R/alphabet.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ alphabet <- function(which = "standard") {
structure(alphabet_(which), class = "alphabet")
}

#' @export
#' @rdname alphabet
new_alphabet <- function(chars) {
n <- nchar(chars)
Expand Down
7 changes: 3 additions & 4 deletions R/config.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
#' @param decode_padding_mode default `"canonical"`. Other values are `"indifferent"` and `"none"`. See details for more.
#' @export
#' @return an object of class `engine_config`
#' @examples
#' # create a new nonsensicle config
#' new_config(FALSE, TRUE, "none")
new_config <- function(
encode_padding = TRUE,
decode_padding_trailing_bits = FALSE,
Expand All @@ -38,14 +41,10 @@ new_config <- function(
structure(res, class = "engine_config")
}

# shoddy print method for the time being

#' @export
print.engine_config <- function(x, ...) {
y <- print_config_(x)
# z <- trimws(strsplit(y, "\n")[[1]][2:4])
cat("<engine_config>\n")
# cat(gsub(",", "", z), sep = "\n")
invisible(x)
}

Expand Down
11 changes: 11 additions & 0 deletions R/encode.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@
#' and blob vector the same length as `what`, respectively.
#' @export
#' @name encode
#' @examples
#' # encode hello world
#' encoded <- encode("Hello world")
#' encoded
#'
#' # decode to a blob
#' decoded <- decode(encoded)
#' decoded
#'
#' # convert back to a character
#' rawToChar(decoded[[1]])
encode <- function(what, eng = engine()) {
n <- length(what)
if (inherits(what, "raw") || (n == 1 & inherits(what, "character"))) {
Expand Down
5 changes: 4 additions & 1 deletion R/engine.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
#'
#' @param which default `"standard"`. The base64 encoding engine to be used.
#' See details for more.
#' @param .alphabet an object of class `alphabet` as created with [`alphabet()`] or [`new_alphabet()`]
#' @param .alphabet an object of class `alphabet` as created with
#' [`alphabet()`] or [`new_alphabet()`]
#' @param .config an object of class `engine_config` as created with
#' [new_config()]
#' @details
#'
#' ## Engines
Expand Down
1 change: 1 addition & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ knitr::opts_chunk$set(
# b64

<!-- badges: start -->
[![R-CMD-check](https://github.com/extendr/b64/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/extendr/b64/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->

The goal of b64 is to provide a very fast, lightweight, and vectorized base64 encoder and decoder.
Expand Down
20 changes: 20 additions & 0 deletions configure
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env sh

# https://github.com/eitsupi/prqlr/blob/main/configure
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 "Alternatively, you may install cargo from your OS package manager:"
echo " - Debian/Ubuntu: apt-get install cargo"
echo " - Fedora/CentOS: dnf install cargo"
echo " - macOS: brew install rustc"
echo "-------------------------------------------------------------------"
echo ""
exit 1
fi

exit 0
15 changes: 15 additions & 0 deletions configure.win
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/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
12 changes: 12 additions & 0 deletions man/encode.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion man/engine.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions man/new_config.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 13 additions & 7 deletions src/Makevars
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,30 @@ all: C_clean

$(SHLIB): $(STATLIB)

CRAN_FLAGS=-j 2 --offline
CARGOTMP = $(CURDIR)/.cargo
VENDOR_DIR = $(CURDIR)/vendor

$(STATLIB):
if [ -f ./rust/vendor.tar.xz ]; then \
tar xf rust/vendor.tar.xz && \
mkdir -p $(CARGOTMP) && \
cp rust/vendor-config.toml $(CARGOTMP)/config.toml; \
fi

# In some environments, ~/.cargo/bin might not be included in PATH, so we need
# to set it here to ensure cargo can be invoked. It is appended to PATH and
# therefore is only used if cargo is absent from the user's PATH.
if [ "$(NOT_CRAN)" != "true" ]; then \
export CARGO_HOME=$(CARGOTMP); \
fi && \
export PATH="$(PATH):$(HOME)/.cargo/bin" && \
cargo build --lib --release --manifest-path=./rust/Cargo.toml --target-dir $(TARGET_DIR)
if [ "$(NOT_CRAN)" != "true" ]; then \
rm -Rf $(CARGOTMP) && \
rm -Rf $(LIBDIR)/build; \
fi
cargo build $(CRAN_FLAGS) --lib --release --manifest-path=./rust/Cargo.toml --target-dir $(TARGET_DIR) && \
echo `cargo --version` && echo `rustc --version`;
rm -Rf $(CARGOTMP) $(VENDOR_DIR) $(LIBDIR)/build; \

C_clean:
rm -Rf $(SHLIB) $(STATLIB) $(OBJECTS)
rm -Rf $(SHLIB) $(STATLIB) $(OBJECTS) $(CARGOTMP) $(VENDOR_DIR)

clean:
rm -Rf $(SHLIB) $(STATLIB) $(OBJECTS) rust/target
rm -Rf $(SHLIB) $(STATLIB) $(OBJECTS) $(CARGOTMP) $(VENDOR_DIR) $(TARGET_DIR)
29 changes: 22 additions & 7 deletions src/Makevars.win
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,29 @@ all: C_clean

$(SHLIB): $(STATLIB)

CRAN_FLAGS=-j 2 --offline
CARGOTMP = $(CURDIR)/.cargo
VENDOR_DIR = $(CURDIR)/vendor

all: C_clean

$(SHLIB): $(STATLIB)

CRAN_FLAGS=-j 2 --offline
CARGOTMP = $(CURDIR)/.cargo

$(STATLIB):
# uncompress vendored deps
if [ -f ./rust/vendor.tar.xz ]; then \
tar xf rust/vendor.tar.xz && \
mkdir -p $(CARGOTMP) && \
cp rust/vendor-config.toml $(CARGOTMP)/config.toml; \
fi

mkdir -p $(TARGET_DIR)/libgcc_mock
# `rustc` adds `-lgcc_eh` flags to the compiler, but Rtools' GCC doesn't have
# `libgcc_eh` due to the compilation settings. So, in order to please the
# compiler, we need to add empty `libgcc_eh` to the library search paths.
#
# For more details, please refer to
# https://github.com/r-windows/rtools-packages/blob/2407b23f1e0925bbb20a4162c963600105236318/mingw-w64-gcc/PKGBUILD#L313-L316
touch $(TARGET_DIR)/libgcc_mock/libgcc_eh.a
Expand All @@ -26,15 +41,15 @@ $(STATLIB):
export CARGO_HOME=$(CARGOTMP); \
fi && \
export CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER="$(CARGO_LINKER)" && \
export LIBRARY_PATH="$${LIBRARY_PATH};$(CURDIR)/$(TARGET_DIR)/libgcc_mock" && \
cargo build --target=$(TARGET) --lib --release --manifest-path=./rust/Cargo.toml --target-dir $(TARGET_DIR)
export LIBRARY_PATH="$${LIBRARY_PATH};$(CURDIR)/$(TARGET_DIR)/libgcc_mock"; \
cargo build $(CRAN_FLAGS) --target=$(TARGET) --lib --release --manifest-path=./rust/Cargo.toml --target-dir $(TARGET_DIR) && \
echo `cargo --version` && echo `rustc --version`;
if [ "$(NOT_CRAN)" != "true" ]; then \
rm -Rf $(CARGOTMP) && \
rm -Rf $(LIBDIR)/build; \
rm -Rf $(CARGOTMP) $(VENDOR_DIR) $(LIBDIR)/build; \
fi

C_clean:
rm -Rf $(SHLIB) $(STATLIB) $(OBJECTS)
rm -Rf $(SHLIB) $(STATLIB) $(OBJECTS) $(CARGOTMP) $(VENDOR_DIR)

clean:
rm -Rf $(SHLIB) $(STATLIB) $(OBJECTS) $(TARGET_DIR)
rm -Rf $(SHLIB) $(STATLIB) $(OBJECTS) $(CARGOTMP) $(VENDOR_DIR) $(TARGET_DIR)
5 changes: 5 additions & 0 deletions src/rust/vendor-config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[source.crates-io]
replace-with = "vendored-sources"

[source.vendored-sources]
directory = "vendor"
Binary file added src/rust/vendor.tar.xz
Binary file not shown.

0 comments on commit 637cbba

Please sign in to comment.