From e05054d1a901b795ba5be1642721892403ea86e2 Mon Sep 17 00:00:00 2001 From: Chen Lai Date: Mon, 22 Apr 2024 18:57:46 -0700 Subject: [PATCH 1/2] strip symbol when linking (#3234) Summary: Refer to https://sourceware.org/binutils/docs/binutils/strip.html command to build for android ``` rm -rf cmake-android-out && mkdir cmake-android-out cmake -DBUCK2="$BUCK" \ -DCMAKE_INSTALL_PREFIX=cmake-android-out \ -DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK}/build/cmake/android.toolchain.cmake" \ -DANDROID_ABI="arm64-v8a" \ -DANDROID_PLATFORM=android-29 \ -DCMAKE_BUILD_TYPE=Release \ -DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \ -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \ -DEXECUTORCH_BUILD_CUSTOM=ON \ -DEXECUTORCH_BUILD_OPTIMIZED=ON \ -DEXECUTORCH_BUILD_QUANTIZED=ON \ -DEXECUTORCH_BUILD_XNNPACK=ON \ -DEXECUTORCH_ENABLE_LOGGING=ON \ -Bcmake-android-out . cmake --build cmake-android-out -j16 --target install --config Release cmake -DBUCK2="$BUCK" \ -DCMAKE_INSTALL_PREFIX=cmake-android-out \ -DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK}/build/cmake/android.toolchain.cmake" \ -DANDROID_ABI="arm64-v8a" \ -DANDROID_PLATFORM=android-23 \ -DCMAKE_BUILD_TYPE=Release \ -DEXECUTORCH_BUILD_CUSTOM=ON \ -DEXECUTORCH_BUILD_OPTIMIZED=ON \ -DEXECUTORCH_BUILD_XNNPACK=ON \ -DEXECUTORCH_ENABLE_LOGGING=ON \ -DEXECUTORCH_USE_TIKTOKEN=ON \ -Bcmake-android-out/${dir} \ ${dir} cmake --build cmake-android-out/${dir} -j16 --config Release ``` ``` (executorch) chenlai@chenlai-mbp executorch % du -sh cmake-android-out/examples/models/llama2/* 44K cmake-android-out/examples/models/llama2/CMakeCache.txt 2.2M cmake-android-out/examples/models/llama2/CMakeFiles 76K cmake-android-out/examples/models/llama2/Makefile 4.0K cmake-android-out/examples/models/llama2/cmake_install.cmake 4.0K cmake-android-out/examples/models/llama2/compile_commands.json 4.9M cmake-android-out/examples/models/llama2/custom_ops 736K cmake-android-out/examples/models/llama2/lib 54M cmake-android-out/examples/models/llama2/llama_main 16K cmake-android-out/examples/models/llama2/options-pinned.h 11M cmake-android-out/examples/models/llama2/runner 151M cmake-android-out/examples/models/llama2/third-party ``` Reviewed By: lucylq, kirklandsign Differential Revision: D56450794 --- examples/models/llama2/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/models/llama2/CMakeLists.txt b/examples/models/llama2/CMakeLists.txt index dd0a1c022c0..17841cd4eb4 100644 --- a/examples/models/llama2/CMakeLists.txt +++ b/examples/models/llama2/CMakeLists.txt @@ -175,8 +175,8 @@ if(ANDROID) endif() add_executable(llama_main ${_srcs}) -if(CMAKE_BUILD_TYPE EQUAL "RELEASE") - target_link_options(llama_main PRIVATE "LINKER:--gc-sections") +if(CMAKE_BUILD_TYPE STREQUAL "Release") + target_link_options(llama_main PRIVATE "LINKER:--gc-sections,-s") endif() target_include_directories(llama_main PUBLIC ${_common_include_directories}) From 9674cfa79c869531f02a76bed843aa8a3589c767 Mon Sep 17 00:00:00 2001 From: Chen Lai Date: Mon, 22 Apr 2024 18:57:46 -0700 Subject: [PATCH 2/2] fix typo Summary: It's "Release" not "RELEASE".... Differential Revision: D56451118 --- examples/selective_build/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/selective_build/CMakeLists.txt b/examples/selective_build/CMakeLists.txt index 239cdc828de..247a269d94b 100644 --- a/examples/selective_build/CMakeLists.txt +++ b/examples/selective_build/CMakeLists.txt @@ -115,7 +115,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(CMAKE_BUILD_TYPE EQUAL "Release") target_link_options(selective_build_test PRIVATE "LINKER:--gc-sections") endif() target_link_libraries(