Skip to content

Unbreak build_size_test.sh on Mac #12089

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

Merged
merged 1 commit into from
Jun 28, 2025
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
6 changes: 1 addition & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -706,11 +706,7 @@ if(EXECUTORCH_BUILD_EXECUTOR_RUNNER)

add_executable(executor_runner ${_executor_runner__srcs})
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
if(APPLE)
target_link_options(executor_runner PRIVATE "LINKER:-dead_strip")
else()
target_link_options(executor_runner PRIVATE "LINKER:--gc-sections")
endif()
target_link_options_gc_sections(executor_runner)
endif()
target_link_libraries(executor_runner ${_executor_runner_libs})
target_compile_options(executor_runner PUBLIC ${_common_compile_options})
Expand Down
7 changes: 3 additions & 4 deletions examples/models/llama/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,9 @@ endif()

add_executable(llama_main ${_srcs})
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
if(APPLE)
target_link_options(llama_main PRIVATE "LINKER:-dead_strip")
else()
target_link_options(llama_main PRIVATE "LINKER:--gc-sections,-s")
target_link_options_gc_sections(llama_main)
if(NOT APPLE)
target_link_options(llama_main PRIVATE "LINKER:-s")
endif()
endif()

Expand Down
7 changes: 3 additions & 4 deletions examples/models/llava/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,9 @@ list(APPEND _common_include_directories ${stb_SOURCE_DIR}

add_executable(llava_main ${_srcs})
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
if(APPLE)
target_link_options(llava_main PRIVATE "LINKER:-dead_strip,-s")
else()
target_link_options(llava_main PRIVATE "LINKER:--gc-sections,-s")
target_link_options_gc_sections(llama_main)
if(NOT APPLE)
target_link_options(llama_main PRIVATE "LINKER:-s")
endif()
endif()

Expand Down
18 changes: 9 additions & 9 deletions examples/selective_build/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,22 +123,22 @@ gen_selected_ops(
)

generate_bindings_for_kernels(
LIB_NAME
"select_build_lib"
LIB_NAME
"select_build_lib"
FUNCTIONS_YAML
${EXECUTORCH_ROOT}/kernels/portable/functions.yaml
${EXECUTORCH_ROOT}/kernels/portable/functions.yaml
CUSTOM_OPS_YAML
"${_custom_ops_yaml}"
DTYPE_SELECTIVE_BUILD
"${EXECUTORCH_DTYPE_SELECTIVE_BUILD}"
)

gen_operators_lib(
LIB_NAME
"select_build_lib"
KERNEL_LIBS
${_kernel_lib}
DEPS
LIB_NAME
"select_build_lib"
KERNEL_LIBS
${_kernel_lib}
DEPS
executorch_core
DTYPE_SELECTIVE_BUILD
"${EXECUTORCH_DTYPE_SELECTIVE_BUILD}"
Expand All @@ -152,7 +152,7 @@ list(TRANSFORM _executor_runner__srcs PREPEND "${EXECUTORCH_ROOT}/")
#
add_executable(selective_build_test ${_executor_runner__srcs})
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
target_link_options(selective_build_test PRIVATE "LINKER:--gc-sections")
target_link_options_gc_sections(selective_build_test)
endif()
target_link_libraries(
selective_build_test PRIVATE executorch_core gflags select_build_lib
Expand Down
6 changes: 3 additions & 3 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ list(TRANSFORM _size_test__srcs PREPEND "${EXECUTORCH_ROOT}/")
add_executable(size_test ${_size_test__srcs})
target_link_libraries(size_test executorch)
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
target_link_options(size_test PRIVATE "LINKER:--gc-sections")
target_link_options_gc_sections(size_test)
endif()

#
Expand All @@ -65,7 +65,7 @@ target_link_libraries(
size_test_all_ops executorch portable_ops_lib portable_kernels
)
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
target_link_options(size_test_all_ops PRIVATE "LINKER:--gc-sections")
target_link_options_gc_sections(size_test_all_ops)
endif()

#
Expand All @@ -77,6 +77,6 @@ target_link_options_shared_lib(optimized_native_cpu_ops_lib)
target_link_libraries(
size_test_all_optimized_ops executorch optimized_native_cpu_ops_lib)
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
target_link_options(size_test_all_optimized_ops PRIVATE "LINKER:--gc-sections")
target_link_options_gc_sections(size_test_all_optimized_ops)
endif()
endif()
8 changes: 8 additions & 0 deletions tools/cmake/Utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ function(target_link_options_shared_lib target_name)
endif()
endfunction()

function(target_link_options_gc_sections target_name)
if(APPLE)
target_link_options(${target_name} PRIVATE "LINKER:-dead_strip")
else()
target_link_options(${target_name} PRIVATE "LINKER:--gc-sections")
endif()
endfunction()

# Extract source files based on toml config. This is useful to keep buck2 and
# cmake aligned. Do not regenerate if file exists.
function(extract_sources sources_file)
Expand Down
Loading