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

[build] Enable strip for libtaichi_c_api.so with Release Build #6845

Merged
merged 16 commits into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from 15 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
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ cmake_minimum_required(VERSION 3.17)

project(taichi)

include("cmake/utils.cmake")

if (NOT DEFINED TI_VERSION_MAJOR)
message(WARNING "It seems that you are running cmake manually, which may cause issues. Please use setup.py to build taichi from source, see https://docs.taichi-lang.org/docs/dev_install for more details.")
set(TI_VERSION_MAJOR 0)
Expand Down Expand Up @@ -64,6 +66,8 @@ option(USE_LLD "Use lld (from llvm) linker" OFF)
option(USE_MOLD "Use mold (A Modern Linker)" OFF)
option(TI_WITH_BACKTRACE "Use backward-cpp to print out C++ stack trace upon failure" OFF)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffunction-sections -fdata-sections")

if (USE_LLD)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=lld")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fuse-ld=lld")
Expand Down
5 changes: 4 additions & 1 deletion cmake/TaichiCAPI.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ endif()

endfunction()


set(TAICHI_C_API_NAME taichi_c_api)

set(TAICHI_C_API_NAME taichi_c_api)
jim19930609 marked this conversation as resolved.
Show resolved Hide resolved
file(GLOB_RECURSE C_API_SOURCE "c_api/src/taichi_core_impl.cpp")

if (TI_WITH_LLVM)
Expand Down Expand Up @@ -49,6 +49,9 @@ endif()

add_library(${TAICHI_C_API_NAME} SHARED ${C_API_SOURCE})
target_link_static_library(${TAICHI_C_API_NAME} taichi_core)
target_enable_function_level_linking(${TAICHI_C_API_NAME})
# Strip shared library
set_target_properties(${TAICHI_C_API_NAME} PROPERTIES LINK_FLAGS_RELEASE -s)

# Avoid exporting third party symbols from libtaichi_c_api.so
# Note that on Windows, external symbols will be excluded from .dll automatically, by default.
Expand Down
7 changes: 7 additions & 0 deletions cmake/utils.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function(target_enable_function_level_linking TARGET)
if(APPLE)
target_link_options(${TARGET} PRIVATE -Wl,-dead_strip)
else() # LINUX AND WIN32
target_link_options(${TARGET} PRIVATE -Wl,--gc-sections)
endif()
endfunction()