Skip to content
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

Build full-static LLVM tools binaries #216

Merged
merged 6 commits into from
Jul 22, 2024
Merged
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
20 changes: 19 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ set(CMAKE_CXX_STANDARD 17)
set(ABSL_PROPAGATE_CXX_STD on)

project(autofdo)
set (Protobuf_USE_STATIC_LIBS TRUE)

function (execute_perf_protobuf)

Expand Down Expand Up @@ -150,6 +151,12 @@ function (build_llvm)
endif()
endif()

# Disable GFLAGS and UNWIND for glog, we do not control glog using
# gflags, nor does call stacks used in log information. And glog
# does not provide a way to force static link these two libraries.
set (WITH_GFLAGS OFF)
set (WITH_UNWIND OFF)

### LLVM Configuration
set (LLVM_INCLUDE_UTILS OFF)
set (LLVM_INCLUDE_TESTS OFF)
Expand All @@ -162,6 +169,9 @@ function (build_llvm)
set (LLVM_TARGETS_TO_BUILD X86 AArch64 CACHE STRING
"Semicolon-separated list of LLVM targets to build, or \"all\".")
set (LLVM_ENABLE_ZSTD FORCE_ON)
set (LLVM_USE_STATIC_ZSTD TRUE CACHE BOOL "use static zstd")
# terminfo is not needed by create_llvm_prof
set (LLVM_ENABLE_TERMINFO OFF CACHE BOOL "enable terminfo")
###

add_subdirectory(third_party/abseil)
Expand Down Expand Up @@ -362,6 +372,7 @@ function (build_llvm)
add_test(NAME symbol_map_test COMMAND symbol_map_test)

find_library (LIBELF_LIBRARIES NAMES elf REQUIRED)
find_library (LIBZ_LIBRARIES NAMES z REQUIRED)
find_library (LIBCRYPTO_LIBRARIES NAMES crypto REQUIRED)

add_executable(llvm_profile_reader_test llvm_profile_reader_test.cc)
Expand Down Expand Up @@ -779,7 +790,7 @@ function (build_llvm)
third_party/perf_data_converter/src/quipper
${PROJECT_BINARY_DIR}/third_party/perf_data_converter/src/quipper)
target_link_libraries(quipper_perf
perf_proto ${LIBELF_LIBRARIES} ${LIBCRYPTO_LIBRARIES})
perf_proto ${LIBELF_LIBRARIES} ${LIBZ_LIBRARIES} ${LIBCRYPTO_LIBRARIES})

add_custom_command(PRE_BUILD
OUTPUT prepare_cmds
Expand All @@ -801,6 +812,13 @@ if (${enable_tool} STREQUAL gcov)
build_gcov()
elseif (${enable_tool} STREQUAL llvm)
message(STATUS "Building tool \"LLVM\" ...")

# Build static binaries.
set (BUILD_SHARED_LIBS OFF)
set (CMAKE_FIND_LIBRARY_SUFFIXES ".a")
# Link static executables.
set (CMAKE_EXE_LINKER_FLAGS "-static")

build_llvm()
else ()
message(FATAL_ERROR
Expand Down