Repository: conan-io/conan-center-index

Issue:
[package] google-cloud-cpp/1.26.1: Segmentation fault on writing object to GBucket
## Package and Environment Details (include every applicable attribute)

- Package Name/Version: **google-cloud-cpp/1.26.1**
- Operating System+version: **Ubuntu 20.04 & Debian 11**
- Compiler+version: **gcc 10 & clang 11**
- Conan version: **conan 1.33.0**
- Python version: **Python 3.8.5**

## Steps to reproduce ##

Testing the basic example of [Google Cloud Platform C++ Client Libraries](https://github.com/googleapis/google-cloud-cpp#quickstart) in Debug or Release mode.

#### conanfile.txt ####

```
[requires]
google-cloud-cpp/1.26.1

[generators]
cmake
```

#### build stage ####

Successfully

#### execution ####

Segmentation fault in calling to `WriteObject` method for `google::cloud::storage::Client` object.

#### call stack ####

```
curl_easy_escape 0x00000000005ce913
google::cloud::storage::v1::internal::CurlHandle::MakeEscapedString curl_handle.h:64
google::cloud::storage::v1::internal::CurlRequestBuilder::AddQueryParameter 0x000000000049f84f
google::cloud::storage::v1::internal::CurlRequestBuilder::AddOption<google::cloud::storage::v1::QuotaUser> curl_request_builder.h:62
google::cloud::storage::v1::internal::GenericRequestBase<google::cloud::storage::v1::internal::UploadChunkRequest, google::cloud::storage::v1::QuotaUser, google::cloud::storage::v1::UserIp>::AddOptionsToHttpRequest<google::cloud::storage::v1::internal::CurlRequestBuilder> generic_request.h:119
google::cloud::storage::v1::internal::GenericRequestBase<google::cloud::storage::v1::internal::UploadChunkRequest, google::cloud::storage::v1::IfNoneMatchEtag, google::cloud::storage::v1::QuotaUser, google::cloud::storage::v1::UserIp>::AddOptionsToHttpRequest<google::cloud::storage::v1::internal::CurlRequestBuilder> generic_request.h:120
google::cloud::storage::v1::internal::GenericRequestBase<google::cloud::storage::v1::internal::UploadChunkRequest, google::cloud::storage::v1::IfMatchEtag, google::cloud::storage::v1::IfNoneMatchEtag, google::cloud::storage::v1::QuotaUser, google::cloud::storage::v1::UserIp>::AddOptionsToHttpRequest<google::cloud::storage::v1::internal::CurlRequestBuilder> generic_request.h:120
google::cloud::storage::v1::internal::GenericRequestBase<google::cloud::storage::v1::internal::UploadChunkRequest, google::cloud::storage::v1::Fields, google::cloud::storage::v1::IfMatchEtag, google::cloud::storage::v1::IfNoneMatchEtag, google::cloud::storage::v1::QuotaUser, google::cloud::storage::v1::UserIp>::AddOptionsToHttpRequest<google::cloud::storage::v1::internal::CurlRequestBuilder> generic_request.h:120
google::cloud::storage::v1::internal::GenericRequestBase<google::cloud::storage::v1::internal::UploadChunkRequest, google::cloud::storage::v1::CustomHeader, google::cloud::storage::v1::Fields, google::cloud::storage::v1::IfMatchEtag, google::cloud::storage::v1::IfNoneMatchEtag, google::cloud::storage::v1::QuotaUser, google::cloud::storage::v1::UserIp>::AddOptionsToHttpRequest<google::cloud::storage::v1::internal::CurlRequestBuilder> generic_request.h:120
google::cloud::storage::v1::internal::CurlClient::SetupBuilder<google::cloud::storage::v1::internal::UploadChunkRequest> 0x000000000044a47a
google::cloud::storage::v1::internal::CurlClient::UploadChunk 0x0000000000433a1a
google::cloud::storage::v1::internal::CurlResumableUploadSession::UploadFinalChunk 0x00000000004a1268
google::cloud::storage::v1::internal::RetryResumableUploadSession::UploadGenericChunk 0x000000000054c347
google::cloud::storage::v1::internal::RetryResumableUploadSession::UploadFinalChunk 0x000000000054cbc5
google::cloud::storage::v1::internal::ObjectWriteStreambuf::FlushFinal 0x0000000000506785
google::cloud::storage::v1::internal::ObjectWriteStreambuf::Close 0x00000000005065ce
google::cloud::storage::v1::ObjectWriteStream::CloseBuf 0x0000000000570e36
google::cloud::storage::v1::ObjectWriteStream::Close 0x000000000057147c
```




Discussion:
Hi, @aruizs . Probably this is an issue for the google-cloud-cpp repository itself. Do you have anything else to think that the error is due to packaging in Conan?
Hi @jgsogo, I'm successfully using the same version of google-cloud-cpp from vcpkg.

By the way, the same issue happens with the new version google-cloud-cpp/1.27.0.

Thanks!
That's a really good point. We should check that we are packaging the same sources (and referring to the same requirements)... IIRC this library had some vendorized dependencies.
I'm running the example locally in Macos and Linux with `google-cloud-cpp/1.27.0` and it works... but it fails for me in GCP (Cloud Run) with a `std::bad_alloc`. I'm trying to find what are the differences between my two builds, I want to think that runtime in cloud-run (gVisor) is not the cause of the failure.

Resolving patch:
diff --git a/recipes/google-cloud-cpp/all/conanfile.py b/recipes/google-cloud-cpp/all/conanfile.py
--- a/recipes/google-cloud-cpp/all/conanfile.py
+++ b/recipes/google-cloud-cpp/all/conanfile.py
@@ -1,9 +1,10 @@
 import os
+import textwrap
 
 from conans import ConanFile, CMake, tools
 from conans.errors import ConanInvalidConfiguration
 
-required_conan_version = ">=1.28.0"
+required_conan_version = ">=1.33.0"
 
 class GoogleCloudCppConan(ConanFile):
     name = "google-cloud-cpp"
@@ -38,10 +39,18 @@ def config_options(self):
     def configure(self):
         if self.options.shared:
             del self.options.fPIC
-        
+    
+    def validate(self):
         if self.settings.os == 'Windows' and self.options.shared:
             raise ConanInvalidConfiguration("Fails to compile for Windows as a DLL")
 
+        if hasattr(self, "settings_build") and tools.cross_building(self):
+            raise ConanInvalidConfiguration("Recipe not prepared for cross-building (yet)")
+
+        if tools.Version(self.version) >= "1.30.0":
+            if self.settings.compiler == 'clang' and tools.Version(self.settings.compiler.version) < "6.0":
+                raise ConanInvalidConfiguration("Clang version must be at least 6.0.")
+
         if self.settings.compiler.cppstd:
             tools.check_min_cppstd(self, 11)
 
@@ -56,13 +65,13 @@ def source(self):
         tools.get(**self.conan_data["sources"][self.version], destination=self._source_subfolder, strip_root=True)
 
     def requirements(self):
-        self.requires('protobuf/3.15.5')
-        self.requires('grpc/1.37.1')
-        self.requires('nlohmann_json/3.9.1')
+        self.requires('protobuf/3.17.1')
+        self.requires('grpc/1.38.0')
+        self.requires('nlohmann_json/3.10.2')
         self.requires('crc32c/1.1.1')
-        self.requires('abseil/20210324.0')
-        self.requires('libcurl/7.75.0')
-        self.requires('openssl/1.1.1k')
+        self.requires('abseil/20210324.2')
+        self.requires('libcurl/7.78.0')
+        self.requires('openssl/1.1.1l')
         # TODO: Add googleapis once it is available in CCI (now it is embedded)
 
     def _configure_cmake(self):
@@ -86,9 +95,24 @@ def _configure_cmake(self):
         self._cmake.configure()
         return self._cmake
 
-    def build(self):
+    def _patch_sources(self):
         for patch in self.conan_data.get("patches", {}).get(self.version, []):
             tools.patch(**patch)
+
+        # Do not override CMAKE_CXX_STANDARD if provided
+        tools.replace_in_file(os.path.join(self._source_subfolder, "CMakeLists.txt"),
+            textwrap.dedent("""\
+                set(CMAKE_CXX_STANDARD
+                    11
+                    CACHE STRING "Configure the C++ standard version for all targets.")"""),
+            textwrap.dedent("""\
+                if(NOT "${CMAKE_CXX_STANDARD}")
+                    set(CMAKE_CXX_STANDARD 11 CACHE STRING "Configure the C++ standard version for all targets.")
+                endif()
+                """))
+
+    def build(self):
+        self._patch_sources()
         cmake = self._configure_cmake()
         cmake.build()
 


Test patch: