jeroen / protolite

Fast and Simple Object Serialization to Protocol Buffers
Other
48 stars 9 forks source link

Can't install protolite from source in Mac Silicon #24

Closed can-taslicukur closed 9 months ago

can-taslicukur commented 9 months ago

I have protobuf installed via homebrew.

When I run renv::restore() in a project that requires protolite, I was first getting this error:

Error: Error installing package 'protolite':
=====================================

* installing *source* package ‘protolite’ ...
** package ‘protolite’ successfully unpacked and MD5 sums checked
** using staged installation
Found pkg-config cflags and libs!
Using PKG_CFLAGS=-DPROTOBUF_USE_DLLS -Wno-float-conversion -Wno-implicit-float-conversion -Wno-implicit-int-float-conversion -Wno-unknown-warning-option -DNOMINMAX -I/opt/homebrew/Cellar/protobuf/25.2/include -I/opt/homebrew/Cellar/abseil/20230802.1/include
Using PKG_LIBS=-L/opt/homebrew/Cellar/protobuf/25.2/lib -L/opt/homebrew/Cellar/abseil/20230802.1/lib -lprotobuf -labsl_log_internal_check_op -labsl_leak_check -labsl_die_if_null -labsl_log_internal_conditions -labsl_log_internal_message -labsl_examine_stack -labsl_log_internal_format -labsl_log_internal_proto -labsl_log_internal_nullguard -labsl_log_internal_log_sink_set -labsl_log_sink -labsl_log_entry -labsl_flags -labsl_flags_internal -labsl_flags_marshalling -labsl_flags_reflection -labsl_flags_private_handle_accessor -labsl_flags_commandlineflag -labsl_flags_commandlineflag_internal -labsl_flags_config -labsl_flags_program_name -labsl_log_initialize -labsl_log_globals -labsl_log_internal_globals -labsl_raw_hash_set -labsl_hash -labsl_city -labsl_low_level_hash -labsl_hashtablez_sampler -labsl_statusor -labsl_status -labsl_cord -labsl_cordz_info -labsl_cord_internal -labsl_cordz_functions -labsl_exponential_biased -labsl_cordz_handle -labsl_crc_cord_state -labsl_crc32c -labsl_crc_internal -labsl_crc_cpu_detect -labsl_bad_optional_access -labsl_str_format_internal -labsl_strerror -labsl_synchronization -labsl_graphcycles_internal -labsl_kernel_timeout_internal -labsl_stacktrace -labsl_symbolize -labsl_debugging_internal -labsl_demangle_internal -labsl_malloc_internal -labsl_time -labsl_civil_time -labsl_time_zone -labsl_bad_variant_access -lutf8_validity -lutf8_range -labsl_strings -labsl_string_view -labsl_strings_internal -labsl_base -labsl_spinlock_wait -labsl_int128 -labsl_throw_delegate -labsl_raw_logging_internal -labsl_log_severity
In file included from <stdin>:1:
In file included from /opt/homebrew/include/google/protobuf/message.h:95:
In file included from /opt/homebrew/include/google/protobuf/stubs/common.h:20:
In file included from /opt/homebrew/include/absl/strings/string_view.h:39:
In file included from /opt/homebrew/include/absl/base/attributes.h:37:
In file included from /opt/homebrew/include/absl/base/config.h:86:
/opt/homebrew/include/absl/base/policy_checks.h:79:2: error: "C++ versions less than C++14 are not supported."
#error "C++ versions less than C++14 are not supported."
 ^
1 error generated.
------------------------- ANTICONF ERROR ---------------------------
Configuration failed because protobuf was not found. Try installing:
 * deb: libprotobuf-dev (Debian, Ubuntu, etc)
 * rpm: protobuf-devel (Fedora, EPEL)
 * csw: protobuf_dev (Solaris)
 * brew: protobuf (OSX)
If protobuf is already installed, check that 'pkg-config' is in your
PATH and PKG_CONFIG_PATH contains a protobuf.pc file. If pkg-config
is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:
R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'
--------------------------------------------------------------------
ERROR: configuration failed for package ‘protolite’
* removing ‘/Users/cantaslicukur/nasa-hello-world/renv/staging/1/protolite’
install of package 'protolite' failed [error code 1]
Traceback (most recent calls last):
13: renv::restore()
12: records <- renv_restore_run_actions(project, diff, current, lockfile, rebuild) at restore.R#154
11: renv_install_impl(records) at restore.R#182
10: if (staged)
      renv_install_staged(records)
    else
      renv_install_default(records) at install.R#236
 9: renv_install_default(records) at install.R#256
 8: handler(package, renv_install_package(record)) at install.R#359
 7: handler(package, renv_install_package(record)) at install.R#359
 6: withCallingHandlers(
      renv_install_package_impl(record),
      error = function(e) writef("FAILED")
    ) at install.R#392
 5: withCallingHandlers(
      renv_install_package_impl(record),
      error = function(e) writef("FAILED")
    ) at install.R#392
 4: if (copyable)
      renv_file_copy(path, installpath, overwrite = TRUE)
    else
      r_cmd_install(package, path) at install.R#597
 3: if (!identical(status, 0L))
      r_exec_error(package, output, "install", status) at r.R#230
 2: abort(all) at r.R#48
 1: stop(fallback) at abort.R#44

