-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Abseil should install w/ the correct base/options.h #696
Comments
I just found https://abseil.io/docs/cpp/guides/options, which suggests that users are supposed to patch the
That's a bit difficult to use. It makes the following (typical) workflow do the wrong thing.
This is basically the normal workflow for compiling and installing software, but using this workflow, the installed Feature request (bug?)I think Abseil's cmake install should install the Is this possible? |
A suggestion: generate (or modify, but that might be harder) You can even compile a small C++ program, detect if https://cmake.org/cmake/help/v3.5/module/CheckCXXSourceCompiles.html |
This is the single most often reported issue on our issue tracker, so in light of that, we should take it as a signal that we might either be getting this wrong. According to our current position, it is fine to install Abseil, but you must build your program with the exact same set of ABI affecting compile options that were used to build the installed Abseil. Since GCC defaults to C++14 (and you used this default when you installed Abseil), but you then tried to build your program with C++17, the build failed. This is currently not something we support. It's fine to use an installed, pre-compiled version of Abseil. This will prevent you from rebuilding it every time you rebuild your program. But regardless of what options are specified in the options file, you must still specify the same ABI affecting compile options for your own program. The options file really only prevents you from having to define things on the command line, and prevents you from redefining them. I think you are trying to test that your build works in multiple C++ standard modes? If so, you are still going to need to recompile Abseil for each build (but it is fine to use the install step). I doubt that Abseil is actually unique in the sense that As long as you understand this principle, Maybe our documentation is lacking about this issue. Currently we do have https://github.com/abseil/abseil-cpp/blob/master/FAQ.md#how-to-i-set-the-c-dialect-used-to-build-abseil and https://github.com/abseil/abseil-cpp/blob/master/FAQ.md#what-is-abi-and-why-dont-you-recommend-using-a-pre-compiled-version-of-abseil. And it is possible the the options file has added to the confusion. Let us know what you think. |
Thanks for the detailed and thoughtful reply, @derekmauro. As a library maintainer for many years myself, I'm completely on board with Abseil's principles. I certainly wouldn't want or expect Abseil to make any ABI guarantees -- we do not make any ABI guarantees in our project either. But that said, practically speaking, most things don't cause ABI breaks. Even changing As a user of Abseil, it seems like Abseil is going out of its way to make things difficult for "make install" users by installing a header that says "Inspect language version and choose option A or B" along with a compiled artifact that says "Only option A". That mismatch is what caused my confusion, and perhaps other's confusion as well, for example, probably #634 too. Following C++ tradition, I think Abseil may have gotten the default wrong for these options 😄 I agree that If Abseil decides to stick w/ the current policy/defaults/behavior, it would at least be good to update the documentation at https://abseil.io/docs/cpp/tools/cmake-installs to mention that "make install" must also patch the |
Agreed. We use Abseil too, and we also use several C++ CMake projects which are either C++11 or C++17. |
FWIW, I think #820 is a duplicate of this bug. |
Note that this is surprising folks in weird places, e.g. conan-io/conan-center-index#5766 |
This PR adds support for `google-cloud-cpp` to the Conda files. Probably the most difficult change to grok is the change to compile with C++17 when using Conda: - Conda defaults all its builds to C++17, [this bug](conda/conda-build#3375) goes into some detail as to why. - Arrow defaults to C++11 if no `CMAKE_CXX_STANDARD` argument is provided. - Abseil's ABI changes when used from C++11 vs. C++17, see abseil/abseil-cpp#696 - Therefore, one must compile with C++17 to use Abseil in Conda. - And because `google-cloud-cpp` has a direct dependency on Abseil, exposed through the headers, one must use C++17 to use `google-cloud-cpp` too. Closes #11916 from coryan/ARROW-14506-add-google-cloud-cpp-to-conda-files Lead-authored-by: Uwe L. Korn <uwe.korn@quantco.com> Co-authored-by: Carlos O'Ryan <coryan@google.com> Signed-off-by: Antoine Pitrou <antoine@python.org>
Abseil already adds the abseil-cpp/CMake/AbseilHelpers.cmake Lines 259 to 263 in c2ef703
I would argue that when compiled with C++ >= 17, Abseil should set this property to Pros If Abseil is compiled with C++ >= 17 it is always consumed with C++ >= 17. It will work most of the time, though it may be surprising for folks that their code is compiled with a newer C++ standard. Cons If Abseil is compiled with C++11 but consumed with C++ >= 17 things still break. |
I think that makes sense. So basically something like this (untested)?
|
Basically. Note that many compilers default to C++14, so even if https://gcc.gnu.org/gcc-11/changes.html I think you will want to write a compile test to determine the effective C++ version. See: https://cmake.org/cmake/help/latest/command/try_compile.html |
This PR adds support for `google-cloud-cpp` to the Conda files. Probably the most difficult change to grok is the change to compile with C++17 when using Conda: - Conda defaults all its builds to C++17, [this bug](conda/conda-build#3375) goes into some detail as to why. - Arrow defaults to C++11 if no `CMAKE_CXX_STANDARD` argument is provided. - Abseil's ABI changes when used from C++11 vs. C++17, see abseil/abseil-cpp#696 - Therefore, one must compile with C++17 to use Abseil in Conda. - And because `google-cloud-cpp` has a direct dependency on Abseil, exposed through the headers, one must use C++17 to use `google-cloud-cpp` too. Closes apache#11916 from coryan/ARROW-14506-add-google-cloud-cpp-to-conda-files Lead-authored-by: Uwe L. Korn <uwe.korn@quantco.com> Co-authored-by: Carlos O'Ryan <coryan@google.com> Signed-off-by: Antoine Pitrou <antoine@python.org>
This PR adds support for `google-cloud-cpp` to the Conda files. Probably the most difficult change to grok is the change to compile with C++17 when using Conda: - Conda defaults all its builds to C++17, [this bug](conda/conda-build#3375) goes into some detail as to why. - Arrow defaults to C++11 if no `CMAKE_CXX_STANDARD` argument is provided. - Abseil's ABI changes when used from C++11 vs. C++17, see abseil/abseil-cpp#696 - Therefore, one must compile with C++17 to use Abseil in Conda. - And because `google-cloud-cpp` has a direct dependency on Abseil, exposed through the headers, one must use C++17 to use `google-cloud-cpp` too. Closes apache#11916 from coryan/ARROW-14506-add-google-cloud-cpp-to-conda-files Lead-authored-by: Uwe L. Korn <uwe.korn@quantco.com> Co-authored-by: Carlos O'Ryan <coryan@google.com> Signed-off-by: Antoine Pitrou <antoine@python.org>
This PR adds support for `google-cloud-cpp` to the Conda files. Probably the most difficult change to grok is the change to compile with C++17 when using Conda: - Conda defaults all its builds to C++17, [this bug](conda/conda-build#3375) goes into some detail as to why. - Arrow defaults to C++11 if no `CMAKE_CXX_STANDARD` argument is provided. - Abseil's ABI changes when used from C++11 vs. C++17, see abseil/abseil-cpp#696 - Therefore, one must compile with C++17 to use Abseil in Conda. - And because `google-cloud-cpp` has a direct dependency on Abseil, exposed through the headers, one must use C++17 to use `google-cloud-cpp` too. Closes apache#11916 from coryan/ARROW-14506-add-google-cloud-cpp-to-conda-files Lead-authored-by: Uwe L. Korn <uwe.korn@quantco.com> Co-authored-by: Carlos O'Ryan <coryan@google.com> Signed-off-by: Antoine Pitrou <antoine@python.org>
Change `absl/base/options.h` at install time to reflect the ABI used to compile the libraries, i.e., if Abseil was compiled with C++ >= 17 then the `ABSL_OPTION_USE_STD_*` macros are set to `1`, because then the C++ 17 types are embedded in the ABI of the installed artifacts. Likewise, set the `target_compile_features()` of Abseil libraries to reflect the C++ version used to compile them. If they the Abseil libraries are compiled with C++ >= 17, then all downstream dependencies must also be compiled with C++ >= 17. Fixes abseil#696 PiperOrigin-RevId: 472538165 Change-Id: Ic9e346ebe277c882a18ad96e1918c9e3511c91c3
We're using Abseil with our https://github.com/googleapis/google-cloud-cpp project. In order to support our CMake build, we compile and install Abseil in our docker images, so that our CMake builds can simply find and use the installed Abseil libraries. Here's how we compile and install Abseil in our docker images.
https://github.com/googleapis/google-cloud-cpp/blob/19d4a7eaf73eeca16278f6ad4852a9340e1a8f37/ci/kokoro/docker/Dockerfile.fedora-install#L55-L68
This has been working okay, until today, when we tried to use
absl::StrSplit
, which usesabsl::string_view
, and we got an error linking in our C++17 build (build log):It looks like the problem is that
ABSL_OPTION_USE_STD_STRING_VIEW
defaults to2
(link), which says to usestd::string_view
if >= C++17, otherwise use Abseil's customabsl::string_view
. The issue is that we compile and install Abseil using some default compiler options (c++11 in this case), and we don't explicitly setABSL_OPTION_USE_STD_STRING_VIEW
. However ,when we link against the installed library in a C++17 build, we start usingstd::string_view
, and then obviously the link fails.Question: Are we holding it wrong? Have we installed Abseil wrong? Is there something we should be doing differently to solve this problem? We installed Abseil the way we thought we should, but I wouldn't be surprised if I did that wrong.
Some general thoughts about a solution
It seems like
ABSL_OPTION_USE_STD_STRING_VIEW=2
is never the right thing for an installed Abseil. The installed binary artifacts were compiled with exactly one of Abseil's customabsl::string_view
ORstd::string
, so having the installedbase/options.h
header default to choosing one of those doesn't seem right.Could Abseil install a
base/options.h
that's configured w/ the options matching the way the binary artifacts were compiled/installed?NOTE: In this issue I'm referring to
absl::string_view
, but the same issue will arise withabsl::any
,absl::optional
, etc. So whatever solution we come up with here, should likely apply to all of those./cc: @coryan @derekmauro @vslashg
The text was updated successfully, but these errors were encountered: