diff --git a/.Rbuildignore b/.Rbuildignore index af9ce000..b8a674fa 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -12,3 +12,7 @@ ^README\.Rmd$ ^vignettes/articles$ ^\.clang-format$ +^tools/build$ +^tools/dist$ +^compile_commands\.json$ +^\.cache$ diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..203732ea --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ + +tools/vendor/abseil-cpp linguist-vendored diff --git a/.github/workflows/check-standard.yaml b/.github/workflows/check-standard.yaml index b912eb92..6f79b931 100644 --- a/.github/workflows/check-standard.yaml +++ b/.github/workflows/check-standard.yaml @@ -19,8 +19,9 @@ jobs: matrix: config: - {os: macOS-latest, r: 'release'} - - {os: windows-latest, r: '3.6'} - {os: windows-latest, r: '4.1'} + - {os: windows-latest, r: '4.2'} + - {os: windows-latest, r: '4.3'} - {os: windows-latest, r: 'release'} - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} - {os: ubuntu-latest, r: 'release'} diff --git a/.gitignore b/.gitignore index a4d151d6..8a1df551 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,6 @@ .vscode docs configure.log +.cache +compile_commands.json +windows diff --git a/DESCRIPTION b/DESCRIPTION index d65a6286..1a82b81d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: s2 Title: Spherical Geometry Operators Using the S2 Geometry Library -Version: 1.1.6 +Version: 1.1.6.9000 Authors@R: c( person(given = "Dewey", family = "Dunnington", @@ -19,26 +19,26 @@ Authors@R: c( Description: Provides R bindings for Google's s2 library for geometric calculations on the sphere. High-performance constructors and exporters provide high compatibility with existing spatial packages, transformers construct new geometries from existing - geometries, predicates provide a means to select geometries based on spatial + geometries, predicates provide a means to select geometries based on spatial relationships, and accessors extract information about geometries. License: Apache License (== 2.0) Encoding: UTF-8 LazyData: true Roxygen: list(markdown = TRUE) RoxygenNote: 7.2.3 -SystemRequirements: OpenSSL >= 1.0.1 -LinkingTo: +SystemRequirements: OpenSSL >= 1.0.1, Abseil >= 20230802.0 +LinkingTo: Rcpp, wk -Imports: +Imports: Rcpp, wk (>= 0.6.0) -Suggests: +Suggests: bit64, testthat (>= 3.0.0), vctrs URL: https://r-spatial.github.io/s2/, https://github.com/r-spatial/s2, http://s2geometry.io/ BugReports: https://github.com/r-spatial/s2/issues -Depends: +Depends: R (>= 3.0.0) Config/testthat/edition: 3 diff --git a/NEWS.md b/NEWS.md index b825a6b0..b87194d8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,13 @@ +# s2 (development version) + +* The Abseil dependency is resolved using pkg-config where possible. + Where this is not possible, a vendored version of Abseil will be built using + CMake (#258). + +# s2 1.1.6 + +* Fix CRAN warning (#254). + # s2 1.1.5 * fix compiler problem on Alpine 3.19.0 (#251) diff --git a/cleanup b/cleanup index 3fd9cd21..56fc4727 100755 --- a/cleanup +++ b/cleanup @@ -1,3 +1,7 @@ #!/bin/sh rm -f src/Makevars configure.log autobrew -rm `find src -name *.o` +rm `find src -name "*.o"` +rm `find src -name "*.a"` +rm `find src -name "*.tmp"` +rm -rf tools/build +rm -rf tools/dist diff --git a/configure b/configure index fbf909f0..4a7aaf5e 100755 --- a/configure +++ b/configure @@ -107,6 +107,51 @@ else PKG_CFLAGS="$PKG_CFLAGS -DIS_BIG_ENDIAN" fi +# Check pkg-config for abseil-cpp, but fall back to a cmake build. +# This should possibly be updated to check that the pkg-config detected +# version will actually work; however, the version of abseil that included +# pkg-config files is about the same as the minimum version required here. +export PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:`pwd`/tools/pkgconfig" +echo "** Using PKG_CONFIG_PATH=${PKG_CONFIG_PATH}" + +if [ -z "${R_S2_ABSL_HOME}" ] && pkg-config absl_s2 --libs 2>/dev/null; then + echo "** Using abseil-cpp from pkg-config" + + PKGCONFIG_CFLAGS=`pkg-config --cflags-only-I absl_s2` + PKGCONFIG_LIBS=`pkg-config --libs absl_s2` + PKG_CFLAGS="${PKGCONFIG_CFLAGS} ${PKG_CFLAGS}" + PKG_LIBS="${PKGCONFIG_LIBS} ${PKG_LIBS}" +else + # Allow developers to set R_S2_ABSL_HOME in .Renviron to avoid building + # Abseil on every package rebuild. This can be built from this directory using + # tools/build_absl.sh path/to/dir (then R_S2_ABSL_HOME=path/to/dir in .Renviron) + if [ -z "$R_S2_ABSL_HOME" ]; then + echo "** Building abseil-cpp using cmake" + CMAKE_INSTALL_PREFIX="`pwd`/tools/dist" + if tools/build_absl.sh "${CMAKE_INSTALL_PREFIX}"; then + echo "** Done!" + else + echo "** CMake build of Abseil failed" + echo "** Abseil can be installed with:" + echo "** - apt-get install libabsl-dev" + echo "** - dnf install abseil-cpp-devel" + echo "** - brew install abseil" + echo "** If a system install of Abseil is not possible, cmake is required to build" + echo "** the internal vendored copy." + exit 1 + fi + + # Clean up build directory + rm -rf tools/build + + R_S2_ABSL_HOME="`pwd`/tools/dist" + fi + + ABSL_LIBS="-labsl_cord -labsl_cordz_info -labsl_cord_internal -labsl_cordz_functions -labsl_cordz_handle -labsl_crc_cord_state -labsl_crc32c -labsl_crc_internal -labsl_crc_cpu_detect -labsl_raw_hash_set -labsl_hashtablez_sampler -labsl_exponential_biased -labsl_synchronization -labsl_graphcycles_internal -labsl_kernel_timeout_internal -labsl_stacktrace -labsl_symbolize -labsl_malloc_internal -labsl_time -labsl_civil_time -labsl_time_zone -labsl_hash -labsl_city -labsl_bad_optional_access -labsl_bad_variant_access -labsl_low_level_hash -labsl_str_format_internal -labsl_strings -labsl_string_view -labsl_strings_internal -labsl_int128 -labsl_throw_delegate -labsl_demangle_internal -labsl_base -labsl_spinlock_wait -labsl_debugging_internal -labsl_raw_logging_internal -labsl_log_severity" + PKG_CFLAGS="-I${R_S2_ABSL_HOME}/include ${PKG_CFLAGS}" + PKG_LIBS="-L${R_S2_ABSL_HOME}/lib ${ABSL_LIBS} ${PKG_LIBS}" +fi + # 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 @@ -117,7 +162,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 diff --git a/configure.win b/configure.win index e69de29b..85d0e2ce 100755 --- a/configure.win +++ b/configure.win @@ -0,0 +1,21 @@ + +# On R 4.3 and 4.4, Abseil can be resolved using pkg-config. Otherwise, +# build a copy of Abseil-cpp using CMake. +if pkg-config absl_base --libs 2>/dev/null; then + echo "Using Abseil from RTools via pkg-config" +else + # Build the libraries + CMAKE_INSTALL_PREFIX="`pwd`/tools/dist" + WIN_CPPFLAGS="-DABSL_FORCE_WAITER_MODE=4" tools/build_absl.sh "${CMAKE_INSTALL_PREFIX}" + + # Remove the build directory (its existence causes a check warning on R 4.2) + rm -rf tools/build +fi + +# On R 4.3 and 4.4, OpenSSL can be resolved using pkg-config. Otherwise, +# Use rwinlibs to download a static library for that toolchain. +if pkg-config openssl --libs 2>/dev/null; then + echo "Using openssl from RTools via pkg-config" +else + "${R_HOME}/bin/Rscript.exe" "tools/winlibs.R" +fi diff --git a/data-raw/update-absl.R b/data-raw/update-absl.R index 6c361b20..b59d68a4 100644 --- a/data-raw/update-absl.R +++ b/data-raw/update-absl.R @@ -1,166 +1,30 @@ library(tidyverse) -tag <- "20220623.1" +tag <- "20230802.2" # 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" -) - -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") +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/.clang-format") +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 + ) +) +unlink("tools/vendor/abseil-cpp/absl/time/internal/cctz/testdata", recursive = TRUE) diff --git a/src/.gitignore b/src/.gitignore index e8386315..39cd3a44 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -2,3 +2,4 @@ *.so *.dll Makevars +s2/libs2static.a diff --git a/src/Makevars.in b/src/Makevars.in index 2bc496ee..5b75e25d 100644 --- a/src/Makevars.in +++ b/src/Makevars.in @@ -1,117 +1,10 @@ PKG_CPPFLAGS = -I../src -DSTRICT_R_HEADERS -PKG_LIBS = @libs@ +PKG_LIBS = -Ls2 -ls2static @libs@ PKG_CXXFLAGS = @cflags@ -pthread -CXX_STD = CXX11 +CXX_STD = CXX17 -ABSL_LIBS = absl/base/internal/cycleclock.o \ - absl/base/internal/low_level_alloc.o \ - absl/base/internal/raw_logging.o \ - absl/base/internal/scoped_set_env.o \ - absl/base/internal/spinlock_wait.o \ - absl/base/internal/spinlock.o \ - absl/base/internal/strerror.o \ - absl/base/internal/sysinfo.o \ - absl/base/internal/thread_identity.o \ - absl/base/internal/throw_delegate.o \ - absl/base/internal/unscaledcycleclock.o \ - absl/base/log_severity.o \ - absl/container/internal/hashtablez_sampler_force_weak_definition.o \ - absl/container/internal/hashtablez_sampler.o \ - absl/container/internal/raw_hash_set.o \ - absl/debugging/failure_signal_handler.o \ - absl/debugging/internal/address_is_readable.o \ - absl/debugging/internal/demangle.o \ - absl/debugging/internal/elf_mem_image.o \ - absl/debugging/internal/examine_stack.o \ - absl/debugging/internal/stack_consumption.o \ - absl/debugging/internal/vdso_support.o \ - absl/debugging/leak_check.o \ - absl/debugging/stacktrace.o \ - absl/debugging/symbolize.o \ - absl/numeric/int128.o \ - absl/profiling/internal/exponential_biased.o \ - absl/profiling/internal/periodic_sampler.o \ - absl/strings/ascii.o \ - absl/strings/charconv.o \ - absl/strings/cord_analysis.o \ - absl/strings/cord_buffer.o \ - absl/strings/cord.o \ - absl/strings/escaping.o \ - absl/strings/internal/charconv_bigint.o \ - absl/strings/internal/charconv_parse.o \ - absl/strings/internal/cord_internal.o \ - absl/strings/internal/cord_rep_btree_navigator.o \ - absl/strings/internal/cord_rep_btree_reader.o \ - absl/strings/internal/cord_rep_btree.o \ - absl/strings/internal/cord_rep_consume.o \ - absl/strings/internal/cord_rep_crc.o \ - absl/strings/internal/cord_rep_ring.o \ - absl/strings/internal/cordz_functions.o \ - absl/strings/internal/cordz_handle.o \ - absl/strings/internal/cordz_info.o \ - absl/strings/internal/cordz_sample_token.o \ - absl/strings/internal/escaping.o \ - absl/strings/internal/memutil.o \ - absl/strings/internal/ostringstream.o \ - absl/strings/internal/pow10_helper.o \ - absl/strings/internal/str_format/arg.o \ - absl/strings/internal/str_format/bind.o \ - absl/strings/internal/str_format/extension.o \ - absl/strings/internal/str_format/float_conversion.o \ - absl/strings/internal/str_format/output.o \ - absl/strings/internal/str_format/parser.o \ - absl/strings/internal/utf8.o \ - absl/strings/match.o \ - absl/strings/numbers.o \ - absl/strings/str_cat.o \ - absl/strings/str_replace.o \ - absl/strings/str_split.o \ - absl/strings/string_view.o \ - absl/strings/substitute.o \ - absl/synchronization/barrier.o \ - absl/synchronization/blocking_counter.o \ - absl/synchronization/internal/create_thread_identity.o \ - absl/synchronization/internal/graphcycles.o \ - absl/synchronization/internal/per_thread_sem.o \ - absl/synchronization/internal/waiter.o \ - absl/synchronization/mutex.o \ - absl/synchronization/notification.o \ - absl/time/civil_time.o \ - absl/time/clock.o \ - absl/time/duration.o \ - absl/time/format.o \ - absl/time/internal/cctz/src/civil_time_detail.o \ - absl/time/internal/cctz/src/time_zone_fixed.o \ - absl/time/internal/cctz/src/time_zone_format.o \ - absl/time/internal/cctz/src/time_zone_if.o \ - absl/time/internal/cctz/src/time_zone_impl.o \ - absl/time/internal/cctz/src/time_zone_info.o \ - absl/time/internal/cctz/src/time_zone_libc.o \ - absl/time/internal/cctz/src/time_zone_lookup.o \ - absl/time/internal/cctz/src/time_zone_posix.o \ - absl/time/internal/cctz/src/zone_info_source.o \ - absl/time/time.o \ - absl/types/bad_any_cast.o \ - absl/types/bad_optional_access.o \ - absl/types/bad_variant_access.o - -OBJECTS = $(ABSL_LIBS) \ - cpp-compat.o \ - s2-accessors.o \ - s2-bounds.o \ - s2-cell.o \ - s2-cell-union.o \ - s2-constructors-formatters.o \ - s2-predicates.o \ - s2-transformers.o \ - init.o \ - RcppExports.o \ - s2-geography.o \ - s2-lnglat.o \ - s2-matrix.o \ - wk-impl.o \ - s2geography/accessors.o \ +S2_OBJECTS = s2geography/accessors.o \ s2geography/accessors-geog.o \ s2geography/linear-referencing.o \ s2geography/distance.o \ @@ -217,3 +110,30 @@ OBJECTS = $(ABSL_LIBS) \ s2/util/math/exactfloat/exactfloat.o \ s2/util/math/mathutil.o \ s2/util/units/length-units.o + +STATLIB = s2/libs2static.a + +OBJECTS = cpp-compat.o \ + s2-accessors.o \ + s2-bounds.o \ + s2-cell.o \ + s2-cell-union.o \ + s2-constructors-formatters.o \ + s2-predicates.o \ + s2-transformers.o \ + init.o \ + RcppExports.o \ + s2-geography.o \ + s2-lnglat.o \ + s2-matrix.o \ + wk-impl.o + +$(SHLIB): $(STATLIB) + +$(STATLIB): $(S2_OBJECTS) + ar rcs $(STATLIB) $(S2_OBJECTS) + +clean: + rm -f $(SHLIB) $(STATLIB) $(OBJECTS) $(S2LIBS) + +.PHONY: clean diff --git a/src/Makevars.ucrt b/src/Makevars.ucrt deleted file mode 100644 index 51eed486..00000000 --- a/src/Makevars.ucrt +++ /dev/null @@ -1,3 +0,0 @@ -CRT=-ucrt -include Makevars.win -CXX_STD = CXX11 diff --git a/src/Makevars.win b/src/Makevars.win index 31ed40b7..0fa5a2f8 100644 --- a/src/Makevars.win +++ b/src/Makevars.win @@ -1,113 +1,35 @@ -OPENSSL_LIBS = $(shell pkg-config --libs openssl) -# Config for legacy rtools without pkgconfig -ifeq (,$(OPENSSL_LIBS)) -OPENSSL_LIBS=-L../windows/openssl-$(VERSION)/lib${R_ARCH}${CRT} -lssl -lcrypto -lws2_32 -lgdi32 -lcrypt32 -OPENSSL_CFLAGS=-I../windows/openssl-$(VERSION)/include +# Configure Abseil. If it wasn't available via pkg-config, it was built +# by cmake in configure.win. + +ABSL_LIBS = -labsl_cord -labsl_cordz_info -labsl_cord_internal -labsl_cordz_functions -labsl_cordz_handle -labsl_crc_cord_state -labsl_crc32c -labsl_crc_internal -labsl_crc_cpu_detect -labsl_raw_hash_set -labsl_hashtablez_sampler -labsl_exponential_biased -labsl_synchronization -labsl_graphcycles_internal -labsl_kernel_timeout_internal -labsl_stacktrace -labsl_symbolize -labsl_malloc_internal -labsl_time -labsl_civil_time -labsl_time_zone -labsl_hash -labsl_city -labsl_bad_optional_access -labsl_bad_variant_access -labsl_low_level_hash -labsl_str_format_internal -labsl_strings -labsl_string_view -labsl_strings_internal -labsl_int128 -labsl_throw_delegate -labsl_demangle_internal -labsl_base -labsl_spinlock_wait -labsl_debugging_internal -labsl_raw_logging_internal -labsl_log_severity + +ifeq (,$(shell pkg-config absl_base --libs 2>/dev/null)) + ABSL_CFLAGS = -I../tools/dist/include + ABSL_LIB_FLAGS = -L../tools/dist/lib $(ABSL_LIBS) -limagehlp +else + ABSL_LIB_FLAGS = $(ABSL_LIBS) endif -VERSION = 1.1.1k -PKG_CPPFLAGS = -DS2_USE_EXACTFLOAT -D_USE_MATH_DEFINES -DNDEBUG -DIS_LITTLE_ENDIAN -DOMIT_STRPTIME $(OPENSSL_CFLAGS) -I../src -PKG_LIBS = -Ls2 -ls2static $(OPENSSL_LIBS) -CXX_STD = CXX11 +# Configure openssl and finalize PKG_LIBS. If openssl is not available via +# pkg-config, it was downloaded from rwinlibs in configure.win. +ifeq (,$(shell pkg-config openssl --libs 2>/dev/null)) + OPENSSL_CFLAGS = -I../windows/openssl/include + OPENSSL_LIB_FLAGS = -L../windows/openssl/lib -lssl -lcrypto -lz -lws2_32 -lgdi32 -lcrypt32 +else + OPENSSL_CFLAGS = + OPENSSL_LIB_FLAGS = $(shell pkg-config --libs openssl) +endif -STATLIB = s2/libs2static.a +PKG_CPPFLAGS = $(ABSL_CFLAGS) $(OPENSSL_CFLAGS) -DSTRICT_R_HEADERS -DS2_USE_EXACTFLOAT -D_USE_MATH_DEFINES -DNDEBUG -DIS_LITTLE_ENDIAN -DOMIT_STRPTIME -I../src +PKG_LIBS = -Ls2 -ls2static $(ABSL_LIB_FLAGS) $(OPENSSL_LIB_FLAGS) -ABSL_LIBS = absl/base/internal/cycleclock.o \ - absl/base/internal/low_level_alloc.o \ - absl/base/internal/raw_logging.o \ - absl/base/internal/scoped_set_env.o \ - absl/base/internal/spinlock_wait.o \ - absl/base/internal/spinlock.o \ - absl/base/internal/strerror.o \ - absl/base/internal/sysinfo.o \ - absl/base/internal/thread_identity.o \ - absl/base/internal/throw_delegate.o \ - absl/base/internal/unscaledcycleclock.o \ - absl/base/log_severity.o \ - absl/container/internal/hashtablez_sampler_force_weak_definition.o \ - absl/container/internal/hashtablez_sampler.o \ - absl/container/internal/raw_hash_set.o \ - absl/debugging/failure_signal_handler.o \ - absl/debugging/internal/address_is_readable.o \ - absl/debugging/internal/demangle.o \ - absl/debugging/internal/elf_mem_image.o \ - absl/debugging/internal/examine_stack.o \ - absl/debugging/internal/stack_consumption.o \ - absl/debugging/internal/vdso_support.o \ - absl/debugging/leak_check.o \ - absl/debugging/stacktrace.o \ - absl/debugging/symbolize.o \ - absl/numeric/int128.o \ - absl/profiling/internal/exponential_biased.o \ - absl/profiling/internal/periodic_sampler.o \ - absl/strings/ascii.o \ - absl/strings/charconv.o \ - absl/strings/cord_analysis.o \ - absl/strings/cord_buffer.o \ - absl/strings/cord.o \ - absl/strings/escaping.o \ - absl/strings/internal/charconv_bigint.o \ - absl/strings/internal/charconv_parse.o \ - absl/strings/internal/cord_internal.o \ - absl/strings/internal/cord_rep_btree_navigator.o \ - absl/strings/internal/cord_rep_btree_reader.o \ - absl/strings/internal/cord_rep_btree.o \ - absl/strings/internal/cord_rep_consume.o \ - absl/strings/internal/cord_rep_crc.o \ - absl/strings/internal/cord_rep_ring.o \ - absl/strings/internal/cordz_functions.o \ - absl/strings/internal/cordz_handle.o \ - absl/strings/internal/cordz_info.o \ - absl/strings/internal/cordz_sample_token.o \ - absl/strings/internal/escaping.o \ - absl/strings/internal/memutil.o \ - absl/strings/internal/ostringstream.o \ - absl/strings/internal/pow10_helper.o \ - absl/strings/internal/str_format/arg.o \ - absl/strings/internal/str_format/bind.o \ - absl/strings/internal/str_format/extension.o \ - absl/strings/internal/str_format/float_conversion.o \ - absl/strings/internal/str_format/output.o \ - absl/strings/internal/str_format/parser.o \ - absl/strings/internal/utf8.o \ - absl/strings/match.o \ - absl/strings/numbers.o \ - absl/strings/str_cat.o \ - absl/strings/str_replace.o \ - absl/strings/str_split.o \ - absl/strings/string_view.o \ - absl/strings/substitute.o \ - absl/synchronization/barrier.o \ - absl/synchronization/blocking_counter.o \ - absl/synchronization/internal/create_thread_identity.o \ - absl/synchronization/internal/graphcycles.o \ - absl/synchronization/internal/per_thread_sem.o \ - absl/synchronization/internal/waiter.o \ - absl/synchronization/mutex.o \ - absl/synchronization/notification.o \ - absl/time/civil_time.o \ - absl/time/clock.o \ - absl/time/duration.o \ - absl/time/format.o \ - absl/time/internal/cctz/src/civil_time_detail.o \ - absl/time/internal/cctz/src/time_zone_fixed.o \ - absl/time/internal/cctz/src/time_zone_format.o \ - absl/time/internal/cctz/src/time_zone_if.o \ - absl/time/internal/cctz/src/time_zone_impl.o \ - absl/time/internal/cctz/src/time_zone_info.o \ - absl/time/internal/cctz/src/time_zone_libc.o \ - absl/time/internal/cctz/src/time_zone_lookup.o \ - absl/time/internal/cctz/src/time_zone_posix.o \ - absl/time/internal/cctz/src/zone_info_source.o \ - absl/time/time.o \ - absl/types/bad_any_cast.o \ - absl/types/bad_optional_access.o \ - absl/types/bad_variant_access.o +CXX_STD = CXX17 -S2LIBS = $(ABSL_LIBS) \ - s2geography/linear-referencing.o \ +STATLIB = s2/libs2static.a + +S2LIBS = s2geography/linear-referencing.o \ s2geography/distance.o \ s2geography/accessors.o \ s2geography/accessors-geog.o \ @@ -218,15 +140,9 @@ $(SHLIB): $(STATLIB) $(STATLIB): $(S2LIBS) -$(S2LIBS): winlibs - #all: clean -winlibs: - mkdir -p ../inst - "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" "../tools/winlibs.R" $(VERSION) - clean: rm -f $(SHLIB) $(STATLIB) $(OBJECTS) $(S2LIBS) -.PHONY: all winlibs clean +.PHONY: all clean diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index 24a5ac1b..6350151d 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -1344,12 +1344,12 @@ BEGIN_RCPP END_RCPP } -RcppExport SEXP c_s2_geography_writer_new(SEXP, SEXP, SEXP, SEXP); -RcppExport SEXP c_s2_handle_geography(SEXP, SEXP); -RcppExport SEXP c_s2_handle_geography_tessellated(SEXP, SEXP); -RcppExport SEXP c_s2_projection_mercator(SEXP); -RcppExport SEXP c_s2_projection_orthographic(SEXP); -RcppExport SEXP c_s2_projection_plate_carree(SEXP); +RcppExport SEXP c_s2_geography_writer_new(void *, void *, void *, void *); +RcppExport SEXP c_s2_handle_geography(void *, void *); +RcppExport SEXP c_s2_handle_geography_tessellated(void *, void *); +RcppExport SEXP c_s2_projection_mercator(void *); +RcppExport SEXP c_s2_projection_orthographic(void *); +RcppExport SEXP c_s2_projection_plate_carree(void *); RcppExport SEXP c_s2_trans_s2_lnglat_new(void); RcppExport SEXP c_s2_trans_s2_point_new(void); diff --git a/src/absl/container/internal/raw_hash_set.cc b/src/absl/container/internal/raw_hash_set.cc deleted file mode 100644 index c63a2e02..00000000 --- a/src/absl/container/internal/raw_hash_set.cc +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright 2018 The Abseil Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "absl/container/internal/raw_hash_set.h" - -#include -#include - -#include "absl/base/config.h" - -namespace absl { -ABSL_NAMESPACE_BEGIN -namespace container_internal { - -// A single block of empty control bytes for tables without any slots allocated. -// This enables removing a branch in the hot path of find(). -alignas(16) ABSL_CONST_INIT ABSL_DLL const ctrl_t kEmptyGroup[16] = { - ctrl_t::kSentinel, ctrl_t::kEmpty, ctrl_t::kEmpty, ctrl_t::kEmpty, - ctrl_t::kEmpty, ctrl_t::kEmpty, ctrl_t::kEmpty, ctrl_t::kEmpty, - ctrl_t::kEmpty, ctrl_t::kEmpty, ctrl_t::kEmpty, ctrl_t::kEmpty, - ctrl_t::kEmpty, ctrl_t::kEmpty, ctrl_t::kEmpty, ctrl_t::kEmpty}; - -#ifdef ABSL_INTERNAL_NEED_REDUNDANT_CONSTEXPR_DECL -constexpr size_t Group::kWidth; -#endif - -// Returns "random" seed. -inline size_t RandomSeed() { -#ifdef ABSL_HAVE_THREAD_LOCAL - static thread_local size_t counter = 0; - size_t value = ++counter; -#else // ABSL_HAVE_THREAD_LOCAL - static std::atomic counter(0); - size_t value = counter.fetch_add(1, std::memory_order_relaxed); -#endif // ABSL_HAVE_THREAD_LOCAL - return value ^ static_cast(reinterpret_cast(&counter)); -} - -bool ShouldInsertBackwards(size_t hash, const ctrl_t* ctrl) { - // To avoid problems with weak hashes and single bit tests, we use % 13. - // TODO(kfm,sbenza): revisit after we do unconditional mixing - return (H1(hash, ctrl) ^ RandomSeed()) % 13 > 6; -} - -void ConvertDeletedToEmptyAndFullToDeleted(ctrl_t* ctrl, size_t capacity) { - assert(ctrl[capacity] == ctrl_t::kSentinel); - assert(IsValidCapacity(capacity)); - for (ctrl_t* pos = ctrl; pos < ctrl + capacity; pos += Group::kWidth) { - Group{pos}.ConvertSpecialToEmptyAndFullToDeleted(pos); - } - // Copy the cloned ctrl bytes. - std::memcpy(ctrl + capacity + 1, ctrl, NumClonedBytes()); - ctrl[capacity] = ctrl_t::kSentinel; -} -// Extern template instantiotion for inline function. -template FindInfo find_first_non_full(const ctrl_t*, size_t, size_t); - -} // namespace container_internal -ABSL_NAMESPACE_END -} // namespace absl diff --git a/src/absl/memory/memory.h b/src/absl/memory/memory.h deleted file mode 100644 index d6332606..00000000 --- a/src/absl/memory/memory.h +++ /dev/null @@ -1,699 +0,0 @@ -// Copyright 2017 The Abseil Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ----------------------------------------------------------------------------- -// File: memory.h -// ----------------------------------------------------------------------------- -// -// This header file contains utility functions for managing the creation and -// conversion of smart pointers. This file is an extension to the C++ -// standard library header file. - -#ifndef ABSL_MEMORY_MEMORY_H_ -#define ABSL_MEMORY_MEMORY_H_ - -#include -#include -#include -#include -#include -#include - -#include "absl/base/macros.h" -#include "absl/meta/type_traits.h" - -namespace absl { -ABSL_NAMESPACE_BEGIN - -// ----------------------------------------------------------------------------- -// Function Template: WrapUnique() -// ----------------------------------------------------------------------------- -// -// Adopts ownership from a raw pointer and transfers it to the returned -// `std::unique_ptr`, whose type is deduced. Because of this deduction, *do not* -// specify the template type `T` when calling `WrapUnique`. -// -// Example: -// X* NewX(int, int); -// auto x = WrapUnique(NewX(1, 2)); // 'x' is std::unique_ptr. -// -// Do not call WrapUnique with an explicit type, as in -// `WrapUnique(NewX(1, 2))`. The purpose of WrapUnique is to automatically -// deduce the pointer type. If you wish to make the type explicit, just use -// `std::unique_ptr` directly. -// -// auto x = std::unique_ptr(NewX(1, 2)); -// - or - -// std::unique_ptr x(NewX(1, 2)); -// -// While `absl::WrapUnique` is useful for capturing the output of a raw -// pointer factory, prefer 'absl::make_unique(args...)' over -// 'absl::WrapUnique(new T(args...))'. -// -// auto x = WrapUnique(new X(1, 2)); // works, but nonideal. -// auto x = make_unique(1, 2); // safer, standard, avoids raw 'new'. -// -// Note that `absl::WrapUnique(p)` is valid only if `delete p` is a valid -// expression. In particular, `absl::WrapUnique()` cannot wrap pointers to -// arrays, functions or void, and it must not be used to capture pointers -// obtained from array-new expressions (even though that would compile!). -template -std::unique_ptr WrapUnique(T* ptr) { - static_assert(!std::is_array::value, "array types are unsupported"); - static_assert(std::is_object::value, "non-object types are unsupported"); - return std::unique_ptr(ptr); -} - -namespace memory_internal { - -// Traits to select proper overload and return type for `absl::make_unique<>`. -template -struct MakeUniqueResult { - using scalar = std::unique_ptr; -}; -template -struct MakeUniqueResult { - using array = std::unique_ptr; -}; -template -struct MakeUniqueResult { - using invalid = void; -}; - -} // namespace memory_internal - -// gcc 4.8 has __cplusplus at 201301 but the libstdc++ shipped with it doesn't -// define make_unique. Other supported compilers either just define __cplusplus -// as 201103 but have make_unique (msvc), or have make_unique whenever -// __cplusplus > 201103 (clang). -#if (__cplusplus > 201103L || defined(_MSC_VER)) && \ - !(defined(__GLIBCXX__) && !defined(__cpp_lib_make_unique)) -using std::make_unique; -#else -// ----------------------------------------------------------------------------- -// Function Template: make_unique() -// ----------------------------------------------------------------------------- -// -// Creates a `std::unique_ptr<>`, while avoiding issues creating temporaries -// during the construction process. `absl::make_unique<>` also avoids redundant -// type declarations, by avoiding the need to explicitly use the `new` operator. -// -// This implementation of `absl::make_unique<>` is designed for C++11 code and -// will be replaced in C++14 by the equivalent `std::make_unique<>` abstraction. -// `absl::make_unique<>` is designed to be 100% compatible with -// `std::make_unique<>` so that the eventual migration will involve a simple -// rename operation. -// -// For more background on why `std::unique_ptr(new T(a,b))` is problematic, -// see Herb Sutter's explanation on -// (Exception-Safe Function Calls)[https://herbsutter.com/gotw/_102/]. -// (In general, reviewers should treat `new T(a,b)` with scrutiny.) -// -// Example usage: -// -// auto p = make_unique(args...); // 'p' is a std::unique_ptr -// auto pa = make_unique(5); // 'pa' is a std::unique_ptr -// -// Three overloads of `absl::make_unique` are required: -// -// - For non-array T: -// -// Allocates a T with `new T(std::forward args...)`, -// forwarding all `args` to T's constructor. -// Returns a `std::unique_ptr` owning that object. -// -// - For an array of unknown bounds T[]: -// -// `absl::make_unique<>` will allocate an array T of type U[] with -// `new U[n]()` and return a `std::unique_ptr` owning that array. -// -// Note that 'U[n]()' is different from 'U[n]', and elements will be -// value-initialized. Note as well that `std::unique_ptr` will perform its -// own destruction of the array elements upon leaving scope, even though -// the array [] does not have a default destructor. -// -// NOTE: an array of unknown bounds T[] may still be (and often will be) -// initialized to have a size, and will still use this overload. E.g: -// -// auto my_array = absl::make_unique(10); -// -// - For an array of known bounds T[N]: -// -// `absl::make_unique<>` is deleted (like with `std::make_unique<>`) as -// this overload is not useful. -// -// NOTE: an array of known bounds T[N] is not considered a useful -// construction, and may cause undefined behavior in templates. E.g: -// -// auto my_array = absl::make_unique(); -// -// In those cases, of course, you can still use the overload above and -// simply initialize it to its desired size: -// -// auto my_array = absl::make_unique(10); - -// `absl::make_unique` overload for non-array types. -template -typename memory_internal::MakeUniqueResult::scalar make_unique( - Args&&... args) { - return std::unique_ptr(new T(std::forward(args)...)); -} - -// `absl::make_unique` overload for an array T[] of unknown bounds. -// The array allocation needs to use the `new T[size]` form and cannot take -// element constructor arguments. The `std::unique_ptr` will manage destructing -// these array elements. -template -typename memory_internal::MakeUniqueResult::array make_unique(size_t n) { - return std::unique_ptr(new typename absl::remove_extent_t[n]()); -} - -// `absl::make_unique` overload for an array T[N] of known bounds. -// This construction will be rejected. -template -typename memory_internal::MakeUniqueResult::invalid make_unique( - Args&&... /* args */) = delete; -#endif - -// ----------------------------------------------------------------------------- -// Function Template: RawPtr() -// ----------------------------------------------------------------------------- -// -// Extracts the raw pointer from a pointer-like value `ptr`. `absl::RawPtr` is -// useful within templates that need to handle a complement of raw pointers, -// `std::nullptr_t`, and smart pointers. -template -auto RawPtr(T&& ptr) -> decltype(std::addressof(*ptr)) { - // ptr is a forwarding reference to support Ts with non-const operators. - return (ptr != nullptr) ? std::addressof(*ptr) : nullptr; -} -inline std::nullptr_t RawPtr(std::nullptr_t) { return nullptr; } - -// ----------------------------------------------------------------------------- -// Function Template: ShareUniquePtr() -// ----------------------------------------------------------------------------- -// -// Adopts a `std::unique_ptr` rvalue and returns a `std::shared_ptr` of deduced -// type. Ownership (if any) of the held value is transferred to the returned -// shared pointer. -// -// Example: -// -// auto up = absl::make_unique(10); -// auto sp = absl::ShareUniquePtr(std::move(up)); // shared_ptr -// CHECK_EQ(*sp, 10); -// CHECK(up == nullptr); -// -// Note that this conversion is correct even when T is an array type, and more -// generally it works for *any* deleter of the `unique_ptr` (single-object -// deleter, array deleter, or any custom deleter), since the deleter is adopted -// by the shared pointer as well. The deleter is copied (unless it is a -// reference). -// -// Implements the resolution of [LWG 2415](http://wg21.link/lwg2415), by which a -// null shared pointer does not attempt to call the deleter. -template -std::shared_ptr ShareUniquePtr(std::unique_ptr&& ptr) { - return ptr ? std::shared_ptr(std::move(ptr)) : std::shared_ptr(); -} - -// ----------------------------------------------------------------------------- -// Function Template: WeakenPtr() -// ----------------------------------------------------------------------------- -// -// Creates a weak pointer associated with a given shared pointer. The returned -// value is a `std::weak_ptr` of deduced type. -// -// Example: -// -// auto sp = std::make_shared(10); -// auto wp = absl::WeakenPtr(sp); -// CHECK_EQ(sp.get(), wp.lock().get()); -// sp.reset(); -// CHECK(wp.lock() == nullptr); -// -template -std::weak_ptr WeakenPtr(const std::shared_ptr& ptr) { - return std::weak_ptr(ptr); -} - -namespace memory_internal { - -// ExtractOr::type evaluates to E if possible. Otherwise, D. -template