Where the ANTICONF ERROR is actually misleading because the error above actually states that "C++ versions less than C++14 are not supported.". So, I've googled it and added CXXFLAGS += -std=c++14 to .R/Makevars.

Now the error is different:

Error: Error installing package 'protolite':
=====================================

* installing *source* package ‘protolite’ ...
** package ‘protolite’ successfully unpacked and MD5 sums checked
** using staged installation
Found pkg-config cflags and libs!
Using PKG_CFLAGS=-DPROTOBUF_USE_DLLS -Wno-float-conversion -Wno-implicit-float-conversion -Wno-implicit-int-float-conversion -Wno-unknown-warning-option -DNOMINMAX -I/opt/homebrew/Cellar/protobuf/25.2/include -I/opt/homebrew/Cellar/abseil/20230802.1/include
Using PKG_LIBS=-L/opt/homebrew/Cellar/protobuf/25.2/lib -L/opt/homebrew/Cellar/abseil/20230802.1/lib -lprotobuf -labsl_log_internal_check_op -labsl_leak_check -labsl_die_if_null -labsl_log_internal_conditions -labsl_log_internal_message -labsl_examine_stack -labsl_log_internal_format -labsl_log_internal_proto -labsl_log_internal_nullguard -labsl_log_internal_log_sink_set -labsl_log_sink -labsl_log_entry -labsl_flags -labsl_flags_internal -labsl_flags_marshalling -labsl_flags_reflection -labsl_flags_private_handle_accessor -labsl_flags_commandlineflag -labsl_flags_commandlineflag_internal -labsl_flags_config -labsl_flags_program_name -labsl_log_initialize -labsl_log_globals -labsl_log_internal_globals -labsl_raw_hash_set -labsl_hash -labsl_city -labsl_low_level_hash -labsl_hashtablez_sampler -labsl_statusor -labsl_status -labsl_cord -labsl_cordz_info -labsl_cord_internal -labsl_cordz_functions -labsl_exponential_biased -labsl_cordz_handle -labsl_crc_cord_state -labsl_crc32c -labsl_crc_internal -labsl_crc_cpu_detect -labsl_bad_optional_access -labsl_str_format_internal -labsl_strerror -labsl_synchronization -labsl_graphcycles_internal -labsl_kernel_timeout_internal -labsl_stacktrace -labsl_symbolize -labsl_debugging_internal -labsl_demangle_internal -labsl_malloc_internal -labsl_time -labsl_civil_time -labsl_time_zone -labsl_bad_variant_access -lutf8_validity -lutf8_range -labsl_strings -labsl_string_view -labsl_strings_internal -labsl_base -labsl_spinlock_wait -labsl_int128 -labsl_throw_delegate -labsl_raw_logging_internal -labsl_log_severity
Using libprotoc 25.2 from /opt/homebrew/bin/protoc
Warning: protoc version libprotoc 25.2 might not match libproto version 25.2.0.
** libs
using C++ compiler: ‘Apple clang version 15.0.0 (clang-1500.1.0.2.5)’
using C++11
using SDK: ‘’
clang++ -arch arm64 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -DPROTOBUF_USE_DLLS -Wno-float-conversion -Wno-implicit-float-conversion -Wno-implicit-int-float-conversion -Wno-unknown-warning-option -DNOMINMAX I'/Users/cantaslicukur/nasa-hello-world/renv/staging/1/Rcpp/include' -I/opt/homebrew/include -I/opt/homebrew/opt/libomp/include -Xclang -fopenmp -std=c++14 -I/opt/homebrew/opt/libxml2/include    -fPIC  -falign-functions=64 -Wall -g -O2  -c RcppExports.cpp -o RcppExports.o
clang++ -arch arm64 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -DPROTOBUF_USE_DLLS -Wno-float-conversion -Wno-implicit-float-conversion -Wno-implicit-int-float-conversion -Wno-unknown-warning-option -DNOMINMAX -I/opt/homebrew/Cellar/protobuf/25.2/include -I/opt/homebrew/Cellar/abseil/20230802.1/include -DUSENEWAPI -I'/Users/cantaslicukur/nasa-hello-world/renv/staging/1/Rcpp/include' -I/opt/homebrew/include -I/opt/homebrew/opt/libomp/include -Xclang -fopenmp -std=c++14 -I/opt/homebrew/opt/libxml2/include    -fPIC  -falign-functions=64 -Wall -g -O2  -c geobuf.cpp -o geobuf.o
In file included from geobuf.cpp:1:
In file included from ./geobuf.pb.h:26:
In file included from /opt/homebrew/Cellar/protobuf/25.2/include/google/protobuf/io/coded_stream.h:111:
In file included from /opt/homebrew/Cellar/abseil/20230802.1/include/absl/strings/cord.h:78:
In file included from /opt/homebrew/Cellar/abseil/20230802.1/include/absl/container/inlined_vector.h:53:
In file included from /opt/homebrew/Cellar/abseil/20230802.1/include/absl/container/internal/inlined_vector.h:30:
In file included from /opt/homebrew/Cellar/abseil/20230802.1/include/absl/container/internal/compressed_tuple.h:40:
/opt/homebrew/Cellar/abseil/20230802.1/include/absl/utility/utility.h:164:12: error: no member named 'in_place_t' in namespace 'std'
using std::in_place_t;
      ~~~~~^
