Skip to content

Commit

Permalink
apacheGH-36598: [C++][MinGW] Fix build failure with Protobuf 23.4 (ap…
Browse files Browse the repository at this point in the history
…ache#36606)

### Rationale for this change

There are 2 problems:

* `FindProtobuf.cmake` provided by CMake is incomplete with Protobuf 23.4.
* Misses `-DPROTOBUF_USE_DLLS` for building Substrait related files.

### What changes are included in this PR?

* We need to use `protobuf-config.cmake` provided by Protobuf instead of `FindProtobuf.cmake` provided by CMake because `FindProtobuf.cmake` misses `absl::status` dependency.
* Accept Protobuf 23.4.
* Use `PROTOBUF_USE_DLLS` when we build Substrait related files.
* Use `Boost_INCLUDE_DIRS` instead of `Boost_INCLUDE_DIR` because `Boost_INCLUDE_DIR` isn't defined in `BoostConfig.cmake`.

### Are these changes tested?

Yes.

### Are there any user-facing changes?

Yes.
* Closes: apache#36598

Authored-by: Sutou Kouhei <kou@clear-code.com>
Signed-off-by: Antoine Pitrou <antoine@python.org>
  • Loading branch information
kou committed Jul 12, 2023
1 parent e4bf235 commit f18d8b3
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/workflows/cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ jobs:
CMAKE_ARGS: >-
-DARROW_PACKAGE_PREFIX=/${{ matrix.msystem_lower}}
-DBoost_NO_BOOST_CMAKE=ON
-DCMAKE_FIND_PACKAGE_PREFER_CONFIG=ON
# We can't use unity build because we don't have enough memory on
# GitHub Actions.
# CMAKE_UNITY_BUILD: ON
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ jobs:
CMAKE_ARGS: >-
-DARROW_PACKAGE_PREFIX=/ucrt${{ matrix.mingw-n-bits }}
-DBoost_NO_BOOST_CMAKE=ON
-DCMAKE_FIND_PACKAGE_PREFER_CONFIG=ON
CMAKE_UNITY_BUILD: ON
steps:
- name: Disable Crash Dialogs
Expand Down
7 changes: 7 additions & 0 deletions cpp/cmake_modules/FindProtobufAlt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,10 @@ if(ProtobufAlt_FIND_QUIETLY)
endif()
find_package(Protobuf ${find_package_args})
set(ProtobufAlt_FOUND ${Protobuf_FOUND})
if(ProtobufAlt_FOUND)
set(ProtobufAlt_VERSION ${Protobuf_VERSION})
set(ProtobufAlt_VERSION_MAJOR ${Protobuf_VERSION_MAJOR})
set(ProtobufAlt_VERSION_MINOR ${Protobuf_VERSION_MINOR})
set(ProtobufAlt_VERSION_PATCH ${Protobuf_VERSION_PATCH})
set(ProtobufAlt_VERSION_TWEEK ${Protobuf_VERSION_TWEEK})
endif()
14 changes: 12 additions & 2 deletions cpp/cmake_modules/ThirdpartyToolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1224,7 +1224,7 @@ if(ARROW_USE_BOOST)
target_compile_definitions(Boost::headers INTERFACE "BOOST_USE_WINDOWS_H=1")
endif()

message(STATUS "Boost include dir: ${Boost_INCLUDE_DIR}")
message(STATUS "Boost include dir: ${Boost_INCLUDE_DIRS}")
endif()

# ----------------------------------------------------------------------
Expand Down Expand Up @@ -1710,7 +1710,17 @@ if(ARROW_WITH_PROTOBUF)
else()
set(ARROW_PROTOBUF_REQUIRED_VERSION "2.6.1")
endif()
# We need to use FORCE_ANY_NEWER_VERSION here to accept Protobuf
# newer version such as 23.4. If we don't use it, 23.4 is processed
# as an incompatible version with 3.12.0 with protobuf-config.cmake
# provided by Protobuf. Because protobuf-config-version.cmake
# requires the same major version. In the example, "23" for 23.4 and
# "3" for 3.12.0 are different. So 23.4 is rejected with 3.12.0. If
# we use FORCE_ANY_NEWER_VERSION here, we can bypass the check and
# use 23.4.
resolve_dependency(Protobuf
FORCE_ANY_NEWER_VERSION
TRUE
HAVE_ALT
TRUE
REQUIRED_VERSION
Expand Down Expand Up @@ -1853,7 +1863,7 @@ macro(build_substrait)
add_library(substrait STATIC ${SUBSTRAIT_SOURCES})
set_target_properties(substrait PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_include_directories(substrait PUBLIC ${SUBSTRAIT_INCLUDES})
target_link_libraries(substrait INTERFACE ${ARROW_PROTOBUF_LIBPROTOBUF})
target_link_libraries(substrait PUBLIC ${ARROW_PROTOBUF_LIBPROTOBUF})
add_dependencies(substrait substrait_gen)

list(APPEND ARROW_BUNDLED_STATIC_LIBS substrait)
Expand Down
4 changes: 3 additions & 1 deletion cpp/src/gandiva/precompiled/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ foreach(SRC_FILE ${PRECOMPILED_SRCS})
-I${ARROW_BINARY_DIR}/src)

if(NOT ARROW_USE_NATIVE_INT128)
list(APPEND PRECOMPILE_COMMAND -I${Boost_INCLUDE_DIR})
foreach(boost_include_dir ${Boost_INCLUDE_DIRS})
list(APPEND PRECOMPILE_COMMAND -I${boost_include_dir})
endforeach()
endif()
add_custom_command(OUTPUT ${BC_FILE}
COMMAND ${PRECOMPILE_COMMAND}
Expand Down

0 comments on commit f18d8b3

Please sign in to comment.