Skip to content

Commit

Permalink
feat(installation): download lib binaries (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
eitsupi committed Sep 30, 2023
1 parent d220b0b commit 97fa7ce
Show file tree
Hide file tree
Showing 14 changed files with 317 additions and 16 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
^\.task$
^src/\.cargo$
^src/rust/vendor$
^src/Makevars$
^tools/libprqlr\.a$
68 changes: 63 additions & 5 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

defaults:
run:
shell: bash

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}
Expand All @@ -41,15 +45,16 @@ jobs:
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'}
- { 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
LIBPRQLR_BUILD: "true"

steps:
- uses: actions/checkout@v4
Expand All @@ -72,3 +77,56 @@ jobs:
- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true

source-with-bin-check:
runs-on: ${{ matrix.os }}

name: ${{ matrix.os }} with pre-built binary (${{ matrix.r }})

strategy:
fail-fast: false
matrix:
os:
- macos-latest
- windows-latest
- ubuntu-latest
r:
- release

env:
NOT_CRAN: "true"
LIB_SUMS_PATH: "tools/lib-sums.tsv"

steps:
- uses: actions/checkout@v4

- name: Check for pre-built binary
run: |
if [[ -f "${LIB_SUMS_PATH}" ]]; then
echo "TEST_BIN_LIB=true" >>"${GITHUB_ENV}"
rm -f "$(rustup which cargo)"
else
echo "TEST_BIN_LIB=false" >>"${GITHUB_ENV}"
fi
- uses: r-lib/actions/setup-pandoc@v2
if: env.TEST_BIN_LIB == 'true'

- uses: r-lib/actions/setup-r@v2
if: env.TEST_BIN_LIB == 'true'
with:
r-version: ${{ matrix.r }}
use-public-rspm: true
Ncpus: "2"

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

- name: Install with pre-built binary
if: env.TEST_BIN_LIB == 'true'
shell: Rscript {0}
run: |
remotes::install_local()
devtools::test()
2 changes: 1 addition & 1 deletion .github/workflows/release-lib.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
run: |
LIB_PATH="$(pwd)/rust/target/${TARGET}/${PRQLR_PROFILE}/${LIB_NAME}.a"
ARTIFACT_NAME="${LIB_NAME}-${LIB_VERSION}-${TARGET}.tar.gz"
make -f Makevars${{ runner.os == 'Windows' && '.win' || '' }} "${LIB_PATH}"
make -f Makevars${{ runner.os == 'Windows' && '.win' || '.in' }} "${LIB_PATH}"
tar -czf "../${ARTIFACT_NAME}" -C "rust/target/${TARGET}/${PRQLR_PROFILE}" "${LIB_NAME}.a"
echo "ARTIFACT_NAME=${ARTIFACT_NAME}" >>"$GITHUB_ENV"
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ docs

src/rust/vendor
src/rust/vendor.tar.xz
src/Makevars
tools/libprqlr.a
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Language: en-US
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
SystemRequirements: GNU make, Cargo (Rust's package manager), rustc
SystemRequirements: Cargo (Rust's package manager), rustc
VignetteBuilder: knitr
Config/testthat/edition: 3
Config/rextendr/version: 0.3.1
Expand All @@ -45,3 +45,4 @@ Config/Needs/dev:
Config/Needs/website:
pkgdown,
rextendr
Config/prqlr/LibVersion: 0.9.0
18 changes: 16 additions & 2 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
version: "3"

env:
NOT_CRAN: true
NOT_CRAN: "true"
LIBPRQLR_BUILD: "true"

vars:
MANIFEST: src/rust/Cargo.toml
Expand Down Expand Up @@ -53,9 +54,22 @@ tasks:
cmds:
- Rscript dev/vendoring.R

build-lib-sums:
desc: Build lib-sums.tsv.
sources:
- dev/generate-lib-sums.R
- DESCRIPTION
- "{{.CARGO_LOCK}}"
generates:
- tools/lib-sums.tsv
- tools/prep-lib.R
cmds:
- Rscript dev/generate-lib-sums.R

build-all:
desc: Build the R package, generate documents, run all tests, and update files.
deps:
- build-lib-sums
- build-documents
cmds:
- task: test-all
Expand Down Expand Up @@ -118,7 +132,7 @@ tasks:
- Rscript -e
'devtools::load_all();
list.files("vignettes/", pattern = r"(\.Rmd$)", recursive = TRUE, full.names = TRUE) |>
purrr::walk(\(x) rmarkdown::render(x, output_dir = tempdir()))'
purrr::walk(\(x) rmarkdown::render(x, output_dir = tempdir()))'

build-documents:
desc: Build the R package and generate documents.
Expand Down
3 changes: 3 additions & 0 deletions cleanup
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env sh

rm -f src/Makevars
50 changes: 48 additions & 2 deletions configure
Original file line number Diff line number Diff line change
@@ -1,23 +1,69 @@
#!/usr/bin/env sh

NOT_CRAN=${NOT_CRAN:-"false"}
LIBPRQLR_BUILD=${LIBPRQLR_BUILD:-""}

LIBNAME="libprqlr.a"
LIBPRQLR_PATH="tools/${LIBNAME}"

export PATH="$PATH:$HOME/.cargo/bin"

check_cargo() {
if [ ! "$(command -v cargo)" ]; then
echo "----------------------- [RUST NOT FOUND]---------------------------"
echo ""
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 "--------------------------------------------------------------------"
echo ""
exit 1
else
echo ""
echo "--------------------------- [RUST FOUND] ---------------------------"
"$(cargo -V)"
echo ""
"$(rustc -vV)"
echo "--------------------------------------------------------------------"
echo ""
fi
}

check_bin_lib() {
if [ "${NOT_CRAN}" = "true" ] && [ -z "${LIBPRQLR_BUILD}" ]; then
LIBPRQLR_BUILD="false"
fi

if [ "${LIBPRQLR_BUILD}" = "false" ] && [ -f "tools/lib-sums.tsv" ] && [ ! -f "${LIBPRQLR_PATH}" ] ; then
echo "Try to download pre-built binary..."
LIBPRQLR_PATH="tools/${LIBNAME}"
Rscript "tools/prep-lib.R" || echo "Failed to download pre-built binary..."
fi

if [ "${LIBPRQLR_BUILD}" = "false" ] && [ -f "${LIBPRQLR_PATH}" ]; then
echo ""
echo "------------------------- [LIBRARY FOUND] -------------------------"
echo "The library was found at <${LIBPRQLR_PATH}>. No need to build it."
echo "-------------------------------------------------------------------"
echo ""
sed -e "s|@RUST_TARGET@||" src/Makevars.in >src/Makevars
exit 0
elif [ "${LIBPRQLR_BUILD}" = "false" ]; then
echo ""
echo "----------------------- [LIBRARY NOT FOUND] -----------------------"
echo "The library was not found at <${LIBPRQLR_PATH}>."
echo "-------------------------------------------------------------------"
echo ""
fi
}

check_bin_lib
check_cargo

sed -e "s|@RUST_TARGET@|$(rustc -vV | grep host | cut -d' ' -f2)|" src/Makevars.in >src/Makevars

exit 0
48 changes: 46 additions & 2 deletions configure.win
Original file line number Diff line number Diff line change
@@ -1,18 +1,62 @@
#!/bin/sh

NOT_CRAN=${NOT_CRAN:-"false"}
LIBPRQLR_BUILD=${LIBPRQLR_BUILD:-""}

LIBNAME="libprqlr.a"
LIBPRQLR_PATH="tools/${LIBNAME}"

export PATH="$PATH:$HOME/.cargo/bin"

check_cargo() {
if [ ! "$(command -v cargo)" ]; then
echo "----------------------- [RUST NOT FOUND]---------------------------"
echo ""
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 "--------------------------------------------------------------------"
echo ""
exit 1
else
echo ""
echo "--------------------------- [RUST FOUND] ---------------------------"
"$(cargo -V)"
echo ""
"$(rustc -vV)"
echo "--------------------------------------------------------------------"
echo ""
fi
}

check_bin_lib() {
if [ "${NOT_CRAN}" = "true" ] && [ -z "${LIBPRQLR_BUILD}" ]; then
LIBPRQLR_BUILD="false"
fi

if [ "${LIBPRQLR_BUILD}" = "false" ] && [ -f "tools/lib-sums.tsv" ] && [ ! -f "${LIBPRQLR_PATH}" ] ; then
echo "Try to download pre-built binary..."
LIBPRQLR_PATH="tools/${LIBNAME}"
Rscript "tools/prep-lib.R" || echo "Failed to download pre-built binary..."
fi

if [ "${LIBPRQLR_BUILD}" = "false" ] && [ -f "${LIBPRQLR_PATH}" ]; then
echo ""
echo "------------------------- [LIBRARY FOUND] -------------------------"
echo "The library was found at <${LIBPRQLR_PATH}>. No need to build it."
echo "-------------------------------------------------------------------"
echo ""
sed -e "s|@RUST_TARGET@||" src/Makevars.in >src/Makevars
exit 0
elif [ "${LIBPRQLR_BUILD}" = "false" ]; then
echo ""
echo "----------------------- [LIBRARY NOT FOUND] -----------------------"
echo "The library was not found at <${LIBPRQLR_PATH}>."
echo "-------------------------------------------------------------------"
echo ""
fi
}

check_bin_lib
check_cargo

exit 0
40 changes: 40 additions & 0 deletions dev/generate-lib-sums.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
base_url <- "https://github.com/eitsupi/prqlr/releases/download/"

tag_prefix <- "lib-v"

lib_data_file_path <- file.path("tools", "lib-sums.tsv")

package_name <- desc::desc_get("Package")
current_lib_version <- RcppTOML::parseTOML("src/rust/Cargo.toml")$package$version

latest_released_lib_version <- gert::git_remote_ls(remote = "https://github.com/eitsupi/prqlr/") |>
dplyr::pull(ref) |>
stringr::str_subset(stringr::str_c(r"(^refs/tags/)", tag_prefix)) |>
stringr::str_remove(stringr::str_c(".*", tag_prefix)) |>
sort(decreasing = TRUE) |>
_[1]

write_bin_lib_data <- function(path, sums_url, libs_base_url) {
df <- readr::read_table(sums_url, col_names = FALSE, show_col_types = FALSE) |>
dplyr::mutate(
url = glue::glue("{libs_base_url}{X2}"),
sha256sum = X1,
.keep = "none"
)

readr::write_tsv(df, path)
}

desc::desc_set(paste0("Config/", package_name, "/LibVersion"), current_lib_version)

if (identical(current_lib_version, latest_released_lib_version)) {
message("Current lib version is available via the binary release.")
write_bin_lib_data(
lib_data_file_path,
glue::glue("{base_url}{tag_prefix }{latest_released_lib_version}/sha256sums.txt"),
glue::glue("{base_url}{tag_prefix }{latest_released_lib_version}/")
)
} else {
message("Current lib version is not available via binary releases.")
if (fs::file_exists(lib_data_file_path)) fs::file_delete(lib_data_file_path)
}
4 changes: 2 additions & 2 deletions src/Makevars → src/Makevars.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
TARGET ?= $(shell export PATH="$(PATH):$(HOME)/.cargo/bin" && rustc -vV | grep host | cut -d" " -f2)
TARGET ?= @RUST_TARGET@
PRQLR_PROFILE ?= release
PRQLR_FEATURES ?=

Expand Down Expand Up @@ -43,4 +43,4 @@ C_clean:
rm -Rf "$(SHLIB)" "$(STATLIB)" "$(OBJECTS)"

clean:
rm -Rf "$(SHLIB)" "$(STATLIB)" "$(OBJECTS)" "$(CURDIR)/rust/target"
rm -Rf "$(SHLIB)" "$(STATLIB)" "$(OBJECTS)" "$(TARGET_DIR)"
2 changes: 1 addition & 1 deletion src/Makevars.win
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ C_clean:
rm -Rf "$(SHLIB)" "$(STATLIB)" "$(OBJECTS)"

clean:
rm -Rf "$(SHLIB)" "$(STATLIB)" "$(OBJECTS)" "$(CURDIR)/rust/target"
rm -Rf "$(SHLIB)" "$(STATLIB)" "$(OBJECTS)" "$(TARGET_DIR)"
6 changes: 6 additions & 0 deletions tools/lib-sums.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
url sha256sum
https://github.com/eitsupi/prqlr/releases/download/lib-v0.9.0/libprqlr-0.9.0-aarch64-apple-darwin.tar.gz 882ffcc187e225d44d17c1c3bdcac3c27e7fa3b9577a26a4ab2f74677e87f0e8
https://github.com/eitsupi/prqlr/releases/download/lib-v0.9.0/libprqlr-0.9.0-aarch64-unknown-linux-musl.tar.gz e91a0e3db7a60e8b6b61f55dd061ec1d0429e82e749e0ce16a8af8830fa55eec
https://github.com/eitsupi/prqlr/releases/download/lib-v0.9.0/libprqlr-0.9.0-x86_64-apple-darwin.tar.gz de46cb2e1a68dfca1a6a40116d176cdb850b0c63de0d8495b4453a1099dfcde1
https://github.com/eitsupi/prqlr/releases/download/lib-v0.9.0/libprqlr-0.9.0-x86_64-pc-windows-gnu.tar.gz 4170bd99c98bc1b39610bdadeccc60a69e5aeaf00f348d2e760da19cb188dbe8
https://github.com/eitsupi/prqlr/releases/download/lib-v0.9.0/libprqlr-0.9.0-x86_64-unknown-linux-musl.tar.gz 3a9fcdae0b4fdd42bc2e12476b44471c1704a6702770d0dd4e85dee7df38972f
Loading

0 comments on commit 97fa7ce

Please sign in to comment.