/opt/homebrew/Cellar/abseil/20230802.1/include/absl/utility/utility.h:165:12: error: no member named 'in_place' in namespace 'std'
using std::in_place;
      ~~~~~^
/opt/homebrew/Cellar/abseil/20230802.1/include/absl/utility/utility.h:181:12: error: no member named 'in_place_type' in namespace 'std'
using std::in_place_type;
      ~~~~~^
/opt/homebrew/Cellar/abseil/20230802.1/include/absl/utility/utility.h:182:12: error: no member named 'in_place_type_t' in namespace 'std'
using std::in_place_type_t;
      ~~~~~^
/opt/homebrew/Cellar/abseil/20230802.1/include/absl/utility/utility.h:198:12: error: no member named 'in_place_index' in namespace 'std'
using std::in_place_index;
      ~~~~~^
/opt/homebrew/Cellar/abseil/20230802.1/include/absl/utility/utility.h:199:12: error: no member named 'in_place_index_t' in namespace 'std'
using std::in_place_index_t;
      ~~~~~^
In file included from geobuf.cpp:1:
In file included from ./geobuf.pb.h:26:
In file included from /opt/homebrew/Cellar/protobuf/25.2/include/google/protobuf/io/coded_stream.h:111:
In file included from /opt/homebrew/Cellar/abseil/20230802.1/include/absl/strings/cord.h:78:
In file included from /opt/homebrew/Cellar/abseil/20230802.1/include/absl/container/inlined_vector.h:53:
In file included from /opt/homebrew/Cellar/abseil/20230802.1/include/absl/container/internal/inlined_vector.h:30:
/opt/homebrew/Cellar/abseil/20230802.1/include/absl/container/internal/compressed_tuple.h:89:36: error: no type named 'in_place_t' in namespace 'absl'
  explicit constexpr Storage(absl::in_place_t, V&& v)
                             ~~~~~~^
/opt/homebrew/Cellar/abseil/20230802.1/include/absl/container/internal/compressed_tuple.h:102:36: error: no type named 'in_place_t' in namespace 'absl'
  explicit constexpr Storage(absl::in_place_t, V&& v)
                             ~~~~~~^
/opt/homebrew/Cellar/abseil/20230802.1/include/absl/container/internal/compressed_tuple.h:125:48: error: no type named 'in_place_t' in namespace 'absl'
  explicit constexpr CompressedTupleImpl(absl::in_place_t, Vs&&... args)
                                         ~~~~~~^
/opt/homebrew/Cellar/abseil/20230802.1/include/absl/container/internal/compressed_tuple.h:126:24: error: no member named 'in_place' in namespace 'absl'; did you mean 'isspace'?
      : Storage<Ts, I>(absl::in_place, absl::forward<Vs>(args))... {}
                       ^~~~~~~~~~~~~~
                       isspace
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_ctype.h:267:1: note: 'isspace' declared here
isspace(int _c)
^
In file included from geobuf.cpp:1:
In file included from ./geobuf.pb.h:26:
In file included from /opt/homebrew/Cellar/protobuf/25.2/include/google/protobuf/io/coded_stream.h:111:
In file included from /opt/homebrew/Cellar/abseil/20230802.1/include/absl/strings/cord.h:78:
In file included from /opt/homebrew/Cellar/abseil/20230802.1/include/absl/container/inlined_vector.h:53:
In file included from /opt/homebrew/Cellar/abseil/20230802.1/include/absl/container/internal/inlined_vector.h:30:
/opt/homebrew/Cellar/abseil/20230802.1/include/absl/container/internal/compressed_tuple.h:137:48: error: no type named 'in_place_t' in namespace 'absl'
  explicit constexpr CompressedTupleImpl(absl::in_place_t, Vs&&... args)
                                         ~~~~~~^
