Revert "Use CMake wholearchive group (#156393)"

This reverts commit d1b4e0fa9a5feb22fc6de1d36dc4c9dac685caed.

Reverted https://github.com/pytorch/pytorch/pull/156393 on behalf of https://github.com/etaf due to This PR is breaking XPU windows build. ([comment](https://github.com/pytorch/pytorch/pull/156393#issuecomment-2995576362))
This commit is contained in:
PyTorch MergeBot
2025-06-23 09:03:19 +00:00
parent 92409b6c89
commit 4f70fbbd16
2 changed files with 23 additions and 2 deletions

View File

@ -1157,7 +1157,15 @@ if(USE_XPU)
if(USE_C10D_XCCL)
target_compile_definitions(torch_xpu PUBLIC USE_C10D_XCCL)
endif()
target_link_libraries(torch_xpu PRIVATE $<LINK_LIBRARY:WHOLE_ARCHIVE,torch_xpu_ops>)
if(MSVC)
# Windows
target_link_options(torch_xpu PRIVATE
"-WHOLEARCHIVE:$<TARGET_FILE:torch_xpu_ops>")
else()
# Linux
target_link_options(torch_xpu PRIVATE
"-Wl,--whole-archive,$<TARGET_FILE:torch_xpu_ops>,--no-whole-archive")
endif()
# Set cached ${ATen_XPU_INCLUDE_DIRS} to torch
include_directories(SYSTEM ${ATen_XPU_INCLUDE_DIRS})

View File

@ -163,7 +163,20 @@ macro(caffe2_interface_library SRC DST)
# link command for the specific SRC library.
if(${__src_target_type} STREQUAL "STATIC_LIBRARY")
# In the case of static library, we will need to add whole-static flags.
target_link_libraries(${DST} INTERFACE $<LINK_LIBRARY:WHOLE_ARCHIVE,${SRC}>)
if(APPLE)
target_link_libraries(
${DST} INTERFACE -Wl,-force_load,\"$<TARGET_FILE:${SRC}>\")
elseif(MSVC)
# In MSVC, we will add whole archive in default.
target_link_libraries(
${DST} INTERFACE "$<TARGET_FILE:${SRC}>")
target_link_options(
${DST} INTERFACE "-WHOLEARCHIVE:$<TARGET_FILE:${SRC}>")
else()
# Assume everything else is like gcc
target_link_libraries(${DST} INTERFACE
"-Wl,--whole-archive,\"$<TARGET_FILE:${SRC}>\" -Wl,--no-whole-archive")
endif()
# Link all interface link libraries of the src target as well.
# For static library, we need to explicitly depend on all the libraries
# that are the dependent library of the source library. Note that we cannot