Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update internal S2 version and migrate dependency build to cmake #249

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@
^README\.Rmd$
^vignettes/articles$
^\.clang-format$
^tools/build$
^tools/dist$
^compile_commands\.json$
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tools/vendor/abseil-cpp linguist-vendored
tools/vendor/s2-geometry linguist-vendored
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
.vscode
docs
configure.log
compile_commands.json
.cache
3 changes: 0 additions & 3 deletions cleanup

This file was deleted.

159 changes: 60 additions & 99 deletions configure
Original file line number Diff line number Diff line change
@@ -1,112 +1,74 @@
# Anticonf (tm) script by Jeroen Ooms (2020)
# This script will query 'pkg-config' for the required cflags and ldflags.
# If pkg-config is unavailable or does not find the library, try setting
# INCLUDE_DIR and LIB_DIR manually via e.g:
# R CMD INSTALL --configure-vars='INCLUDE_DIR=/.../include LIB_DIR=/.../lib'

# Library settings
PKG_CONFIG_NAME="openssl"
PKG_DEB_NAME="libssl-dev"
PKG_RPM_NAME="openssl-devel"
PKG_CSW_NAME="libssl_dev"
PKG_BREW_NAME="[email protected]"
PKG_TEST_FILE="tools/version.c"
PKG_LIBS="-lssl -lcrypto"
PKG_CFLAGS=""

# Use pkg-config if available
pkg-config ${PKG_CONFIG_NAME} --atleast-version=1.0 2>/dev/null
if [ $? -eq 0 ]; then
PKGCONFIG_CFLAGS=`pkg-config --cflags ${PKG_CONFIG_NAME}`
PKGCONFIG_LIBS=`pkg-config --libs ${PKG_CONFIG_NAME}`
fi

# Note that cflags may be empty in case of success
if [ "$INCLUDE_DIR" ] || [ "$LIB_DIR" ]; then
echo "Found INCLUDE_DIR and/or LIB_DIR!"
PKG_CFLAGS="-I$INCLUDE_DIR $PKG_CFLAGS"
PKG_LIBS="-L$LIB_DIR $PKG_LIBS"
elif [ "$PKGCONFIG_CFLAGS" ] || [ "$PKGCONFIG_LIBS" ]; then
echo "Found pkg-config cflags and libs!"
PKG_CFLAGS=${PKGCONFIG_CFLAGS}
PKG_LIBS=${PKGCONFIG_LIBS}
elif [ `uname` = "Darwin" ]; then
test ! "$CI" && brew --version 2>/dev/null
if [ $? -eq 0 ]; then
BREWDIR=`brew --prefix`
PKG_CFLAGS="-I$BREWDIR/opt/openssl/include -I$BREWDIR/opt/[email protected]/include"
PKG_LIBS="-L$BREWDIR/opt/openssl/lib -L$BREWDIR/opt/[email protected]/lib $PKG_LIBS"
else
curl -sfL "https://autobrew.github.io/scripts/$PKG_BREW_NAME" > autobrew
. ./autobrew
fi
# https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Using-cmake

if test -z "$CMAKE"; then CMAKE="`which cmake`"; fi
if test -z "$CMAKE"; then CMAKE=/Applications/CMake.app/Contents/bin/cmake; fi
if ${CMAKE} --version ; then
echo "Using CMAKE=$CMAKE"
echo "Using MAKE=$MAKE $MAKEVARS"
else
echo "cmake not found"
fi

# Find compiler
CC=`${R_HOME}/bin/R CMD config CC`
CFLAGS=`${R_HOME}/bin/R CMD config CFLAGS`
CPPFLAGS=`${R_HOME}/bin/R CMD config CPPFLAGS`

# For debugging
echo "Testing compiler using PKG_CFLAGS=$PKG_CFLAGS"

# Test configuration
${CC} ${CPPFLAGS} ${PKG_CFLAGS} ${CFLAGS} -E ${PKG_TEST_FILE} >/dev/null 2>configure.log

