googleapis / google-cloud-cpp

C++ Client Libraries for Google Cloud Services
https://cloud.google.com/
Apache License 2.0
530 stars 353 forks source link

Can't build with MinGW: BCRYPT_SHA256_ALG_HANDLE isn't defined #14436

Closed kou closed 1 day ago

kou commented 3 days ago

Does this issue affect the google-cloud-cpp project? If the problem is with the Google Cloud service exposed by the google-cloud-cpp libraries instead of the client libraries themselves, you may consider opening a support request instead. The google-cloud-cpp developers cannot help you troubleshoot problems with the service itself.

Yes.

What component of google-cloud-cpp is this related to? For example, is this related to bigtable (i.e., something in google/cloud/bigtable), or GCS (i.e., something in google/cloud/storage)?

Describe the bug A clear and concise description of what the bug is.

I don't think that this is a bug of google-cloud-cpp but the latest release can't be built with MinGW-w64 because MinGW-w64's bcrypt.h doesn't provide BCRYPT_SHA256_ALG_HANDLE. See also: https://github.com/mingw-w64/mingw-w64/issues/49

So we can't build the latest google-cloud-cpp with MinGW-w64. Here are build error logs in apache/arrow:

With GCC: https://github.com/apache/arrow/actions/runs/9784972906/job/27017012557#step:7:1038

