Skip to content
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

strip after compilation #32145

Merged
merged 7 commits into from
Apr 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ option(WITH_SW "Compile PaddlePaddle with sw support" OFF)
option(WITH_MIPS "Compile PaddlePaddle with mips support" OFF)
option(WITH_MUSL "Compile with musl libc instead of gblic" OFF)
option(WITH_UNITY_BUILD "Compile with UnityBuild mode" OFF)
option(WITH_STRIP "Strip so files of Whl packages" OFF)

# PY_VERSION
if(NOT PY_VERSION)
Expand Down Expand Up @@ -366,6 +367,13 @@ else()
message(WARNING "On inference mode, will take place some specific optimization. Turn on the ON_INFER flag when building inference_lib only.")
endif()

if(WITH_STRIP)
find_program(STRIP_PATH strip)
if(NOT STRIP_PATH OR NOT LINUX)
set(WITH_STRIP OFF CACHE STRING "Command strip is only used on Linux when it exists." FORCE)
endif()
endif()

add_subdirectory(paddle)
if(WITH_PYTHON)
add_subdirectory(python)
Expand Down
5 changes: 5 additions & 0 deletions paddle/fluid/inference/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,8 @@ if(NOT APPLE AND NOT WIN32)
DEPENDS paddle_inference_shared)
add_custom_target(check_symbol ALL DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/.check_symbol")
endif()

if(LINUX AND WITH_STRIP)
add_custom_command(TARGET paddle_inference_shared POST_BUILD
COMMAND ${STRIP_PATH} $<TARGET_FILE:paddle_inference_shared>)
endif()
6 changes: 6 additions & 0 deletions python/setup.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,12 @@ else:
with open("@PADDLE_BINARY_DIR@/python/paddle/README.rst", "r")as f:
long_description = unicode(f.read(), 'UTF-8')

# strip *.so to reduce package size
if '${WITH_STRIP}' == 'ON':
command = 'find ${PADDLE_BINARY_DIR}/python/paddle -name "*.so" | xargs -i strip {}'
if os.system(command) != 0:
raise Exception("strip *.so failed, command: %s" % command)

with redirect_stdout():
setup(name='${PACKAGE_NAME}',
version='${PADDLE_VERSION}',
Expand Down