From b8b74b7c66273d6506b2499ffe94c73dde288658 Mon Sep 17 00:00:00 2001 From: Andrey Arutiunian <110744283+andreylzmw@users.noreply.github.com> Date: Thu, 2 Nov 2023 17:12:51 +0300 Subject: [PATCH] Install h3 from cmake (#927) --- .github/workflows/Build.yml | 10 -------- cmake/external-libraries.cmake | 17 +++++++++++++ compiler/compiler-settings.cpp | 9 +++++++ .../compiling-kphp-from-sources.md | 25 ++++++------------- 4 files changed, 33 insertions(+), 28 deletions(-) diff --git a/.github/workflows/Build.yml b/.github/workflows/Build.yml index 413ef5711d..f56a518646 100644 --- a/.github/workflows/Build.yml +++ b/.github/workflows/Build.yml @@ -130,13 +130,6 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Get polyfills repo - uses: actions/checkout@v3 - with: - repository: 'uber/h3' - path: 'h3' - ref: stable-3.x - # because of https://github.com/orgs/Homebrew/discussions/4612 - name: Check Environment run: | @@ -151,9 +144,6 @@ jobs: brew link --overwrite --force shivammathur/php/php@7.4 /usr/local/Frameworks/Python.framework/Versions/3.11/bin/pip3 install jsonschema - - name: Build Uber h3 - run: cmake -DCMAKE_CXX_COMPILER=${{matrix.compiler}} -DCMAKE_CXX_STANDARD=${{matrix.cpp}} -S $GITHUB_WORKSPACE/h3 -B ${{runner.workspace}}/h3/build && make install -C ${{runner.workspace}}/h3/build -j$(nproc) all - - name: Run cmake run: cmake -DCMAKE_CXX_COMPILER=${{matrix.compiler}} -DCMAKE_CXX_STANDARD=${{matrix.cpp}} -DDOWNLOAD_MISSING_LIBRARIES=On -S $GITHUB_WORKSPACE -B ${{runner.workspace}}/build diff --git a/cmake/external-libraries.cmake b/cmake/external-libraries.cmake index 44a6734f28..f5851b960b 100644 --- a/cmake/external-libraries.cmake +++ b/cmake/external-libraries.cmake @@ -54,6 +54,23 @@ else() add_link_options(-L${kphp-timelib_SOURCE_DIR}/objs) endif() +find_library(KPHP_H3 h3) +if(KPHP_H3) + add_library(h3 STATIC IMPORTED ${KPHP_H3}) +else() + handle_missing_library("h3") + FetchContent_Declare( + h3 + GIT_REPOSITORY https://github.com/VKCOM/uber-h3.git + GIT_TAG fetch_content + ) + message(STATUS "---------------------") + FetchContent_MakeAvailable(h3) + include_directories(${h3_BINARY_DIR}/src/include) + add_definitions(-DKPHP_H3_LIB_DIR="${h3_BINARY_DIR}/lib") + add_link_options(-L${h3_BINARY_DIR}/lib) +endif() + if(APPLE) if (DEFINED ENV{EPOLL_SHIM_REPO}) FetchContent_Declare( diff --git a/compiler/compiler-settings.cpp b/compiler/compiler-settings.cpp index af61b1fe80..66058f47f1 100644 --- a/compiler/compiler-settings.cpp +++ b/compiler/compiler-settings.cpp @@ -332,6 +332,15 @@ void CompilerSettings::init() { ld_flags.value_ += " -L /usr/local/lib"; #endif +#ifdef KPHP_H3_LIB_DIR + ld_flags.value_ += " -L" KPHP_H3_LIB_DIR; +#else + // kphp-h3 is usually installed in /usr/local/lib; + // LDD may not find a library in /usr/local/lib if we don't add it here + // TODO: can we avoid this hardcoded library path? + ld_flags.value_ += " -L /usr/local/lib"; +#endif + std::vector external_libs{"pthread", "m", "dl"}; #ifdef PDO_DRIVER_MYSQL diff --git a/docs/kphp-internals/developing-and-extending-kphp/compiling-kphp-from-sources.md b/docs/kphp-internals/developing-and-extending-kphp/compiling-kphp-from-sources.md index ab5606e23e..7f460881dd 100644 --- a/docs/kphp-internals/developing-and-extending-kphp/compiling-kphp-from-sources.md +++ b/docs/kphp-internals/developing-and-extending-kphp/compiling-kphp-from-sources.md @@ -79,32 +79,21 @@ apt install git cmake make g++ gperf python3-minimal python3-jsonschema \ ``` -##### MacOS with Intel chipset +##### MacOS Make sure you have `brew` and `clang` (at least `Apple clang version 10.0.0`) ```bash +# Install dependencies brew tap shivammathur/php brew update brew install re2c cmake coreutils openssl libiconv re2 pcre yaml-cpp zstd googletest shivammathur/php/php@7.4 brew link --overwrite shivammathur/php/php@7.4 pip3 install jsonschema -``` -Clone somewhere local [epoll-shim from GitHub]({{site.url_package_epoll_shim}}) and switch to *osx-platform* branch. -Add env variable `EPOLL_SHIM_REPO` to your bash profile. It allows to avoid of cloning `epoll-shim` on each clean cmake call. -```bash -git clone https://github.com/VKCOM/epoll-shim.git -cd epoll-shim -git checkout osx-platform -echo 'export "EPOLL_SHIM_REPO=$(pwd)" >> ~/.bash_profile' -``` -Clone somewhere local [h3 from GitHub]({{site.url_package_h3_mac}}) and switch to *stable-3.x* branch. -```bash -git clone https://github.com/uber/h3.git -git checkout stable-3.x -mkdir build -cd build -cmake .. -sudo make install +# Build kphp +git clone https://github.com/VKCOM/kphp.git && cd kphp +mkdir build && cd build +cmake .. -DDOWNLOAD_MISSING_LIBRARIES=On +make -j$(nproc) ``` ##### Other Linux