# Customize the error
if [ $? -ne 0 ]; then
echo "--------------------------- [ANTICONF] --------------------------------"
echo "Configuration failed because $PKG_CONFIG_NAME was not found. Try installing:"
echo " * deb: $PKG_DEB_NAME (Debian, Ubuntu, etc)"
echo " * rpm: $PKG_RPM_NAME (Fedora, CentOS, RHEL)"
echo " * csw: $PKG_CSW_NAME (Solaris)"
echo " * brew: $PKG_BREW_NAME (Mac OSX)"
echo "If $PKG_CONFIG_NAME is already installed, check that 'pkg-config' is in your"
echo "PATH and PKG_CONFIG_PATH contains a $PKG_CONFIG_NAME.pc file. If pkg-config"
echo "is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:"
echo "R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'"
echo "-------------------------- [ERROR MESSAGE] ---------------------------"
cat configure.log
echo "--------------------------------------------------------------------"
: ${R_HOME=`R RHOME`}
if test -z "${R_HOME}"; then
echo "could not determine R_HOME"
exit 1
fi

# Try to link against the correct OpenSSL version
if [ -z "$AUTOBREW" ]; then
SONAME=`${CC} -E ${PKG_CFLAGS} src/tests/soname.h | sh | xargs`
if [ "$SONAME" ]; then
if [ `uname` = "Darwin" ]; then
PKG_LIBS_VERSIONED=`echo "${PKG_LIBS}" | sed "s/-lssl/-lssl.${SONAME}/" | sed "s/-lcrypto/-lcrypto.${SONAME}/"`
else
PKG_LIBS_VERSIONED=`echo "${PKG_LIBS}" | sed "s/-lssl/-l:libssl.so.${SONAME}/" | sed "s/-lcrypto/-l:libcrypto.so.${SONAME}/"`
fi
CC=`"${R_HOME}/bin/R" CMD config CC`
CXX=`${R_HOME}/bin/R CMD config CXX14`
CFLAGS=`"${R_HOME}/bin/R" CMD config CFLAGS`
CPPFLAGS=`"${R_HOME}/bin/R" CMD config CPPFLAGS`
CXXFLAGS=`"${R_HOME}/bin/R" CMD config CXX14FLAGS`
LDFLAGS=`"${R_HOME}/bin/R" CMD config LDFLAGS`

# Test if versioned linking works
${CC} ${PKG_CFLAGS} src/tests/main.c ${PKG_LIBS_VERSIONED} -o src/main.exe 2>/dev/null
if [ $? -eq 0 ]; then PKG_LIBS="${PKG_LIBS_VERSIONED}"; fi
rm src/main.exe || true
CMAKE_INSTALL_PREFIX="`pwd`/tools/dist"
CMAKE_PREFIX_PATH="`pwd`/tools/dist/lib/cmake"

# Suppress opensslv3 warnings for now
if [ "$SONAME" = "3" ]; then
PKG_CFLAGS="$PKG_CFLAGS -DOPENSSL_SUPPRESS_DEPRECATED"
fi
build_cmake () {
if [ ! -d "tools/build/$1" ]; then
mkdir -p "tools/build/$1"
fi

fi #SONAME
fi #AUTOBREW

# Define system endianness (compile-time endianness using system/compiler
# defines isn't detected on Solaris)
# based on endian detection from the feather package by @hadley
R_ENDIAN=`${R_HOME}/bin/Rscript -e 'cat(.Platform$endian)'`
# Trim off any warning messages that Rscript appends in front of the platform endianness
R_ENDIAN=`expr "$R_ENDIAN" : '.*\(little\)$'`
SYS_ENDIAN=""
if [ "$R_ENDIAN" = "little" ]; then
PKG_CFLAGS="$PKG_CFLAGS -DIS_LITTLE_ENDIAN"
else
PKG_CFLAGS="$PKG_CFLAGS -DIS_BIG_ENDIAN"
cd "tools/build/$1"

${CMAKE} \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=OFF \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-DCMAKE_INSTALL_PREFIX="${CMAKE_INSTALL_PREFIX}" \
-DCMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH}" \
-DCMAKE_OSX_DEPLOYMENT_TARGET=11.3 \
-DCMAKE_CXX_STANDARD=14 "${@:2}" \
"../../vendor/$1" &&
${MAKE} ${MAKEVARS} &&
${CMAKE} --install .

cd ../../..
}

# Consider doing this in a separate CMakeLists.txt?

if [ -d tools/build ] || [ ! -d tools/dist ]; then
build_cmake abseil-cpp -DABSL_PROPAGATE_CXX_STD=ON &&
build_cmake s2geometry &&
build_cmake s2geography -DS2_ROOT_DIR="`pwd`/tools/dist" &&
cp tools/build/s2geography/OPENSSL* tools/dist/ &&
rm -rf tools/build
fi

