Skip to content

Commit 3fdde2e

Browse files
committed
Add ncurl, allow setting NANONEXT_TLS, update CI
1 parent 954519d commit 3fdde2e

File tree

13 files changed

+345
-81
lines changed

13 files changed

+345
-81
lines changed

.github/workflows/check-standard.yaml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Workflow derived from https://github.com/r-lib/actions/tree/master/examples
1+
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
22
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
33
on:
44
push:
@@ -31,16 +31,17 @@ jobs:
3131
steps:
3232
- uses: actions/checkout@v2
3333

34-
- uses: r-lib/actions/setup-pandoc@v1
34+
- uses: r-lib/actions/setup-pandoc@v2
3535

36-
- uses: r-lib/actions/setup-r@v1
36+
- uses: r-lib/actions/setup-r@v2
3737
with:
3838
r-version: ${{ matrix.config.r }}
3939
http-user-agent: ${{ matrix.config.http-user-agent }}
4040
use-public-rspm: true
4141

42-
- uses: r-lib/actions/setup-r-dependencies@v1
42+
- uses: r-lib/actions/setup-r-dependencies@v2
4343
with:
44-
extra-packages: rcmdcheck
44+
extra-packages: any::rcmdcheck
45+
needs: check
4546

46-
- uses: r-lib/actions/check-r-package@v1
47+
- uses: r-lib/actions/check-r-package@v2

.github/workflows/pkgdown.yaml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
# Workflow derived from https://github.com/r-lib/actions/tree/master/examples
1+
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
22
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
33
on:
44
push:
55
branches: [main]
6+
pull_request:
7+
branches: [main]
68
release:
79
types: [published]
810
workflow_dispatch:
@@ -17,19 +19,25 @@ jobs:
1719
steps:
1820
- uses: actions/checkout@v2
1921

20-
- uses: r-lib/actions/setup-pandoc@v1
22+
- uses: r-lib/actions/setup-pandoc@v2
2123

22-
- uses: r-lib/actions/setup-r@v1
24+
- uses: r-lib/actions/setup-r@v2
2325
with:
2426
use-public-rspm: true
2527

26-
- uses: r-lib/actions/setup-r-dependencies@v1
28+
- uses: r-lib/actions/setup-r-dependencies@v2
2729
with:
28-
extra-packages: pkgdown
30+
extra-packages: any::pkgdown, local::.
2931
needs: website
3032

3133
- name: Deploy package
34+
if: github.event_name != 'pull_request'
3235
run: |
3336
git config --local user.name "$GITHUB_ACTOR"
3437
git config --local user.email "[email protected]"
3538
Rscript -e 'pkgdown::deploy_to_branch(new_process = FALSE)'
39+
40+
- name: Build site without deploying
41+
if: github.event_name == 'pull_request'
42+
run: |
43+
Rscript -e 'pkgdown::build_site(preview = FALSE, install = FALSE)'

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export(ctx_send_vec)
2727
export(dial)
2828
export(listen)
2929
export(nano)
30+
export(ncurl)
3031
export(nng_error)
3132
export(nng_version)
3233
export(recv)

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# nanonext 0.1.0.9000 (under development)
22

3+
* Add `ncurl()` minimalistic http(s) client.
4+
* Allow setting the environment variable 'NANONEXT_TLS=1' prior to package installation to enable TLS where the system NNG library has been built with TLS support (using Mbed TLS).
5+
36
# nanonext 0.1.0
47

58
* Initial release to CRAN, rOpenSci R-universe and Github.

R/utils.R

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,16 @@
22

33
#' NNG Library Version
44
#'
5-
#' Returns the version of 'libnng' used.
5+
#' Returns the version of 'libnng' used and whether TLS is supported.
66
#'
7-
#' @return A character vector.
7+
#' @return A character vector of length 2.
8+
#'
9+
#' @section TLS Support:
10+
#'
11+
#' The environment variable 'NANONEXT_TLS=1' may be set, e.g. by using
12+
#' \code{Sys.setenv(NANONEXT_TLS=1)}, prior to package installation to enable
13+
#' TLS where the system NNG library has been built with TLS support (using
14+
#' Mbed TLS). Note: this is not applicable to Windows systems.
815
#'
916
#' @examples
1017
#' nng_version()
@@ -38,3 +45,41 @@ nng_error <- function(error) {
3845

3946
}
4047