/opt/homebrew/Cellar/abseil/20230802.1/include/absl/container/internal/compressed_tuple.h:138:31: error: no member named 'in_place' in namespace 'absl'; did you mean 'isspace'?
      : Storage<Ts, I, false>(absl::in_place, absl::forward<Vs>(args))... {}
                              ^~~~~~~~~~~~~~
                              isspace
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_ctype.h:267:1: note: 'isspace' declared here
isspace(int _c)
^
In file included from geobuf.cpp:1:
In file included from ./geobuf.pb.h:26:
In file included from /opt/homebrew/Cellar/protobuf/25.2/include/google/protobuf/io/coded_stream.h:111:
In file included from /opt/homebrew/Cellar/abseil/20230802.1/include/absl/strings/cord.h:78:
In file included from /opt/homebrew/Cellar/abseil/20230802.1/include/absl/container/inlined_vector.h:53:
In file included from /opt/homebrew/Cellar/abseil/20230802.1/include/absl/container/internal/inlined_vector.h:30:
/opt/homebrew/Cellar/abseil/20230802.1/include/absl/container/internal/compressed_tuple.h:224:46: error: no member named 'in_place' in namespace 'absl'; did you mean 'isspace'?
      : CompressedTuple::CompressedTupleImpl(absl::in_place, base...) {}
                                             ^~~~~~~~~~~~~~
                                             isspace
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_ctype.h:267:1: note: 'isspace' declared here
isspace(int _c)
^
In file included from geobuf.cpp:1:
In file included from ./geobuf.pb.h:26:
In file included from /opt/homebrew/Cellar/protobuf/25.2/include/google/protobuf/io/coded_stream.h:111:
In file included from /opt/homebrew/Cellar/abseil/20230802.1/include/absl/strings/cord.h:78:
In file included from /opt/homebrew/Cellar/abseil/20230802.1/include/absl/container/inlined_vector.h:53:
In file included from /opt/homebrew/Cellar/abseil/20230802.1/include/absl/container/internal/inlined_vector.h:30:
/opt/homebrew/Cellar/abseil/20230802.1/include/absl/container/internal/compressed_tuple.h:236:46: error: no member named 'in_place' in namespace 'absl'; did you mean 'isspace'?
      : CompressedTuple::CompressedTupleImpl(absl::in_place,
                                             ^~~~~~~~~~~~~~
                                             isspace
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_ctype.h:267:1: note: 'isspace' declared here
isspace(int _c)
^
In file included from geobuf.cpp:1:
In file included from ./geobuf.pb.h:26:
In file included from /opt/homebrew/Cellar/protobuf/25.2/include/google/protobuf/io/coded_stream.h:111:
In file included from /opt/homebrew/Cellar/abseil/20230802.1/include/absl/strings/cord.h:79:
In file included from /opt/homebrew/Cellar/abseil/20230802.1/include/absl/crc/internal/crc_cord_state.h:23:
/opt/homebrew/Cellar/abseil/20230802.1/include/absl/crc/crc32c.h:184:35: error: 'FormatSpecTemplate' is unavailable: Format string is not constexpr.
  return os << absl::StreamFormat("%08x", static_cast<uint32_t>(crc));
                                  ^
/opt/homebrew/Cellar/abseil/20230802.1/include/absl/strings/internal/str_format/bind.h:128:3: note: 'FormatSpecTemplate' has been explicitly marked unavailable here
  FormatSpecTemplate(...)  // NOLINT
  ^
In file included from geobuf.cpp:1:
In file included from ./geobuf.pb.h:26:
In file included from /opt/homebrew/Cellar/protobuf/25.2/include/google/protobuf/io/coded_stream.h:111:
In file included from /opt/homebrew/Cellar/abseil/20230802.1/include/absl/strings/cord.h:80:
In file included from /opt/homebrew/Cellar/abseil/20230802.1/include/absl/functional/function_ref.h:54:
In file included from /opt/homebrew/Cellar/abseil/20230802.1/include/absl/functional/internal/function_ref.h:23:
In file included from /opt/homebrew/Cellar/abseil/20230802.1/include/absl/functional/any_invocable.h:42:
/opt/homebrew/Cellar/abseil/20230802.1/include/absl/functional/internal/any_invocable.h:380:28: error: no member named 'in_place_type_t' in namespace 'absl'
struct IsInPlaceType<absl::in_place_type_t<T>> : std::true_type {};
                     ~~~~~~^
/opt/homebrew/Cellar/abseil/20230802.1/include/absl/functional/internal/any_invocable.h:380:44: error: 'T' does not refer to a value
struct IsInPlaceType<absl::in_place_type_t<T>> : std::true_type {};
                                           ^
/opt/homebrew/Cellar/abseil/20230802.1/include/absl/functional/internal/any_invocable.h:379:17: note: declared here
template <class T>
                ^
/opt/homebrew/Cellar/abseil/20230802.1/include/absl/functional/internal/any_invocable.h:380:46: error: expected unqualified-id
struct IsInPlaceType<absl::in_place_type_t<T>> : std::true_type {};
                                             ^
/opt/homebrew/Cellar/abseil/20230802.1/include/absl/functional/internal/any_invocable.h:476:27: error: no template named 'in_place_type_t' in namespace 'absl'
  explicit CoreImpl(absl::in_place_type_t<QualTRef>, Args&&... args) {
                    ~~~~~~^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make: *** [geobuf.o] Error 1
ERROR: compilation failed for package ‘protolite’
* removing ‘/Users/cantaslicukur/nasa-hello-world/renv/staging/1/protolite’
install of package 'protolite' failed [error code 1]
Traceback (most recent calls last):
13: renv::restore()
12: records <- renv_restore_run_actions(project, diff, current, lockfile, rebuild) at restore.R#154
11: renv_install_impl(records) at restore.R#182
10: if (staged)
      renv_install_staged(records)
    else
      renv_install_default(records) at install.R#236
 9: renv_install_default(records) at install.R#256
 8: handler(package, renv_install_package(record)) at install.R#359
 7: handler(package, renv_install_package(record)) at install.R#359
 6: withCallingHandlers(
      renv_install_package_impl(record),
      error = function(e) writef("FAILED")
    ) at install.R#392
 5: withCallingHandlers(
      renv_install_package_impl(record),
      error = function(e) writef("FAILED")
    ) at install.R#392
 4: if (copyable)
      renv_file_copy(path, installpath, overwrite = TRUE)
    else
      r_cmd_install(package, path) at install.R#597
 3: if (!identical(status, 0L))
      r_exec_error(package, output, "install", status) at r.R#230
 2: abort(all) at r.R#48
 1: stop(fallback) at abort.R#44

Any suggestions would be greatly appreciated. Thank you so much for this package!

can-taslicukur commented 9 months ago

Ok, I've actually found a solution right after I posted this issue 🤦

All of the errors in the second error are generated from /opt/homebrew/Cellar/abseil/ so I've googled "brew abseil" and this github issue came up which states that "abseil is built against c++17". Which also makes the error message in the first installation error invalid.

So I've replaced CXXFLAGS += -std=c++14 in .R/Makevars with CXXFLAGS += -std=c++17

Moral of the story: Building from source using Apple Silicon is extremely painful.

jeroen commented 9 months ago

I can't reproduce these trouble. I just tried on my M1 box brew install protobuf and then installing protolite, and it all just works without warnings or errors.

Perhaps you need to brew upgrade ?

Are you installing the most recent version of protolite from CRAN?

can-taslicukur commented 9 months ago

it is 2.1 in the renv.lock of the project I was running renv::restore(). I will try brew upgrade thank you so much for the advice!

jeroen commented 9 months ago

You probably can fix the problem by installing the latest version of protolite instead (there are no breaking changes).

can-taslicukur commented 9 months ago

Yes! Can confirm that the latest version can install without the need to add CXXFLAGS += -std=c++17 to .R/Makevars. Tested it by commenting this line in .R/Makevars and running install.packages("protolite")

r$> install.packages("protolite")
# Downloading packages -------------------------------------------------------
- Downloading protolite from RSPM ...           OK [file is up to date]
Successfully downloaded 1 package in 2.3 seconds.

The following package(s) will be installed:
- protolite [2.3.0]
These packages will be installed into "~/project/renv/library/R-4.3/aarch64-apple-darwin20".

Do you want to proceed? [Y/n]: y

# Installing packages --------------------------------------------------------
- Installing protolite ...                      OK [built from source and cached in 13s]
Successfully installed 1 package in 13 seconds.