# Assemble bulit libraries
CMAKE_LIBS="-labsl_base -labsl_city -labsl_cord -labsl_cord_internal -labsl_cordz_functions -labsl_cordz_handle -labsl_cordz_info -labsl_hash -labsl_hashtablez_sampler -labsl_int128 -labsl_kernel_timeout_internal -labsl_low_level_hash -labsl_malloc_internal -labsl_raw_hash_set -labsl_raw_logging_internal -labsl_spinlock_wait -labsl_stacktrace -labsl_str_format_internal -labsl_strerror -labsl_string_view -labsl_strings -labsl_strings_internal -labsl_synchronization -labsl_throw_delegate -labsl_time -labsl_time_zone -ls2 -ls2geography"

#CMAKE_LIBS=`ls tools/dist/lib | grep -e "lib" | sed -e "s/^lib/-l/" -e "s/.a$//" | tr '\n' ' '`
OPENSSL_INCLUDE_DIR=`cat tools/dist/OPENSSL_INCLUDE_DIR`
OPENSSL_CRYPTO_LIBRARY=`cat tools/dist/OPENSSL_CRYPTO_LIBRARY`
OPENSSSL_LIB_DIR=`dirname $OPENSSL_CRYPTO_LIBRARY`

PKG_LIBS="-L`pwd`/tools/dist/lib $CMAKE_LIBS -L$OPENSSSL_LIB_DIR -lcrypto"
PKG_CFLAGS="-I`pwd`/tools/dist/include -I$OPENSSL_INCLUDE_DIR"

# From apache/arrow/r/configure:
# If on Raspberry Pi, need to manually link against latomic
# See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81358 for similar example
Expand All @@ -117,7 +79,6 @@ fi
echo "Using PKG_LIBS=$PKG_LIBS"
echo "Using PKG_CFLAGS=$PKG_CFLAGS"


# Write to Makevars
sed -e "s|@cflags@|$PKG_CFLAGS|" -e "s|@libs@|$PKG_LIBS|" src/Makevars.in > src/Makevars

Expand Down
3 changes: 0 additions & 3 deletions data-raw/.gitignore

This file was deleted.

180 changes: 21 additions & 159 deletions data-raw/update-absl.R
Original file line number Diff line number Diff line change
@@ -1,166 +1,28 @@

library(tidyverse)
tag <- "20220623.1"
tag <- "20230802.1"

# download Abseil
source_url <- glue::glue("https://github.com/abseil/abseil-cpp/archive/refs/tags/{tag}.zip")
curl::curl_download(source_url, "data-raw/abseil-cpp-source.zip")
unzip("data-raw/abseil-cpp-source.zip", exdir = "data-raw")


absl_copy <- function(src, dst) {
src_files <- list.files(src, "\\.(cc|h|inc)$", recursive = TRUE) %>%
str_subset("_test(ing)?\\.(cc|h)$", negate = TRUE) %>%
str_subset("test_", negate = TRUE) %>%
str_subset("_benchmark", negate = TRUE)

dst_files <- file.path(dst, src_files)
dst_dirs <- unique(dirname(dst_files))
for (d in sort(dst_dirs)) {
if (!dir.exists(d)) dir.create(d, recursive = TRUE)
}

stopifnot(all(file.copy(file.path(src, src_files), dst_files)))
}

unlink("src/absl", recursive = TRUE)

absl_copy(
glue::glue("data-raw/abseil-cpp-{tag}/absl/container"),
"src/absl/container"
)

absl_copy(
glue::glue("data-raw/abseil-cpp-{tag}/absl/base"),
"src/absl/base"
)

absl_copy(
glue::glue("data-raw/abseil-cpp-{tag}/absl/meta"),
"src/absl/meta"
)

absl_copy(
glue::glue("data-raw/abseil-cpp-{tag}/absl/synchronization"),
"src/absl/synchronization"
)

absl_copy(
glue::glue("data-raw/abseil-cpp-{tag}/absl/time"),
"src/absl/time"
)

absl_copy(
glue::glue("data-raw/abseil-cpp-{tag}/absl/strings"),
"src/absl/strings"
)

absl_copy(
glue::glue("data-raw/abseil-cpp-{tag}/absl/utility"),
"src/absl/utility"
)

absl_copy(
glue::glue("data-raw/abseil-cpp-{tag}/absl/debugging"),
"src/absl/debugging"
)

absl_copy(
glue::glue("data-raw/abseil-cpp-{tag}/absl/memory"),
"src/absl/memory"
)

