Skip to content

Commit

Permalink
Vendor and link C++ dependencies (#9581)
Browse files Browse the repository at this point in the history
Summary:
Since HHVM OSS currently only builds with libc++, we need to build all C++ dependencies from source against libc++, since their system library equivalents are built against libstdc++ on most distros and therefore ABI incompatible.

Add listfiles to conditionally build gflags and glog from source accordingly if the corresponding CLANG_FORCE_LIBCPP build option is set, and update existing listfiles to correctly forward compiler options so that vendored projects are also built against libc++ if the superproject is doing so.

As we're here, update the fmtlib version used by the project, as v8 is too old to build with.

Pull Request resolved: #9581

Reviewed By: Wilfred

Differential Revision: D68245981

fbshipit-source-id: 4cd4cc0f5ec286171b2bd239fadb48af96a7a161
  • Loading branch information
mszabo-wikia authored and facebook-github-bot committed Jan 17, 2025
1 parent 13de035 commit 91448a6
Show file tree
Hide file tree
Showing 10 changed files with 156 additions and 27 deletions.
12 changes: 4 additions & 8 deletions CMake/HPHPFindLibs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@ if (LIBDL_INCLUDE_DIRS)
endif()
endif()

# google-glog
find_package(Glog REQUIRED)
if (GLOG_STATIC)
add_definitions("-DGOOGLE_GLOG_DLL_DECL=")
endif()
include_directories(${GLOG_INCLUDE_DIR})

# inotify checks
find_package(Libinotify)
if (LIBINOTIFY_INCLUDE_DIR)
Expand Down Expand Up @@ -337,7 +330,7 @@ macro(hphp_link target)
target_link_libraries(${target} ${VISIBILITY} ${ICU_DATA_LIBRARIES} ${ICU_I18N_LIBRARIES} ${ICU_LIBRARIES})
target_link_libraries(${target} ${VISIBILITY} ${LIBEVENT_LIB})
target_link_libraries(${target} ${VISIBILITY} ${CURL_LIBRARIES})
target_link_libraries(${target} ${VISIBILITY} glog::glog)
target_link_libraries(${target} ${VISIBILITY} glog)

if (LIBINOTIFY_LIBRARY)
target_link_libraries(${target} ${VISIBILITY} ${LIBINOTIFY_LIBRARY})
Expand Down Expand Up @@ -406,10 +399,13 @@ macro(hphp_link target)
target_link_libraries(${target} ${VISIBILITY} fastlz)
endif()

target_link_libraries(${target} ${VISIBILITY} re2)

target_link_libraries(${target} ${VISIBILITY} timelib)
target_link_libraries(${target} ${VISIBILITY} folly)
target_link_libraries(${target} ${VISIBILITY} jemalloc)
target_link_libraries(${target} ${VISIBILITY} wangle)
target_link_libraries(${target} ${VISIBILITY} fizz)
target_link_libraries(${target} ${VISIBILITY} brotli)
target_link_libraries(${target} ${VISIBILITY} hhbc_ast_header)
target_link_libraries(${target} ${VISIBILITY} compiler_ffi)
Expand Down
2 changes: 2 additions & 0 deletions third-party/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ add_subdirectory(fmt)
add_subdirectory(jemalloc)
add_subdirectory(libsodium)
add_subdirectory(zstd)
add_subdirectory(gflags)
add_subdirectory(glog)

add_subdirectory(folly)

Expand Down
8 changes: 5 additions & 3 deletions third-party/fizz/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ get_target_property(LIBSODIUM_LIBRARY libsodium INTERFACE_LINK_LIBRARIES)
get_target_property(ZSTD_INCLUDE_DIR zstd INTERFACE_INCLUDE_DIRECTORIES)
get_target_property(ZSTD_LIBRARY zstd INTERFACE_LINK_LIBRARIES)
get_target_property(JEMALLOC_INCLUDE_DIR jemalloc INTERFACE_INCLUDE_DIRECTORIES)

get_target_property(GLOG_INCLUDE_DIR glog INTERFACE_INCLUDE_DIRECTORIES)
get_target_property(GLOG_LIBRARY glog INTERFACE_LINK_LIBRARIES)

set(
FIZZ_DEPS
Expand Down Expand Up @@ -66,8 +67,8 @@ ExternalProject_Add(
"-DBOOST_LIBRARYDIR=${BOOST_LIBRARY_DIR}"
-DDOUBLE_CONVERSION_INCLUDE_DIR=${DOUBLE_CONVERSION_INCLUDE_DIR}
-DDOUBLE_CONVERSION_LIBRARY=${DOUBLE_CONVERSION_LIBRARY}
-DLIBGLOG_INCLUDE_DIR=${GLOG_INCLUDE_DIR}
-DLIBGLOG_LIBRARY=${GLOG_LIBRARY}
-DGLOG_INCLUDE_DIR=${GLOG_INCLUDE_DIR}
-DGLOG_LIBRARY=${GLOG_LIBRARY}
-DLIBSODIUM_INCLUDEDIR=${LIBSODIUM_INCLUDE_DIR}
-DLIBSODIUM_LIBRARIES=${LIBSODIUM_LIBRARY}
-DZSTD_INCLUDE_DIR=${ZSTD_INCLUDE_DIR}
Expand All @@ -91,4 +92,5 @@ target_link_libraries(
"${INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}fizz${CMAKE_STATIC_LIBRARY_SUFFIX}"
fizz_deps
)

set(FIZZ_INSTALL_DIR "${INSTALL_DIR}" PARENT_SCOPE)
12 changes: 7 additions & 5 deletions third-party/fmt/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
find_package(fmt 8 CONFIG)
if (TARGET fmt::fmt)
find_package(fmt 9 CONFIG)
if (TARGET fmt::fmt AND NOT CLANG_FORCE_LIBCPP)
message(STATUS "Using system fmt: ${fmt_DIR}")
add_library(fmt INTERFACE)
add_dependencies(fmt fmt::fmt)
Expand All @@ -14,9 +14,9 @@ else()
SET_HHVM_THIRD_PARTY_SOURCE_ARGS(
FMT_SOURCE_ARGS
SOURCE_URL
"https://github.com/fmtlib/fmt/releases/download/8.0.0/fmt-8.0.0.zip"
"https://github.com/fmtlib/fmt/releases/download/11.1.1/fmt-11.1.1.zip"
SOURCE_HASH
"SHA512=70848739642bebf2820d661e7547208445329325a0d8b5919d85f375d683c0f9bef763bc7e9d7823def15100134fd9a126a9e418223b20bf8d567e5084334778"
"SHA512=6321f29b4ddabfcd92362883ca54039f5f2f90d85d95af1410ba98607acdde02c8c02b61c4fad212337aa2938681e038cd4533013b4e1f500c6839f77a74aeca"
)

set(INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/fmt-prefix")
Expand All @@ -31,6 +31,8 @@ else()
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_OSX_SYSROOT=${CMAKE_OSX_SYSROOT}
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
-DFMT_TEST=Off
)
cmake_minimum_required(VERSION 2.8.0)
ExternalProject_get_property(bundled_fmt INSTALL_DIR)
Expand All @@ -42,4 +44,4 @@ else()
"${INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}fmt$<$<CONFIG:Debug>:d>${CMAKE_STATIC_LIBRARY_SUFFIX}"
)
set(fmt_DIR "${INSTALL_DIR}/lib/cmake/fmt" PARENT_SCOPE)
endif()
endif()
16 changes: 12 additions & 4 deletions third-party/folly/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ get_target_property(LIBSODIUM_LIBRARY libsodium INTERFACE_LINK_LIBRARIES)
get_target_property(ZSTD_INCLUDE_DIR zstd INTERFACE_INCLUDE_DIRECTORIES)
get_target_property(ZSTD_LIBRARY zstd INTERFACE_LINK_LIBRARIES)
get_target_property(JEMALLOC_INCLUDE_DIR jemalloc INTERFACE_INCLUDE_DIRECTORIES)
get_target_property(GFLAGS_INCLUDE_DIR gflags INTERFACE_INCLUDE_DIRECTORIES)
get_target_property(GFLAGS_LIBRARY gflags INTERFACE_LINK_LIBRARIES)
get_target_property(GLOG_INCLUDE_DIR glog INTERFACE_INCLUDE_DIRECTORIES)
get_target_property(GLOG_LIBRARY glog INTERFACE_LINK_LIBRARIES)

get_target_property(BOOST_LIBRARIES boost INTERFACE_LINK_LIBRARIES)
list(GET BOOST_LIBRARIES 0 FIRST_LIB)
Expand Down Expand Up @@ -38,7 +42,8 @@ ExternalProject_add(
"${CMAKE_CURRENT_SOURCE_DIR}/patches"
LIST_SEPARATOR "!!"
CMAKE_ARGS
"-DCMAKE_CXX_FLAGS=${FOLLY_CXXFLAGS}"
-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}
"-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} ${FOLLY_CXXFLAGS}"
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_OSX_SYSROOT=${CMAKE_OSX_SYSROOT}
Expand All @@ -55,8 +60,10 @@ ExternalProject_add(
# Dependencies
-DOPENSSL_INCLUDE_DIR=${OPENSSL_INCLUDE_DIR}
-DOPENSSL_CRYPTO_LIBRARY=${OPENSSL_CRYPTO_LIBRARY}
-DGLOG_INCLUDE_DIR=${LIBGLOG_INCLUDE_DIR}
-DGLOG_LIBRARY=glog::glog
-DGFLAGS_INCLUDE_DIR=${GFLAGS_INCLUDE_DIR}
-DGFLAGS_LIBRARY=${GFLAGS_LIBRARY}
-DGLOG_INCLUDE_DIR=${GLOG_INCLUDE_DIR}
-DGLOG_LIBRARY=glog
-DBoost_NO_SYSTEM_PATHS=ON
-DBoost_NO_BOOST_CMAKE=ON
-DBoost_USE_STATIC_LIBS=${Boost_USE_STATIC_LIBS}
Expand Down Expand Up @@ -89,7 +96,8 @@ set(
libsodium
jemalloc
zstd
glog::glog
gflags
glog
)
add_dependencies(bundled_folly ${FOLLY_DEPS})
add_library(folly_deps INTERFACE)
Expand Down
55 changes: 55 additions & 0 deletions third-party/gflags/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
if (NOT CLANG_FORCE_LIBCPP)
find_package(gflags CONFIG)

if (TARGET gflags::gflags)
message(STATUS "Using system gflags")

add_library(gflags INTERFACE)
add_dependencies(gflags gflags::gflags)
target_link_libraries(gflags INTERFACE gflags::gflags)

get_target_property(GFLAGS_INCLUDE_DIR gflags::gflags INTERFACE_INCLUDE_DIRECTORIES)

target_include_directories(gflags INTERFACE ${GFLAGS_INCLUDE_DIR})

return()
endif()
endif()

message(STATUS "Using third-party bundled gflags")
include(ExternalProject)
include(HPHPFunctions)

SET_HHVM_THIRD_PARTY_SOURCE_ARGS(
GFLAGS_SOURCE_ARGS
SOURCE_URL
"https://github.com/gflags/gflags/archive/refs/tags/v2.2.2.tar.gz"
SOURCE_HASH
"SHA256=34af2f15cf7367513b352bdcd2493ab14ce43692d2dcd9dfc499492966c64dcf"
)

set(INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/gflags-prefix")
ExternalProject_add(
bundled_gflags
${GFLAGS_SOURCE_ARGS}
CMAKE_ARGS
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
-DCMAKE_INSTALL_INCLUDEDIR=include
-DCMAKE_INSTALL_LIBDIR=lib
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_OSX_SYSROOT=${CMAKE_OSX_SYSROOT}
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
)

ExternalProject_get_property(bundled_gflags INSTALL_DIR)

add_library(gflags INTERFACE)
add_dependencies(gflags bundled_gflags)
target_include_directories(gflags INTERFACE "${INSTALL_DIR}/include")
target_link_libraries(gflags INTERFACE
"${INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}gflags$<$<CONFIG:Debug>:_debug>${CMAKE_STATIC_LIBRARY_SUFFIX}"
)

set(gflags_DIR "${INSTALL_DIR}/lib/cmake/gflags" PARENT_SCOPE)
58 changes: 58 additions & 0 deletions third-party/glog/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
if(CLANG_FORCE_LIBCPP)
include(ExternalProject)
include(HPHPFunctions)

SET_HHVM_THIRD_PARTY_SOURCE_ARGS(
GLOG_SOURCE_ARGS
SOURCE_URL
"https://github.com/google/glog/archive/refs/tags/v0.5.0.zip"
SOURCE_HASH
"SHA512=46669f603279edc05e98153247897c8a7b50ebc9e800132cc8c3eef531687691e616b5210ed9a1dfbb5170ea354b76fb9244b383a8d309bacbfcf2810ec07546"
)

set(INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/glog-prefix")
ExternalProject_add(
bundled_glog
${GLOG_SOURCE_ARGS}
CMAKE_ARGS
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
-DCMAKE_INSTALL_INCLUDEDIR=include
-DCMAKE_INSTALL_LIBDIR=lib
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_OSX_SYSROOT=${CMAKE_OSX_SYSROOT}
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}

-DBUILD_SHARED_LIBS=Off
-DBUILD_EXAMPLES=Off
-DBUILD_TESTING=Off

-Dgflags_DIR=${gflags_DIR}
)
ExternalProject_get_property(bundled_glog INSTALL_DIR)

add_dependencies(bundled_glog gflags)

add_library(glog INTERFACE)
add_dependencies(glog bundled_glog)
target_include_directories(glog INTERFACE "${INSTALL_DIR}/include")
target_link_libraries(glog INTERFACE
"${INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}glog$<$<CONFIG:Debug>:d>${CMAKE_STATIC_LIBRARY_SUFFIX}"
gflags
)

set(GLOG_INSTALL_DIR "${INSTALL_DIR}" PARENT_SCOPE)
else()
# google-glog
find_package(Glog REQUIRED)
if (GLOG_STATIC)
add_definitions("-DGOOGLE_GLOG_DLL_DECL=")
endif()
include_directories(${GLOG_INCLUDE_DIR})

add_library(glog INTERFACE)
add_dependencies(glog glog::glog)
target_link_libraries(glog INTERFACE ${GLOG_LIBRARIES})
target_include_directories(glog INTERFACE ${GLOG_INCLUDE_DIRS})
endif()
3 changes: 2 additions & 1 deletion third-party/re2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
add_library(re2 INTERFACE)

find_package(RE2)
if(RE2_LIBRARY)
if(RE2_LIBRARY AND NOT CLANG_FORCE_LIBCPP)
target_link_libraries(re2 INTERFACE ${RE2_LIBRARY})
target_include_directories(re2 INTERFACE ${RE2_INCLUDE_DIR})
return() # from File
Expand Down Expand Up @@ -33,6 +33,7 @@ ExternalProject_Add(
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_OSX_SYSROOT=${CMAKE_OSX_SYSROOT}
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}

-DBUILD_TESTING=OFF
-DRE2_BUILD_TESTING=OFF
Expand Down
8 changes: 6 additions & 2 deletions third-party/thrift/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ get_filename_component(BOOST_LIBRARY_DIR "${FIRST_LIB}" DIRECTORY)
get_target_property(ZSTD_INCLUDE_DIR zstd INTERFACE_INCLUDE_DIRECTORIES)
get_target_property(ZSTD_LIBRARY zstd INTERFACE_LINK_LIBRARIES)
get_target_property(JEMALLOC_INCLUDE_DIR jemalloc INTERFACE_INCLUDE_DIRECTORIES)
get_target_property(GLOG_INCLUDE_DIR glog INTERFACE_INCLUDE_DIRECTORIES)
get_target_property(GLOG_LIBRARY glog INTERFACE_LINK_LIBRARIES)

get_filename_component(GLOG_LIBRARY_DIR "${GLOG_LIBRARY}" DIRECTORY)

find_package(FLEX REQUIRED)
# Thrift uses `%code`, which isn't in 2.x
Expand Down Expand Up @@ -44,8 +48,8 @@ ExternalProject_Add(
-DBoost_USE_STATIC_LIBS=${Boost_USE_STATIC_LIBS}
-DBoost_INCLUDE_DIR=${BOOST_INCLUDE_DIR}
"-DBOOST_LIBRARYDIR=${BOOST_LIBRARY_DIR}"
"-DLIBGLOG_INCLUDE_DIR=${GLOG_INCLUDE_DIR}"
"-DLIBGLOG_LIBRARY=${GLOG_LIBRARY}"
-DGLOG_INCLUDEDIR=${GLOG_INCLUDE_DIR}
-DGLOG_LIBRARYDIR=${GLOG_LIBRARY_DIR}
"-DZSTD_INCLUDE_DIRS=${ZSTD_INCLUDE_DIR}"
"-DZSTD_LIBRARIES=${ZSTD_LIBRARY}"

Expand Down
9 changes: 5 additions & 4 deletions third-party/wangle/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ get_target_property(DOUBLE_CONVERSION_LIBRARY double-conversion INTERFACE_LINK_L
get_target_property(ZSTD_INCLUDE_DIR zstd INTERFACE_INCLUDE_DIRECTORIES)
get_target_property(ZSTD_LIBRARY zstd INTERFACE_LINK_LIBRARIES)
get_target_property(JEMALLOC_INCLUDE_DIR jemalloc INTERFACE_INCLUDE_DIRECTORIES)

get_target_property(GLOG_INCLUDE_DIR glog INTERFACE_INCLUDE_DIRECTORIES)
get_target_property(GLOG_LIBRARY glog INTERFACE_LINK_LIBRARIES)

ExternalProject_Add(
bundled_wangle
Expand Down Expand Up @@ -50,16 +51,16 @@ ExternalProject_Add(
"-DBOOST_LIBRARYDIR=${BOOST_LIBRARY_DIR}"
-DDOUBLE_CONVERSION_INCLUDE_DIR=${DOUBLE_CONVERSION_INCLUDE_DIR}
-DDOUBLE_CONVERSION_LIBRARY=${DOUBLE_CONVERSION_LIBRARY}
-DLIBGLOG_INCLUDE_DIR=${GLOG_INCLUDE_DIR}
-DLIBGLOG_LIBRARY=${GLOG_LIBRARY}
-DGLOG_INCLUDE_DIR=${GLOG_INCLUDE_DIR}
-DGLOG_LIBRARY=${GLOG_LIBRARY}
-DZSTD_INCLUDE_DIR=${ZSTD_INCLUDE_DIR}
-DZSTD_LIBRARY_RELEASE=${ZSTD_LIBRARY}

"-Dfizz_DIR=${FIZZ_INSTALL_DIR}/lib/cmake/fizz"
"-Dfmt_DIR=${fmt_DIR}"
"-Dfolly_DIR=${FOLLY_INSTALL_DIR}/lib/cmake/folly"

"-DCMAKE_CXX_FLAGS=-I${JEMALLOC_INCLUDE_DIR}"
"-DCMAKE_CXX_FLAGS=-I${JEMALLOC_INCLUDE_DIR} ${CMAKE_CXX_FLAGS}"
)
ExternalProject_Get_property(bundled_wangle INSTALL_DIR)

Expand Down

0 comments on commit 91448a6

Please sign in to comment.