Skip to content
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

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

Closed
kou opened this issue Jul 4, 2024 · 3 comments · Fixed by #14437
Closed

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

kou opened this issue Jul 4, 2024 · 3 comments · Fixed by #14437
Assignees
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@kou
Copy link
Contributor

kou commented Jul 4, 2024

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)?

  • google/cloud/internal/sha256_hash.cc
  • google/cloud/internal/sha256_hmac.cc

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: mingw-w64/mingw-w64#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),
@kou kou added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Jul 4, 2024
@coryan
Copy link
Contributor

coryan commented Jul 4, 2024

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

@coryan coryan self-assigned this Jul 4, 2024
kou added a commit to apache/arrow that referenced this issue Jul 5, 2024
### Rationale for this change

`google_cloud_cpp_mocks` depends on `GTest::gmock_main` but it's built without `BUILD_TESTING`. google-cloud-cpp finds GoogleTest only with `BUILD_TESTING`.

### What changes are included in this PR?

The recent google-cloud-cpp doesn't build `google_cloud_cpp_mocks` without `BUILD_TESTING`.

Note that we can't use 2.23.0 or later because they can't be built with MinGW-w64. See also:
* mingw-w64/mingw-w64#49
* googleapis/google-cloud-cpp#14436

### Are these changes tested?

Yes.

### Are there any user-facing changes?

Yes.
* GitHub Issue: #43134

Authored-by: Sutou Kouhei <[email protected]>
Signed-off-by: Sutou Kouhei <[email protected]>
raulcd pushed a commit to apache/arrow that referenced this issue Jul 5, 2024
### Rationale for this change

`google_cloud_cpp_mocks` depends on `GTest::gmock_main` but it's built without `BUILD_TESTING`. google-cloud-cpp finds GoogleTest only with `BUILD_TESTING`.

### What changes are included in this PR?

The recent google-cloud-cpp doesn't build `google_cloud_cpp_mocks` without `BUILD_TESTING`.

Note that we can't use 2.23.0 or later because they can't be built with MinGW-w64. See also:
* mingw-w64/mingw-w64#49
* googleapis/google-cloud-cpp#14436

### Are these changes tested?

Yes.

### Are there any user-facing changes?

Yes.
* GitHub Issue: #43134

Authored-by: Sutou Kouhei <[email protected]>
Signed-off-by: Sutou Kouhei <[email protected]>
@coryan
Copy link
Contributor

coryan commented Jul 5, 2024

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
Copy link
Contributor Author

kou commented Jul 5, 2024

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.

zanmato1984 pushed a commit to zanmato1984/arrow that referenced this issue Jul 9, 2024
…che#43136)

### Rationale for this change

`google_cloud_cpp_mocks` depends on `GTest::gmock_main` but it's built without `BUILD_TESTING`. google-cloud-cpp finds GoogleTest only with `BUILD_TESTING`.

### What changes are included in this PR?

The recent google-cloud-cpp doesn't build `google_cloud_cpp_mocks` without `BUILD_TESTING`.

Note that we can't use 2.23.0 or later because they can't be built with MinGW-w64. See also:
* mingw-w64/mingw-w64#49
* googleapis/google-cloud-cpp#14436

### Are these changes tested?

Yes.

### Are there any user-facing changes?

Yes.
* GitHub Issue: apache#43134

Authored-by: Sutou Kouhei <[email protected]>
Signed-off-by: Sutou Kouhei <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants