microsoft / vcpkg

C++ Library Manager for Windows, Linux, and MacOS
MIT License
22.51k stars 6.21k forks source link

[New Port Request] braft #22763

Closed Gab-Menezes closed 2 years ago

Gab-Menezes commented 2 years ago

Library name: braft

Library description: A library that implements consensus algorithms.

Source repository URL: https://github.com/baidu/braft

OBS: I wanted to try to do this port, but I never made one. So any resources, tips and help are welcomed.

Gab-Menezes commented 2 years ago

Depends on https://github.com/microsoft/vcpkg/pull/22685, since braft needs brpc

Gab-Menezes commented 2 years ago

@JackBoosY hey, since we found the brpc problem I started creating the braft port. I was able to build it already, but I have a few questions. Both brpc and braft doesn't include *config.cmake file, so how can I link them in my executables ? Because we usually do

find_package(<name> CONFIG REQUIRED)
target_link_libraries(main PRIVATE <name>::<name>)

But when I try to find_package(brpc CONFIG REQUIRED) or find_package(braft CONFIG REQUIRED) i get the error saying

CMake Error at CMakeLists.txt:4 (find_package):
  Could not find a package configuration file provided by "braft" with any of
  the following names:

    braftConfig.cmake
    braft-config.cmake

  Add the installation prefix of "braft" to CMAKE_PREFIX_PATH or set
  "braft_DIR" to a directory containing one of the above files.  If "braft"
  provides a separate development package or SDK, be sure it has been
  installed.

So my question is how can I link those types of libraries ? And why when building braft (the only patch I applied was to remove the braft cli compilation) it was able to locate and link with brpc ? Because if a copy the way that braft finds brpc I sill get ther error message "Fail to find brpc".

find_path(BRPC_INCLUDE_PATH NAMES brpc/server.h)
find_library(BRPC_LIB NAMES libbrpc.a brpc)
if ((NOT BRPC_INCLUDE_PATH) OR (NOT BRPC_LIB))
    message(FATAL_ERROR "Fail to find brpc")
endif()
JackBoosY commented 2 years ago

If the upstream doesn't support exporting the cmake configure files, we may need to write the find code such as find_path / find_library manually.

JackBoosY commented 2 years ago

@Gab-Menezes Also, you can make a patch to export them. Can you please make a PR to add this port?

Thanks.

Gab-Menezes commented 2 years ago

@JackBoosY can you guide me on how to export a package ? I have never done it. I tried searching it and found some resources but it didn't make much sense.

JackBoosY commented 2 years ago

In CMakeLists.txt

install(TARGETS braft EXPORT unofficial-braftTargets)
install(EXPORT unofficial-braftTargets
    NAMESPACE unofficial::braft::
    DESTINATION share/unofficial-braft
)

if this port doesn't have any dependencies.

In portfile.cmake:

vcpkg_cmake_config_fixup(PACKAGE_NAME unofficial-braft CONFIG_PATH share/unofficial-braft)
Gab-Menezes commented 2 years ago

So I added the the install in the CMakeLists.txt and changed the target from braft to braft-static (since this is the name used).

install(TARGETS braft-static EXPORT unofficial-braftTargets)
install(EXPORT unofficial-braftTargets
    NAMESPACE unofficial::braft::
    DESTINATION share/unofficial-braft
)

And added the vcpkg_cmake_config_fixup in the portfile.cmake, but got an error.

CMake Error at installed/x64-linux/share/vcpkg-cmake-config/vcpkg_cmake_config_fixup.cmake:135 (message):

  '/mnt/c/dev/vcpkg-dev/vcpkg/packages/braft_x64-linux/debug/share/unofficial-braft'
  does not exist.
Call Stack (most recent call first):
  ports/braft/portfile.cmake:25 (vcpkg_cmake_config_fixup)
  scripts/ports.cmake:145 (include)

Error: Building package braft:x64-linux failed with: BUILD_FAILED
Please ensure you're using the latest portfiles with `git pull` and `./vcpkg update`.
Then check for known issues at:
  https://github.com/microsoft/vcpkg/issues?q=is%3Aissue+is%3Aopen+in%3Atitle+braft
You can submit a new issue at:
  https://github.com/microsoft/vcpkg/issues/new?template=report-package-build-failure.md&title=[braft]+Build+error
including:
  package: braft[core]:x64-linux -> 2021-26-04
    vcpkg-tool version: 2021-12-09-724cea8b33cbf06c645f5095fa29773697da9761
    vcpkg-scripts version: 9ff4659a0 2022-03-25 (30 hours ago)

Additionally, attach any relevant sections from the log files above.

As far as I know the install step should have created the folder "/packages/braft_x64-linux/debug/share/unofficial-braft" with "Targets.cmake" and "noconfig.cmake", but it didn't. I pushed the changes to my fork of vcpkg if you want to take a look.

JackBoosY commented 2 years ago

@Gab-Menezes Please note that if you don't use patch to add the cmake code and without --debug in the install command, vcpkg will always create a new source directory.

Can you please make a PR so I can take a look?

Gab-Menezes commented 2 years ago

here https://github.com/microsoft/vcpkg/pull/23830

Gab-Menezes commented 2 years ago

Got merged, closing the issue