Skip to content

Detect release builds by comparing CMAKE_BUILD_TYPE to Debug, not Release #12045

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 3 commits 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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ if(EXECUTORCH_BUILD_EXECUTOR_RUNNER)
endif()

add_executable(executor_runner ${_executor_runner__srcs})
if(CMAKE_BUILD_TYPE STREQUAL "Release")
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
if(APPLE)
target_link_options(executor_runner PRIVATE "LINKER:-dead_strip")
else()
Expand Down
4 changes: 2 additions & 2 deletions backends/qualcomm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_link_options("-flto=auto")
endif()

if(CMAKE_BUILD_TYPE STREQUAL "Release")
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
# strip symbols
add_link_options("-s")

Expand Down Expand Up @@ -259,7 +259,7 @@ if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64")
pybind11_strip(PyQnnWrapperAdaptor)
endif()

if(CMAKE_BUILD_TYPE STREQUAL "Release")
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
# need to allow exceptions in pybind
set(_pybind_compile_options -Wno-deprecated-declarations -fPIC -frtti
-fexceptions
Expand Down
2 changes: 1 addition & 1 deletion examples/models/llama/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ if(ANDROID)
endif()

add_executable(llama_main ${_srcs})
if(CMAKE_BUILD_TYPE STREQUAL "Release")
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
if(APPLE)
target_link_options(llama_main PRIVATE "LINKER:-dead_strip")
else()
Expand Down
2 changes: 1 addition & 1 deletion examples/models/llava/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ list(APPEND _common_include_directories ${stb_SOURCE_DIR}
)

add_executable(llava_main ${_srcs})
if(CMAKE_BUILD_TYPE STREQUAL "Release")
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
if(APPLE)
target_link_options(llava_main PRIVATE "LINKER:-dead_strip,-s")
else()
Expand Down
2 changes: 1 addition & 1 deletion examples/selective_build/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ list(TRANSFORM _executor_runner__srcs PREPEND "${EXECUTORCH_ROOT}/")
# link to
#
add_executable(selective_build_test ${_executor_runner__srcs})
if(CMAKE_BUILD_TYPE EQUAL "Release")
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
target_link_options(selective_build_test PRIVATE "LINKER:--gc-sections")
endif()
target_link_libraries(
Expand Down
12 changes: 9 additions & 3 deletions kernels/portable/cpu/util/normalization_ops_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

#include <c10/util/irange.h>
#include <array>
#include <cstring>

#include <executorch/kernels/portable/cpu/util/normalization_ops_util.h>
Expand Down Expand Up @@ -92,6 +93,11 @@ bool check_layer_norm_args(
", ndim = %zu",
in.dim(),
ndim);
ET_CHECK_OR_RETURN_FALSE(
ndim <= kTensorDimensionLimit,
"Expected normalized shape to have at most %zu dimensions but it had %zu",
kTensorDimensionLimit,
ndim);
size_t shift = in.dim() - ndim;
for (const auto d : c10::irange(ndim)) {
ET_CHECK_OR_RETURN_FALSE(
Expand All @@ -103,20 +109,20 @@ bool check_layer_norm_args(
d,
normalized_shape[d]);
}
executorch::aten::SizesType shape[ndim];
std::array<executorch::aten::SizesType, kTensorDimensionLimit> shape;
for (const auto i : c10::irange(ndim)) {
shape[i] = static_cast<executorch::aten::SizesType>(normalized_shape[i]);
}

if (weight.has_value()) {
ET_LOG_AND_RETURN_IF_FALSE(tensors_have_same_dtype(in, weight.value()));
ET_LOG_AND_RETURN_IF_FALSE(
tensor_has_expected_size(weight.value(), {shape, ndim}));
tensor_has_expected_size(weight.value(), {shape.data(), ndim}));
}
if (bias.has_value()) {
ET_LOG_AND_RETURN_IF_FALSE(tensors_have_same_dtype(in, bias.value()));
ET_LOG_AND_RETURN_IF_FALSE(
tensor_has_expected_size(bias.value(), {shape, ndim}));
tensor_has_expected_size(bias.value(), {shape.data(), ndim}));
}
ET_LOG_AND_RETURN_IF_FALSE(tensors_have_same_dtype(in, out));
ET_LOG_AND_RETURN_IF_FALSE(tensors_have_same_dtype(in, mean_out));
Expand Down
6 changes: 3 additions & 3 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ list(TRANSFORM _size_test__srcs PREPEND "${EXECUTORCH_ROOT}/")
# when we cross compile to ios
add_executable(size_test ${_size_test__srcs})
target_link_libraries(size_test executorch)
if(CMAKE_BUILD_TYPE EQUAL "Release")
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
target_link_options(size_test PRIVATE "LINKER:--gc-sections")
endif()

Expand All @@ -64,7 +64,7 @@ target_link_options_shared_lib(portable_ops_lib)
target_link_libraries(
size_test_all_ops executorch portable_ops_lib portable_kernels
)
if(CMAKE_BUILD_TYPE EQUAL "Release")
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
target_link_options(size_test_all_ops PRIVATE "LINKER:--gc-sections")
endif()

Expand All @@ -76,7 +76,7 @@ add_executable(size_test_all_optimized_ops ${_size_test__srcs})
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(CMAKE_BUILD_TYPE EQUAL "Release")
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
target_link_options(size_test_all_optimized_ops PRIVATE "LINKER:--gc-sections")
endif()
endif()
3 changes: 3 additions & 0 deletions test/build_optimized_size_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,15 @@ test_cmake_size_test() {

echo 'ExecuTorch with no ops binary size, unstripped:'
ls -al cmake-out/test/size_test
size cmake-out/test/size_test

echo 'ExecuTorch with portable ops binary size, unstripped:'
ls -al cmake-out/test/size_test_all_ops
size cmake-out/test/size_test_all_ops

echo 'ExecuTorch with optimized ops binary size, unstripped:'
ls -al cmake-out/test/size_test_all_optimized_ops
size cmake-out/test/size_test_all_optimized_ops
}

if [[ -z $PYTHON_EXECUTABLE ]]; then
Expand Down
2 changes: 2 additions & 0 deletions test/build_size_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ test_cmake_size_test() {

echo 'ExecuTorch with no ops binary size, unstripped:'
ls -al cmake-out/test/size_test
size cmake-out/test/size_test

echo 'ExecuTorch with portable ops binary size, unstripped:'
ls -al cmake-out/test/size_test_all_ops
size cmake-out/test/size_test_all_ops
}

if [[ -z $PYTHON_EXECUTABLE ]]; then
Expand Down
2 changes: 1 addition & 1 deletion tools/cmake/preset/default.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

if(CMAKE_BUILD_TYPE STREQUAL "Release")
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
set(_is_build_type_release ON)
set(_is_build_type_debug OFF)
else()
Expand Down
Loading