Skip to content

Commit

Permalink
Merge pull request #368 from rstudio/system-libuv
Browse files Browse the repository at this point in the history
Use system copy of libuv if found
  • Loading branch information
jcheng5 authored May 13, 2023
2 parents bd47919 + d58d5de commit e1da648
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 5 deletions.
1 change: 0 additions & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ on:
push:
branches: [main, rc-**]
pull_request:
branches: [main]
schedule:
- cron: '0 6 * * 1' # every monday

Expand Down
79 changes: 79 additions & 0 deletions .github/workflows/system-libuv.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, rc-**]
pull_request:
schedule:
- cron: '0 6 * * 1' # every monday

name: Test system libuv

jobs:
R-CMD-check:
# Ubuntu 22.04 has libuv1-dev version 1.43, which is sufficient
runs-on: ubuntu-latest
name: Installed=${{ matrix.config.install }} Bundled=${{ matrix.config.use }}
strategy:
fail-fast: false
matrix:
config:
# This one should test that we've used system and everything runs ok
- {install: true}
# This one should test for bundling log message
- {install: true, use: true}
# This one should test for failure
- {install: false, use: false}

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

steps:
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

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

- name: Install libuv
if: ${{ matrix.config.install }}
# If we add tests for e.g. rhel/centos, we couldn't assume apt-get
run: |
sudo apt-get update -y
sudo apt-get install -y libuv1-dev
- name: Ensure libuv is not on the system
if: ${{ !matrix.config.install }}
run: |
sudo apt-get remove -y libuv1-dev || true
- uses: r-lib/actions/check-r-package@v2
if: ${{ matrix.config.install }}
env:
USE_BUNDLED_LIBUV: ${{ matrix.config.use }}
with:
upload-snapshots: true

- name: Confirm that USE_BUNDLED_LIBUV was respected
if: ${{ matrix.config.install }}
env:
USE_BUNDLED_LIBUV: ${{ matrix.config.use }}
run: |
if [ "$USE_BUNDLED_LIBUV" = "true" ]; then
grep "Using bundled copy of libuv" check/httpuv.Rcheck/00install.out
else
grep "Using libuv found by pkg-config" check/httpuv.Rcheck/00install.out
fi
- name: Confirm error if system libuv missing and use=false
if: ${{ !matrix.config.install && !matrix.config.use }}
env:
USE_BUNDLED_LIBUV: ${{ matrix.config.use }}
run: |
R CMD INSTALL . > install.log || true
grep "Did not find suitable libuv on your system" install.log
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ src/httpuv.files
src/httpuv.includes
.Rproj.user
CRAN-RELEASE
httpuv_*.tar.gz
httpuv_*.tar.gz
src/Makevars
configure.log
.vscode
*.orig
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ remotes::install_github("rstudio/httpuv")

Since httpuv contains C code, you'll need to make sure you're set up to install packages with compiled code. Follow the instructions at http://www.rstudio.com/ide/docs/packages/prerequisites

httpuv may optionally be built using a `libuv` system package, which you can install prior to installing the R package. It goes by different names on different package managers: `libuv1-dev` (deb), `libuv-devel` (rpm), `libuv` (brew). Version 1.43 or greater is required. If `libuv` is not found on the system, it will be built from source along with the R package.

## Basic Usage

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 configure.log
45 changes: 45 additions & 0 deletions configure
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env sh

PKG_CONFIG_NAME="libuv"
LIBUV_VERSION_REQUIRED="$PKG_CONFIG_NAME >= 1.43 $PKG_CONFIG_NAME < 2"

# If unset (default), will try to find libuv on system and fall back to bundled
# If true (case insensitive), will not look for system library
# If false, will not fall back to bundled if system library not found
USE_BUNDLED_LIBUV=`echo $USE_BUNDLED_LIBUV | tr '[:upper:]' '[:lower:]'`

if [ `uname -s` = "Darwin" ]; then
# Always do static linking on macOS
PKG_CONFIG="pkg-config --static"
else
PKG_CONFIG="pkg-config"
fi

# First, look for suitable libuv installed on the system
if [ "${USE_BUNDLED_LIBUV}" != "true" ] && ${PKG_CONFIG} --exists ''"${LIBUV_VERSION_REQUIRED}"'' 2>&1; then
echo "** Using libuv found by pkg-config in `${PKG_CONFIG} --variable=prefix --silence-errors ${PKG_CONFIG_NAME}`"
PKG_CFLAGS=`${PKG_CONFIG} --cflags --silence-errors ${PKG_CONFIG_NAME}`
PKG_LIBS=`${PKG_CONFIG} --libs ${PKG_CONFIG_NAME}`
DEPS=""
elif [ "${USE_BUNDLED_LIBUV}" != "false" ]; then
# If not found, use the bundled copy (unless directed otherwise)
echo "** Using bundled copy of libuv"
PKG_CFLAGS="-Ilibuv/include"
PKG_LIBS="./libuv/.libs/libuv.a"
# By setting DEPS, this triggers the libuv build in src/Makevars
DEPS="libuv/.libs/libuv.a"
else
echo "** Did not find suitable libuv on your system,"
echo "** and not building from source because USE_BUNDLED_LIBUV=false."
echo "** Please install ${LIBUV_VERSION_REQUIRED} or unset USE_BUNDLED_LIBUV"
exit 1
fi

# For debugging
echo "** PKG_CFLAGS=$PKG_CFLAGS"
echo "** PKG_LIBS=$PKG_LIBS"
# Write to Makevars
sed -e "s|@cflags@|$PKG_CFLAGS|" -e "s|@libs@|$PKG_LIBS|" -e "s|@deps@|$DEPS|" src/Makevars.in > src/Makevars

# Success
exit 0
6 changes: 3 additions & 3 deletions src/Makevars → src/Makevars.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
UNAME := $(shell uname)

PKG_LIBS = ./libuv/.libs/libuv.a ./http-parser/http_parser.o ./sha1/sha1.o ./base64/base64.o -pthread
PKG_LIBS = @libs@ ./http-parser/http_parser.o ./sha1/sha1.o ./base64/base64.o -pthread

ifeq ($(UNAME), Darwin)
PKG_LIBS += -framework CoreServices
Expand All @@ -18,7 +18,7 @@ endif

PKG_CFLAGS = $(C_VISIBILITY) -DSTRICT_R_HEADERS
PKG_CXXFLAGS = $(CXX_VISIBILITY) -DSTRICT_R_HEADERS
PKG_CPPFLAGS = -Ilibuv/include -pthread
PKG_CPPFLAGS = @cflags@ -pthread

# To avoid spurious warnings from `R CMD check --as-cran`, about compiler
# warning flags like -Werror.
Expand All @@ -38,7 +38,7 @@ CONFIGURE_FLAGS="--quiet"
# PKG_CPPFLAGS += -D_GLIBCXX_ASSERTIONS


$(SHLIB): libuv/.libs/libuv.a http-parser/http_parser.o sha1/sha1.o base64/base64.o
$(SHLIB): @deps@ http-parser/http_parser.o sha1/sha1.o base64/base64.o

# We needed to rename lt~obsolete.m4 because the name causes problems with R
# CMD check. Here we rename it back.
Expand Down

0 comments on commit e1da648

Please sign in to comment.