Skip to content

Commit 7b1cf49

Browse files
cccclaipytorchbot
authored andcommitted
strip symbol when linking (#3234)
Summary: Pull Request resolved: #3234 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 fbshipit-source-id: 79e77732713708f3ced3801d11e30a9141075a76 (cherry picked from commit d8e94b0)
1 parent 66783f4 commit 7b1cf49

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

examples/models/llama2/CMakeLists.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,14 @@ if(ANDROID)
120120
list(APPEND link_libraries log)
121121
endif()
122122

123-
target_compile_options(llama_main PUBLIC ${_common_compile_options}
124-
-DET_USE_THREADPOOL)
125-
target_link_libraries(llama_main PUBLIC ${link_libraries})
123+
add_executable(llama_main ${_srcs})
124+
if(CMAKE_BUILD_TYPE STREQUAL "Release")
125+
target_link_options(llama_main PRIVATE "LINKER:--gc-sections,-s")
126+
endif()
127+
128+
target_include_directories(llama_main PUBLIC ${_common_include_directories})
129+
target_link_libraries(llama_main PUBLIC llama_runner ${link_libraries})
130+
target_compile_options(llama_main PUBLIC ${_common_compile_options})
126131

127132
if(APPLE)
128133
target_link_options_shared_lib(executorch)

0 commit comments

Comments
 (0)