Repository navigation
GH-46487: [C++] Refactor lz4 from ExternalProject to FetchContent - #46390
Conversation
|
|
4d9b746 to
c3939ce
Compare
|
Can we use one PR per dependency (instead of one commit per dependency in one PR) for easy to review/merge? FYI: We already have "Bump bundled XXX" issues: Some of them have WIP PR such as #45306 . |
Yes, of course. Probably should have done that to start with. I'll repurpose this PR for |
| if(NOT DEFINED CMAKE_EXPORT_NO_PACKAGE_REGISTRY) | ||
| set(CMAKE_EXPORT_NO_PACKAGE_REGISTRY ON) | ||
| endif() | ||
| install(TARGETS lz4_static EXPORT orc_targets) |
There was a problem hiding this comment.
We don't need to install built LZ4 because we create libarrow_bundled_dependencies.a for bundled dependencies.
There was a problem hiding this comment.
Hmm, yeah let me try. When I tried before I had complaints on windows because of this, but I've removed it and we can see what CI does.
There was a problem hiding this comment.
Ah, did you see this error?
https://github.com/apache/arrow/actions/runs/14963508416/job/42029340434?pr=46390#step:9:833
CMake Error: install(EXPORT "orc_targets" ...) includes target "orc" which requires target "lz4_static" that is not in any export set.
I'll take a look at this.
There was a problem hiding this comment.
How about this?
diff --git a/cpp/cmake_modules/ThirdpartyToolchain.cmake b/cpp/cmake_modules/ThirdpartyToolchain.cmake
index 6cfcdc84c0..5541721ec5 100644
--- a/cpp/cmake_modules/ThirdpartyToolchain.cmake
+++ b/cpp/cmake_modules/ThirdpartyToolchain.cmake
@@ -2678,10 +2678,11 @@ macro(build_lz4)
fetchcontent_makeavailable(lz4_ep)
# Since lz4 is now part of our build system, we can directly use the target
- add_library(LZ4::lz4 ALIAS lz4_static)
+ add_library(LZ4::lz4 INTERFACE IMPORTED)
+ target_link_libraries(LZ4::lz4 INTERFACE lz4_static)
# Add to bundled static libs
- list(APPEND ARROW_BUNDLED_STATIC_LIBS LZ4::lz4)
+ list(APPEND ARROW_BUNDLED_STATIC_LIBS lz4_static)
endmacro()
if(ARROW_WITH_LZ4)There was a problem hiding this comment.
Ah, we need to update the "Since lz4 is now part of ..." comment too...
There was a problem hiding this comment.
Yup! And ah ok, thanks, lemme try that. I also updated the comment, but I might not be describing that in the best way, so very open to suggestions.
| # Get the source and binary directories after fetching content | ||
| fetchcontent_getproperties(lz4_ep | ||
| SOURCE_DIR LZ4_SOURCE_DIR | ||
| BINARY_DIR LZ4_BINARY_DIR) | ||
|
|
||
| # Set up the imported library for compatibility with the rest of the build system | ||
| set(LZ4_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/_deps/lz4_ep-build") | ||
| set(LZ4_INCLUDE_DIR "${LZ4_SOURCE_DIR}/lib") | ||
|
|
There was a problem hiding this comment.
Can we remove them?
In general, we want to use CMake targets instead of separated XXX_INCLUDE_DIR and so on variables.
There was a problem hiding this comment.
Yup, they are cruft I should have removed. Done now
| if(NOT DEFINED CMAKE_EXPORT_NO_PACKAGE_REGISTRY) | ||
| set(CMAKE_EXPORT_NO_PACKAGE_REGISTRY ON) | ||
| endif() | ||
| install(TARGETS lz4_static EXPORT orc_targets) |
There was a problem hiding this comment.
We don't need to install built LZ4 because we create libarrow_bundled_dependencies.a for bundled dependencies.
| "-DLZ4_LIBRARY=$<TARGET_FILE:LZ4::lz4>" | ||
| "-DLZ4_STATIC_LIB=$<TARGET_FILE:LZ4::lz4>" | ||
| "-DLZ4_LIBRARY=$<LZ4_TARGET>" | ||
| "-DLZ4_STATIC_LIB=$<LZ4_TARGET>" |
There was a problem hiding this comment.
In general, we always use XXX_TARGET instead of XXX::xxx when we define XXX_TARGET.
In this case, we can replace all existing LZ4::lz4 with ${LZ4_TARGET} with this approach. (It's OK.)
If we don't want to replace all existing LZ4::lz4, how about the following without defining LZ4_TARGET?
diff --git a/cpp/cmake_modules/ThirdpartyToolchain.cmake b/cpp/cmake_modules/ThirdpartyToolchain.cmake
index 92ea7e346f..36aba76cfc 100644
--- a/cpp/cmake_modules/ThirdpartyToolchain.cmake
+++ b/cpp/cmake_modules/ThirdpartyToolchain.cmake
@@ -4709,7 +4709,12 @@ function(build_orc)
INTERFACE_INCLUDE_DIRECTORIES)
get_filename_component(ORC_SNAPPY_ROOT "${ORC_SNAPPY_INCLUDE_DIR}" DIRECTORY)
- get_target_property(ORC_LZ4_ROOT LZ4::lz4 INTERFACE_INCLUDE_DIRECTORIES)
+ if(LZ4_VENDORED)
+ set(ORC_LZ4_TARGET lz4_static)
+ else()
+ set(ORC_LZ4_TARGET LZ4::lz4)
+ endif()
+ get_target_property(ORC_LZ4_ROOT ${ORC_LZ4_TARGET} INTERFACE_INCLUDE_DIRECTORIES)
get_filename_component(ORC_LZ4_ROOT "${ORC_LZ4_ROOT}" DIRECTORY)
get_target_property(ORC_ZSTD_ROOT ${ARROW_ZSTD_LIBZSTD} INTERFACE_INCLUDE_DIRECTORIES)
@@ -4735,8 +4740,8 @@ function(build_orc)
"-DSNAPPY_HOME=${ORC_SNAPPY_ROOT}"
"-DSNAPPY_LIBRARY=$<TARGET_FILE:${Snappy_TARGET}>"
"-DLZ4_HOME=${ORC_LZ4_ROOT}"
- "-DLZ4_LIBRARY=$<TARGET_FILE:LZ4::lz4>"
- "-DLZ4_STATIC_LIB=$<TARGET_FILE:LZ4::lz4>"
+ "-DLZ4_LIBRARY=$<TARGET_FILE:${ORC_LZ4_TARGET}>"
+ "-DLZ4_STATIC_LIB=$<TARGET_FILE:${ORC_LZ4_TARGET}>"
"-DLZ4_INCLUDE_DIR=${ORC_LZ4_ROOT}/include"
"-DSNAPPY_INCLUDE_DIR=${ORC_SNAPPY_INCLUDE_DIR}"
"-DZSTD_HOME=${ORC_ZSTD_ROOT}"build_orc is only the place that requires a real (not alias) LZ4 CMake target. We can do this special approach only here.
| "-DLZ4_LIBRARY=$<LZ4_TARGET>" | ||
| "-DLZ4_STATIC_LIB=$<LZ4_TARGET>" |
There was a problem hiding this comment.
BTW, do we need TARGET_FILE:${...}?
| "-DLZ4_LIBRARY=$<LZ4_TARGET>" | |
| "-DLZ4_STATIC_LIB=$<LZ4_TARGET>" | |
| "-DLZ4_LIBRARY=$<TARGET_FILE:${LZ4_TARGET}>" | |
| "-DLZ4_STATIC_LIB=$<TARGET_FILE:${LZ4_TARGET}>" |
|
@github-actions crossbow submit test-ubuntu-24.04-cpp-gcc-13-bundled |
|
Revision: ae2e181 Submitted crossbow builds: ursacomputing/crossbow @ actions-848cd401e8
|
|
@github-actions crossbow submit test-ubuntu-24.04-cpp-gcc-13-bundled |
|
Revision: a9c8fbd Submitted crossbow builds: ursacomputing/crossbow @ actions-7cb3fee6e0
|
|
@github-actions crossbow submit -g cpp -g r |
|
Revision: a9c8fbd Submitted crossbow builds: ursacomputing/crossbow @ actions-8fcd638307 |
|
|
|
After merging your PR, Conbench analyzed the 4 benchmarking runs that have been run so far on merge-commit f4d52af. There were no benchmark performance regressions. 🎉 The full Conbench report has more details. It also includes information about 2 possible false positives for unstable benchmarks that are known to sometimes produce them. |
Rationale for this change
FetchContentis easier to maintain thanExternalProjectbecause we don't need to create import CMake targets manually withFetchContent.What changes are included in this PR?
Use
FetchContentinstead ofExternalProjectfor bundled LZ4.Are these changes tested?
Yes
Are there any user-facing changes?
No