absl_copy(
glue::glue("data-raw/abseil-cpp-{tag}/absl/types"),
"src/absl/types"
unzip("data-raw/abseil-cpp-source.zip", exdir = "tools/vendor")
file.rename(glue::glue("tools/vendor/abseil-cpp-{tag}"), "tools/vendor/abseil-cpp")

# prune unused components
unlink("tools/vendor/abseil-cpp/.github", recursive = TRUE)
unlink("tools/vendor/abseil-cpp/ci", recursive = TRUE)
unlink(list.files("tools/vendor/abseil-cpp", "\\.py$", full.names = TRUE))
unlink(
list.files(
"tools/vendor/abseil-cpp/absl", "_test.cc$",
full.names = TRUE,
recursive = TRUE
)
)
unlink(
list.files(
"tools/vendor/abseil-cpp/absl", "_benchmark.cc$",
full.names = TRUE,
recursive = TRUE
)
)

absl_copy(
glue::glue("data-raw/abseil-cpp-{tag}/absl/numeric"),
"src/absl/numeric"
)

absl_copy(
glue::glue("data-raw/abseil-cpp-{tag}/absl/algorithm"),
"src/absl/algorithm"
)

absl_copy(
glue::glue("data-raw/abseil-cpp-{tag}/absl/functional"),
"src/absl/functional"
)

absl_copy(
glue::glue("data-raw/abseil-cpp-{tag}/absl/profiling"),
"src/absl/profiling"
)

absl_objects <- list.files("src/absl", ".cc$", recursive = TRUE) %>%
file.path("absl", .) %>%
str_subset("\\.cc$") %>%
str_replace("\\.cc$", ".o") %>%
paste0(collapse = " \\\n ") %>%
paste0("ABSL_LIBS = ", .)

clipr::write_clip(absl_objects)
usethis::edit_file("src/Makevars.win")
usethis::edit_file("src/Makevars.in")

# Edits needed to make CMD check happy

# Pragmas
fix_pragmas <- function(f) {
content <- readr::read_file(f)
content <- stringr::str_replace_all(content, "\n#pragma", "\n// #pragma")
readr::write_file(content, f)
}

fix_pragmas("src/absl/base/internal/invoke.h")
fix_pragmas("src/absl/container/inlined_vector.h")
fix_pragmas("src/absl/container/internal/inlined_vector.h")
fix_pragmas("src/absl/functional/internal/any_invocable.h")
fix_pragmas("src/absl/types/internal/optional.h")
fix_pragmas("src/absl/container/internal/counting_allocator.h")

# Aborts
fix_aborts <- function(f) {
content <- readr::read_file(f)
content <- stringr::str_replace_all(content, fixed("abort()"), "throw std::runtime_error(\"abort()\")")
readr::write_file(content, f)
}

fix_aborts("src/absl/base/internal/raw_logging.cc")
fix_aborts("src/absl/base/internal/sysinfo.cc")
fix_aborts("src/absl/debugging/symbolize_elf.inc")

# Manual updates

# The symbolizer implementation causes some trouble. We don't use this feature here
# and there seems to be a way to turn it off completely. Do this.
usethis::edit_file("src/absl/debugging/symbolize.cc")

# On Windows, R.h defines a macro 'Free', which we have to undefine
usethis::edit_file("src/absl/base/internal/low_level_alloc.h")

# On Windows with rtools35 (i.e., very old GCC with incomplete C++11), a reference
# to std::get_time() causes compilation error. We don't need strptime here, so just
# return nullptr in this function.
usethis::edit_file("src/absl/time/internal/cctz/src/time_zone_format.cc")

# Windows builds have some additional issues with format strings. These are all within
# absl logger functions...just remove the definition of ABSL_RAW_LOG(...).
usethis::edit_file("src/absl/base/internal/raw_logging.h")

# Fix a workaround for older gcc that causes a check warning. The bug that the
# workaround is addressing only applies to old gcc, so only use that bit of code
# for old gcc
usethis::edit_file("src/absl/container/internal/raw_hash_set.h")

# CRAN compiles with -Wpedantic, so we can't use the __int128 intrinsic type
# undefine ABSL_HAVE_INTRINSIC_INT128 here:
usethis::edit_file("src/absl/base/config.h")

# The use of ABSL_HAVE_CPP_ATTRIBUTE() with ABSL_FALLTHROUGH_INTENDED
# here uses C++17 attributes even if -std=c++17 is not set,
# which causes CRAN warnings with -Wpedantic
usethis::edit_file("src/absl/base/attributes.h")
Loading
Loading