48+
#' ncurl
49+
#'
50+
#' nano cURL - a minimalistic http(s) client.
51+
#'
52+
#' @param http the URL/address of the resource to retrieve.
53+
#'
54+
#' @return Named list of 2 elements: 'raw' containing a raw vector of the received
55+
#' resource and 'data', the raw vector converted to a character string.
56+
#'
57+
#' @details Only performs HTTP GET operations, and does not follow HTTP redirects.
58+
#'
59+
#' The raw vector may be saved to a file using \code{\link{writeBin}} to
60+
#' re-create the original resource.
61+
#'
62+
#' The data vector is a character string allowing further parsing within R,
63+
#' as HTML, JSON etc.
64+
#'
65+
#' @section TLS Support:
66+
#'
67+
#' Connecting to secure https sites is supported if your version of the NNG
68+
#' library was built with TLS support (using Mbed TLS) and the environment
69+
#' variable NANONEXT_TLS=1 was set when installing the package e.g. by
70+
#' \code{Sys.setenv(NANONEXT_TLS=1)}. Note: not applicable for Windows systems.
71+
#'
72+
#' @export
73+
#'
74+
ncurl <- function(http) {
75+
76+
res <- .Call(rnng_ncurl, http)
77+
missing(res) && return(invisible())
78+
if (is.integer(res)) {
79+
message(res, " : ", nng_error(res))
80+
return(invisible(res))
81+
}
82+
list(raw = res, data = rawToChar(res))
83+
84+
}
85+

configure

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
# Library settings
77
PKG_TEST_HEADER="<nng/nng.h>"
88
PKG_LIBS="-lnng"
9+
if [ "$NANONEXT_TLS" ]; then
10+
PKG_LIBS="$PKG_LIBS -lmbedtls -lmbedx509 -lmbedcrypto"
11+
fi
912
PKG_CFLAGS=""
1013
LIB_VER="1.5.2"
1114
SYS_LIB=0
@@ -77,7 +80,23 @@ CFLAGS=`${R_HOME}/bin/R CMD config CFLAGS`
7780
echo "#include $PKG_TEST_HEADER" | ${CC} ${PKG_CFLAGS} ${CFLAGS} -E -xc - >/dev/null 2>&1
7881

7982
if [ $? -ne 0 ]; then
80-
if [ $SYS_LIB = 1 ]; then
83+
if [ "$SYS_LIB" -ne 1 ]; then
84+
echo "------------------------------[ NANONEXT ]------------------------------"
85+
echo "Configuration failed because 'libnng' was not found."
86+
echo "Automatic download and/or build also failed. Try installing:"
87+
echo " * deb: libnng-dev (Debian, Ubuntu, etc.)"
88+
echo " * rpm: nng-devel (Fedora, CentOS etc.)"
89+
echo " * arch: https://aur.archlinux.org/nng.git (Arch from AUR)"
90+
echo " * brew: nng (MacOS)"
91+
echo "Alternatively:"
92+
echo " * vcpkg: nng (Linux/MacOS, follow getting started instructions at"
93+
echo " https://vcpkg.io/ starting from your HOME directory)"
94+
echo "If 'libnng' is already installed but in a non-standard location, you"
95+
echo "may set INCLUDE_DIR and LIB_DIR manually via:"
96+
echo "R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'"
97+
echo "-------------------------------------------------------------------------"
98+
exit 1
99+
else
81100
echo "Attempt to use system libnng failed"
82101
echo "Preparing to download and build library from source..."
83102
curl -L https://github.com/nanomsg/nng/archive/refs/tags/v$LIB_VER.tar.gz -o nng.tar.gz
@@ -118,22 +137,6 @@ if [ $? -ne 0 ]; then
118137
echo "-------------------------------------------------------------------------"
119138
exit 1
120139
fi
121-
else
122-
echo "------------------------------[ NANONEXT ]------------------------------"
123-
echo "Configuration failed because 'libnng' was not found."
124-
echo "Automatic download and/or build also failed. Try installing:"
125-
echo " * deb: libnng-dev (Debian, Ubuntu, etc.)"
126-
echo " * rpm: nng-devel (Fedora, CentOS etc.)"
127-
echo " * arch: https://aur.archlinux.org/nng.git (Arch from AUR)"
128-
echo " * brew: nng (MacOS)"
129-
echo "Alternatively:"
130-
echo " * vcpkg: nng (Linux/MacOS, follow getting started instructions at"
131-
echo " https://vcpkg.io/ starting from your HOME directory)"
132-
echo "If 'libnng' is already installed but in a non-standard location, you"
133-
echo "may set INCLUDE_DIR and LIB_DIR manually via:"
134-
echo "R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'"
135-
echo "-------------------------------------------------------------------------"
136-
exit 1
137140
fi
138141
fi
139142

man/ncurl.Rd

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/nng_version.Rd

Lines changed: 11 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)