From 91dd6f0a0ea74b6505aeb640d83964f6dc85101a Mon Sep 17 00:00:00 2001 From: Huang Qi Date: Thu, 18 Apr 2024 09:42:46 +0800 Subject: [PATCH] Link libc++ statically to reduce runtime dependency of wamrc --- build-scripts/build_llvm.py | 1 + wamr-compiler/CMakeLists.txt | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/build-scripts/build_llvm.py b/build-scripts/build_llvm.py index e5036e5ca..04ba19fae 100755 --- a/build-scripts/build_llvm.py +++ b/build-scripts/build_llvm.py @@ -66,6 +66,7 @@ def build_llvm(llvm_dir, platform, backends, projects, use_clang=False, extra_fl "-DLLVM_INCLUDE_UTILS:BOOL=OFF", "-DLLVM_INCLUDE_TESTS:BOOL=OFF", "-DLLVM_OPTIMIZED_TABLEGEN:BOOL=ON", + "-DLLVM_STATIC_LINK_CXX_STDLIB=ON", ] # ccache is not available on Windows diff --git a/wamr-compiler/CMakeLists.txt b/wamr-compiler/CMakeLists.txt index 6a3f97521..4abf7f325 100644 --- a/wamr-compiler/CMakeLists.txt +++ b/wamr-compiler/CMakeLists.txt @@ -387,6 +387,12 @@ if (NOT MSVC) target_link_libraries (wamrc ssp.a ws2_32) else() target_link_libraries (wamrc -ldl) + # Link libc++ statically to reduce the runtime dependency + target_link_libraries (wamrc -static-libstdc++) + # If not on macOS, link libgcc statically + if (NOT APPLE) + target_link_libraries (wamrc -static-libgcc) + endif() endif() else() target_link_libraries (wamrc aotclib vmlib ${lib_lldb} ${WAMRC_LINK_LLVM_LIBS} ${lib_ubsan}