-
Notifications
You must be signed in to change notification settings - Fork 3.8k
GH-45303: [C++] Refactor ZSTD from ExternalProject to FetchContent #46393
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
Open
jonkeane
wants to merge
2
commits into
apache:main
Choose a base branch
from
jonkeane:ZSTD_FetchContent
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2690,49 +2690,87 @@ if(ARROW_WITH_LZ4) | |
endif() | ||
|
||
macro(build_zstd) | ||
message(STATUS "Building Zstandard from source") | ||
message(STATUS "Building Zstandard from source using FetchContent") | ||
|
||
set(ZSTD_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/zstd_ep-install") | ||
# Set Zstd as vendored | ||
set(ZSTD_VENDORED TRUE) | ||
|
||
set(ZSTD_CMAKE_ARGS | ||
${EP_COMMON_CMAKE_ARGS} | ||
"-DCMAKE_INSTALL_PREFIX=${ZSTD_PREFIX}" | ||
-DZSTD_BUILD_PROGRAMS=OFF | ||
-DZSTD_BUILD_SHARED=OFF | ||
-DZSTD_BUILD_STATIC=ON | ||
-DZSTD_MULTITHREAD_SUPPORT=OFF) | ||
# Declare the content | ||
fetchcontent_declare(zstd_ep | ||
${FC_DECLARE_COMMON_OPTIONS} | ||
URL ${ZSTD_SOURCE_URL} | ||
URL_HASH "SHA256=${ARROW_ZSTD_BUILD_SHA256_CHECKSUM}" | ||
SOURCE_SUBDIR "build/cmake") | ||
|
||
if(MSVC) | ||
set(ZSTD_STATIC_LIB "${ZSTD_PREFIX}/lib/zstd_static.lib") | ||
if(ARROW_USE_STATIC_CRT) | ||
list(APPEND ZSTD_CMAKE_ARGS "-DZSTD_USE_STATIC_RUNTIME=ON") | ||
endif() | ||
else() | ||
set(ZSTD_STATIC_LIB "${ZSTD_PREFIX}/lib/libzstd.a") | ||
# Prepare fetch content environment | ||
prepare_fetchcontent() | ||
|
||
# Set Zstd-specific build options as cache variables | ||
set(ZSTD_BUILD_PROGRAMS | ||
OFF | ||
CACHE BOOL "Don't build Zstd programs" FORCE) | ||
set(ZSTD_BUILD_SHARED | ||
OFF | ||
CACHE BOOL "Don't build Zstd shared libraries" FORCE) | ||
set(ZSTD_BUILD_STATIC | ||
ON | ||
CACHE BOOL "Build Zstd static libraries" FORCE) | ||
set(ZSTD_MULTITHREAD_SUPPORT | ||
OFF | ||
CACHE BOOL "Don't build Zstd with multithread support" FORCE) | ||
set(ZSTD_LEGACY_SUPPORT | ||
0 | ||
CACHE NUMBER "Disable legacy support which causes conflicts in MSVC builds" FORCE) | ||
|
||
# Disable Unity build for zstd to prevent redefinition errors in dictBuilder/cover.h | ||
set(CMAKE_UNITY_BUILD | ||
OFF | ||
CACHE BOOL "Disable unity build for zstd" FORCE) | ||
|
||
# Add static runtime option for MSVC if needed | ||
if(MSVC AND ARROW_USE_STATIC_CRT) | ||
set(ZSTD_USE_STATIC_RUNTIME | ||
ON | ||
CACHE BOOL "Build Zstd with static runtime" FORCE) | ||
endif() | ||
|
||
externalproject_add(zstd_ep | ||
${EP_COMMON_OPTIONS} | ||
CMAKE_ARGS ${ZSTD_CMAKE_ARGS} | ||
SOURCE_SUBDIR "build/cmake" | ||
INSTALL_DIR ${ZSTD_PREFIX} | ||
URL ${ZSTD_SOURCE_URL} | ||
URL_HASH "SHA256=${ARROW_ZSTD_BUILD_SHA256_CHECKSUM}" | ||
BUILD_BYPRODUCTS "${ZSTD_STATIC_LIB}") | ||
# Make the dependency available - this will actually perform the download and configure | ||
fetchcontent_makeavailable(zstd_ep) | ||
|
||
file(MAKE_DIRECTORY "${ZSTD_PREFIX}/include") | ||
# Get the source and binary directories after fetching content | ||
fetchcontent_getproperties(zstd_ep | ||
SOURCE_DIR ZSTD_SOURCE_DIR | ||
BINARY_DIR ZSTD_BINARY_DIR) | ||
|
||
add_library(zstd::libzstd_static STATIC IMPORTED) | ||
set_target_properties(zstd::libzstd_static PROPERTIES IMPORTED_LOCATION | ||
"${ZSTD_STATIC_LIB}") | ||
target_include_directories(zstd::libzstd_static BEFORE | ||
INTERFACE "${ZSTD_PREFIX}/include") | ||
# Check which target name is actually created by zstd's CMake | ||
# zstd on macOS often creates 'zstd_static' despite what the docs say | ||
if(TARGET zstd_static) | ||
Comment on lines
+2745
to
+2747
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm. This is strange... |
||
# Create interface library instead of alias | ||
add_library(zstd::libzstd_static INTERFACE IMPORTED) | ||
target_link_libraries(zstd::libzstd_static INTERFACE zstd_static) | ||
|
||
add_dependencies(zstd::libzstd_static zstd_ep) | ||
if(NOT DEFINED CMAKE_EXPORT_NO_PACKAGE_REGISTRY) | ||
set(CMAKE_EXPORT_NO_PACKAGE_REGISTRY ON) | ||
endif() | ||
install(TARGETS zstd_static EXPORT orc_targets) | ||
message(STATUS "Using zstd_static target for zstd") | ||
elseif(TARGET libzstd_static) | ||
# Create interface library instead of alias | ||
add_library(zstd::libzstd_static INTERFACE IMPORTED) | ||
target_link_libraries(zstd::libzstd_static INTERFACE libzstd_static) | ||
|
||
if(NOT DEFINED CMAKE_EXPORT_NO_PACKAGE_REGISTRY) | ||
set(CMAKE_EXPORT_NO_PACKAGE_REGISTRY ON) | ||
endif() | ||
install(TARGETS libzstd_static EXPORT orc_targets) | ||
message(STATUS "Using libzstd_static target for zstd") | ||
else() | ||
message(FATAL_ERROR "Neither zstd_static nor libzstd_static targets were created by FetchContent" | ||
) | ||
endif() | ||
|
||
# Add to bundled static libs | ||
list(APPEND ARROW_BUNDLED_STATIC_LIBS zstd::libzstd_static) | ||
|
||
set(ZSTD_VENDORED TRUE) | ||
endmacro() | ||
|
||
if(ARROW_WITH_ZSTD) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We must use
function()
notmacro()
here to create a new scope.