FAILED: google/cloud/CMakeFiles/google_cloud_cpp_common.dir/internal/sha256_hash.cc.obj 
D:\a\_temp\msys64\mingw64\bin\ccache.exe D:\a\_temp\msys64\mingw64\bin\c++.exe -DWIN32_LEAN_AND_MEAN -ID:/a/arrow/arrow/build/cpp/google_cloud_cpp_ep-prefix/src/google_cloud_cpp_ep -isystem D:/a/arrow/arrow/build/cpp/google_cloud_cpp_ep-prefix/src/google_cloud_cpp_ep-build -fdiagnostics-color=always -fPIC -O3 -DNDEBUG -O2 -ftree-vectorize -Wall -Wextra -Wconversion -Wno-sign-conversion -MD -MT google/cloud/CMakeFiles/google_cloud_cpp_common.dir/internal/sha256_hash.cc.obj -MF google\cloud\CMakeFiles\google_cloud_cpp_common.dir\internal\sha256_hash.cc.obj.d -o google/cloud/CMakeFiles/google_cloud_cpp_common.dir/internal/sha256_hash.cc.obj -c D:/a/arrow/arrow/build/cpp/google_cloud_cpp_ep-prefix/src/google_cloud_cpp_ep/google/cloud/internal/sha256_hash.cc
D:/a/arrow/arrow/build/cpp/google_cloud_cpp_ep-prefix/src/google_cloud_cpp_ep/google/cloud/internal/sha256_hash.cc: In function 'google::cloud::v2_26::internal::Sha256Type google::cloud::v2_26::internal::{anonymous}::Sha256Hash(const void*, std::size_t)':
D:/a/arrow/arrow/build/cpp/google_cloud_cpp_ep-prefix/src/google_cloud_cpp_ep/google/cloud/internal/sha256_hash.cc:33:14: error: 'BCRYPT_SHA256_ALG_HANDLE' was not declared in this scope; did you mean 'BCRYPT_ALG_HANDLE'?
   33 |   BCryptHash(BCRYPT_SHA256_ALG_HANDLE, nullptr, 0,
      |              ^~~~~~~~~~~~~~~~~~~~~~~~
      |              BCRYPT_ALG_HANDLE
D:/a/arrow/arrow/build/cpp/google_cloud_cpp_ep-prefix/src/google_cloud_cpp_ep/google/cloud/internal/sha256_hash.cc:33:3: error: 'BCryptHash' was not declared in this scope; did you mean 'BCryptSignHash'?
   33 |   BCryptHash(BCRYPT_SHA256_ALG_HANDLE, nullptr, 0,
      |   ^~~~~~~~~~
      |   BCryptSignHash

With clang: https://github.com/apache/arrow/actions/runs/9784972906/job/27017012746#step:7:977

FAILED: google/cloud/CMakeFiles/google_cloud_cpp_common.dir/internal/sha256_hash.cc.obj 
D:\a\_temp\msys64\clang64\bin\ccache.exe D:\a\_temp\msys64\clang64\bin\c++.exe -DWIN32_LEAN_AND_MEAN -ID:/a/arrow/arrow/build/cpp/google_cloud_cpp_ep-prefix/src/google_cloud_cpp_ep -isystem D:/a/arrow/arrow/build/cpp/google_cloud_cpp_ep-prefix/src/google_cloud_cpp_ep-build -Qunused-arguments -fcolor-diagnostics -fPIC -O3 -DNDEBUG -O2 -Wall -Wextra -Wconversion -Wno-sign-conversion -MD -MT google/cloud/CMakeFiles/google_cloud_cpp_common.dir/internal/sha256_hash.cc.obj -MF google\cloud\CMakeFiles\google_cloud_cpp_common.dir\internal\sha256_hash.cc.obj.d -o google/cloud/CMakeFiles/google_cloud_cpp_common.dir/internal/sha256_hash.cc.obj -c D:/a/arrow/arrow/build/cpp/google_cloud_cpp_ep-prefix/src/google_cloud_cpp_ep/google/cloud/internal/sha256_hash.cc
D:/a/arrow/arrow/build/cpp/google_cloud_cpp_ep-prefix/src/google_cloud_cpp_ep/google/cloud/internal/sha256_hash.cc:33:14: error: use of undeclared identifier 'BCRYPT_SHA256_ALG_HANDLE'
   33 |   BCryptHash(BCRYPT_SHA256_ALG_HANDLE, nullptr, 0,
      |              ^
1 error generated.
[33/203] Building CXX object google/cloud/CMakeFiles/google_cloud_cpp_common.dir/internal/sha256_hmac.cc.obj
FAILED: google/cloud/CMakeFiles/google_cloud_cpp_common.dir/internal/sha256_hmac.cc.obj 
D:\a\_temp\msys64\clang64\bin\ccache.exe D:\a\_temp\msys64\clang64\bin\c++.exe -DWIN32_LEAN_AND_MEAN -ID:/a/arrow/arrow/build/cpp/google_cloud_cpp_ep-prefix/src/google_cloud_cpp_ep -isystem D:/a/arrow/arrow/build/cpp/google_cloud_cpp_ep-prefix/src/google_cloud_cpp_ep-build -Qunused-arguments -fcolor-diagnostics -fPIC -O3 -DNDEBUG -O2 -Wall -Wextra -Wconversion -Wno-sign-conversion -MD -MT google/cloud/CMakeFiles/google_cloud_cpp_common.dir/internal/sha256_hmac.cc.obj -MF google\cloud\CMakeFiles\google_cloud_cpp_common.dir\internal\sha256_hmac.cc.obj.d -o google/cloud/CMakeFiles/google_cloud_cpp_common.dir/internal/sha256_hmac.cc.obj -c D:/a/arrow/arrow/build/cpp/google_cloud_cpp_ep-prefix/src/google_cloud_cpp_ep/google/cloud/internal/sha256_hmac.cc
D:/a/arrow/arrow/build/cpp/google_cloud_cpp_ep-prefix/src/google_cloud_cpp_ep/google/cloud/internal/sha256_hmac.cc:41:14: error: use of undeclared identifier 'BCRYPT_HMAC_SHA256_ALG_HANDLE'
   41 |   BCryptHash(BCRYPT_HMAC_SHA256_ALG_HANDLE,
      |              ^
1 error generated.

To Reproduce Steps to reproduce the behavior:

  1. Build google-cloud-cpp with MinGW-w64
  2. You can see the above error

Expected behavior A clear and concise description of what you expected to happen.

google-cloud-cpp can be built with MinGW-w64.

Operating system: If you are using a Linux distribution please include the name and version of the distribution too.

Windows.

What compiler and version are you using? Please include the output of g++ -v or clang++ -v or the equivalent command-line flag.

https://github.com/apache/arrow/actions/runs/9784972906/job/27017012557#step:7:96

-- The C compiler identification is GNU 14.1.0
-- The CXX compiler identification is GNU 14.1.0

https://github.com/apache/arrow/actions/runs/9784972906/job/27017012746#step:7:96

-- The C compiler identification is Clang 18.1.8
-- The CXX compiler identification is Clang 18.1.8

What version of google-cloud-cpp are you using? Please include the output from git rev-parse HEAD if you are compiling from source, or the version number from the applicable google/cloud/*/version.h file.

https://github.com/googleapis/google-cloud-cpp/releases/tag/v2.26.0

Additional context Add any other context about the problem here.

I haven't tried yet but the following patch may work:

diff --git a/google/cloud/internal/sha256_hash.cc b/google/cloud/internal/sha256_hash.cc
index 1485c7ce45..1157c30a19 100644
--- a/google/cloud/internal/sha256_hash.cc
+++ b/google/cloud/internal/sha256_hash.cc
@@ -30,6 +30,9 @@ namespace {
 Sha256Type Sha256Hash(void const* data, std::size_t count) {
   Sha256Type hash;
 #ifdef _WIN32
+#ifndef BCRYPT_SHA256_ALG_HANDLE
+#define BCRYPT_SHA256_ALG_HANDLE ((BCRYPT_ALG_HANDLE) 0x00000041)
+#endif
   BCryptHash(BCRYPT_SHA256_ALG_HANDLE, nullptr, 0,
              static_cast<PUCHAR>(const_cast<void*>(data)),
              static_cast<ULONG>(count), hash.data(),
diff --git a/google/cloud/internal/sha256_hmac.cc b/google/cloud/internal/sha256_hmac.cc
index 015649fa74..bc2f6ea58c 100644
--- a/google/cloud/internal/sha256_hmac.cc
+++ b/google/cloud/internal/sha256_hmac.cc
@@ -38,6 +38,9 @@ Sha256Type Sha256HmacImpl(absl::Span<T const> key, unsigned char const* data,
                           std::size_t count) {
   Sha256Type hash;
 #ifdef _WIN32
+#ifndef BCRYPT_HMAC_SHA256_ALG_HANDLE
+#define BCRYPT_HMAC_SHA256_ALG_HANDLE ((BCRYPT_ALG_HANDLE) 0x000000b1)
+#endif
   BCryptHash(BCRYPT_HMAC_SHA256_ALG_HANDLE,
              reinterpret_cast<PUCHAR>(const_cast<T*>(key.data())),
              static_cast<ULONG>(key.size()), const_cast<PUCHAR>(data),
coryan commented 3 days ago

Thanks for the detailed bug report and the proposed patch. I cannot think of a better solution at this time.

coryan commented 2 days ago

As you may have noticed, I sent a PR based on your patch. I expect this PR will get a review on Monday. I expect that will get merged and then be part of the next release (v2.27.0) due early in 2024-08.

kou commented 2 days ago

Thanks! apache/arrow will update bundled google-cloud-cpp after the release.

FYI: The next version of MinGW-w64's bcrypt.h will have BCRYPT_*_ALG_HANDLE.