-
Notifications
You must be signed in to change notification settings - Fork 4k
ARROW-7605: [C++] Bundle private jemalloc symbols into static library libarrow.a #6220
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
Changes from all commits
7a3b6e0
6deb268
c3c0da1
ee5f086
b57ee51
f7783ba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -128,6 +128,85 @@ function(REUSE_PRECOMPILED_HEADER_LIB TARGET_NAME LIB_NAME) | |
| endif() | ||
| endfunction() | ||
|
|
||
| # Based on MIT-licensed | ||
| # https://gist.github.com/cristianadam/ef920342939a89fae3e8a85ca9459b49 | ||
| function(create_merged_static_lib output_target) | ||
| set(options) | ||
| set(one_value_args NAME ROOT) | ||
| set(multi_value_args TO_MERGE) | ||
| cmake_parse_arguments(ARG | ||
| "${options}" | ||
| "${one_value_args}" | ||
| "${multi_value_args}" | ||
| ${ARGN}) | ||
| if(ARG_UNPARSED_ARGUMENTS) | ||
| message(SEND_ERROR "Error: unrecognized arguments: ${ARG_UNPARSED_ARGUMENTS}") | ||
| endif() | ||
|
|
||
| set( | ||
| output_lib_path | ||
| ${BUILD_OUTPUT_ROOT_DIRECTORY}${CMAKE_STATIC_LIBRARY_PREFIX}${ARG_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX} | ||
| ) | ||
|
|
||
| set(all_library_paths $<TARGET_FILE:${ARG_ROOT}>) | ||
| foreach(lib ${ARG_TO_MERGE}) | ||
| list(APPEND all_library_paths $<TARGET_FILE:${lib}>) | ||
| endforeach() | ||
|
|
||
| if(APPLE) | ||
| set(BUNDLE_COMMAND | ||
| "libtool" | ||
| "-no_warning_for_no_symbols" | ||
| "-static" | ||
| "-o" | ||
| ${output_lib_path} | ||
| ${all_library_paths}) | ||
| elseif(CMAKE_CXX_COMPILER_ID MATCHES "^(Clang|GNU)$") | ||
| set(ar_script_path ${CMAKE_BINARY_DIR}/${ARG_NAME}.ar) | ||
|
|
||
| file(WRITE ${ar_script_path}.in "CREATE ${output_lib_path}\n") | ||
| file(APPEND ${ar_script_path}.in "ADDLIB $<TARGET_FILE:${ARG_ROOT}>\n") | ||
|
|
||
| foreach(lib ${ARG_TO_MERGE}) | ||
| file(APPEND ${ar_script_path}.in "ADDLIB $<TARGET_FILE:${lib}>\n") | ||
| endforeach() | ||
|
|
||
| file(APPEND ${ar_script_path}.in "SAVE\nEND\n") | ||
| file(GENERATE OUTPUT ${ar_script_path} INPUT ${ar_script_path}.in) | ||
| set(ar_tool ${CMAKE_AR}) | ||
|
|
||
| if(CMAKE_INTERPROCEDURAL_OPTIMIZATION) | ||
| set(ar_tool ${CMAKE_CXX_COMPILER_AR}) | ||
| endif() | ||
|
|
||
| set(BUNDLE_COMMAND ${ar_tool} -M < ${ar_script_path}) | ||
|
|
||
| elseif(MSVC) | ||
| if(NOT CMAKE_LIBTOOL) | ||
| find_program(lib_tool lib HINTS "${CMAKE_CXX_COMPILER}/..") | ||
| if("${lib_tool}" STREQUAL "lib_tool-NOTFOUND") | ||
| message(FATAL_ERROR "Cannot locate libtool to bundle libraries") | ||
|
||
| endif() | ||
| else() | ||
| set(${lib_tool} ${CMAKE_LIBTOOL}) | ||
| endif() | ||
| set(BUNDLE_TOOL ${lib_tool}) | ||
| set(BUNDLE_COMMAND ${BUNDLE_TOOL} /NOLOGO /OUT:${output_lib_path} | ||
| ${all_library_paths}) | ||
| else() | ||
| message(FATAL_ERROR "Unknown bundle scenario!") | ||
| endif() | ||
|
|
||
| add_custom_command(COMMAND ${BUNDLE_COMMAND} | ||
| OUTPUT ${output_lib_path} | ||
| COMMENT "Bundling ${output_lib_path}" | ||
| VERBATIM) | ||
|
|
||
| add_custom_target(${output_target} ALL DEPENDS ${output_lib_path}) | ||
| add_dependencies(${output_target} ${ARG_ROOT} ${ARG_TO_MERGE}) | ||
| install(FILES ${output_lib_path} DESTINATION ${CMAKE_INSTALL_LIBDIR}) | ||
| endfunction() | ||
|
|
||
| # \arg OUTPUTS list to append built targets to | ||
| function(ADD_ARROW_LIB LIB_NAME) | ||
| set(options BUILD_SHARED BUILD_STATIC) | ||
|
|
@@ -140,6 +219,7 @@ function(ADD_ARROW_LIB LIB_NAME) | |
| STATIC_LINK_LIBS | ||
| SHARED_LINK_LIBS | ||
| SHARED_PRIVATE_LINK_LIBS | ||
| BUNDLE_STATIC_LIBS | ||
| EXTRA_INCLUDES | ||
| PRIVATE_INCLUDES | ||
| DEPENDENCIES | ||
|
|
@@ -341,6 +421,11 @@ function(ADD_ARROW_LIB LIB_NAME) | |
| set(LIB_NAME_STATIC ${LIB_NAME}) | ||
| endif() | ||
|
|
||
| if(ARG_BUNDLE_STATIC_LIBS) | ||
| set(LIB_NAME_BUNDLED ${LIB_NAME_STATIC}) | ||
| set(LIB_NAME_STATIC ${LIB_NAME_STATIC}_unbundled) | ||
|
||
| endif() | ||
|
|
||
| if(ARROW_BUILD_STATIC AND WIN32) | ||
| target_compile_definitions(${LIB_NAME}_static PUBLIC ARROW_STATIC) | ||
| endif() | ||
|
|
@@ -359,6 +444,16 @@ function(ADD_ARROW_LIB LIB_NAME) | |
| "$<BUILD_INTERFACE:${ARG_STATIC_LINK_LIBS}>" | ||
| "$<INSTALL_INTERFACE:${INTERFACE_LIBS}>") | ||
|
|
||
| if(ARG_BUNDLE_STATIC_LIBS) | ||
| create_merged_static_lib(${LIB_NAME}_static_bundled | ||
| NAME | ||
| ${LIB_NAME_BUNDLED} | ||
| ROOT | ||
| ${LIB_NAME}_static | ||
| TO_MERGE | ||
| ${ARG_BUNDLE_STATIC_LIBS}) | ||
| endif() | ||
|
|
||
| install(TARGETS ${LIB_NAME}_static ${INSTALL_IS_OPTIONAL} | ||
| EXPORT ${LIB_NAME}_targets | ||
| RUNTIME DESTINATION ${RUNTIME_INSTALL_DIR} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -416,6 +416,18 @@ endif() | |
|
|
||
| set(ARROW_ALL_SRCS ${ARROW_SRCS} ${ARROW_C_SRCS}) | ||
|
|
||
| # We bundle some private static dependencies into the Arrow static library, | ||
| # for convenience. | ||
| set(ARROW_BUNDLE_STATIC_LIBS) | ||
|
|
||
| if(ARROW_JEMALLOC) | ||
| list(APPEND ARROW_BUNDLE_STATIC_LIBS jemalloc::jemalloc) | ||
| endif() | ||
|
|
||
| if(ARROW_MIMALLOC) | ||
| list(APPEND ARROW_BUNDLE_STATIC_LIBS mimalloc::mimalloc) | ||
| endif() | ||
|
|
||
|
||
| add_arrow_lib(arrow | ||
| CMAKE_PACKAGE_NAME | ||
| Arrow | ||
|
|
@@ -437,6 +449,8 @@ add_arrow_lib(arrow | |
| ${ARROW_SHARED_PRIVATE_LINK_LIBS} | ||
| STATIC_LINK_LIBS | ||
| ${ARROW_STATIC_LINK_LIBS} | ||
| BUNDLE_STATIC_LIBS | ||
| ${ARROW_BUNDLE_STATIC_LIBS} | ||
| SHARED_INSTALL_INTERFACE_LIBS | ||
| ${ARROW_SHARED_INSTALL_INTERFACE_LIBS} | ||
| STATIC_INSTALL_INTERFACE_LIBS | ||
|
|
||
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.
Could you add a comment saying what this does and why? This is a potential future head scratcher for whoever will debug this.
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.
Yes, I certainly will