facebook / proxygen

A collection of C++ HTTP libraries including an easy to use HTTP server.
Other
8.16k stars 1.5k forks source link

Build problems, segfault UT #496

Open jkammerland opened 7 months ago

jkammerland commented 7 months ago

Almost impossible to build AND use, need to fix packaging or provide instructions.

Also segfault on 1 unittest on master.

E.g if you try to use the packeges after installing you simply get 0.403 Could not find a package configuration file provided by "Sodium" with any 0.403 of the following names: 0.403 0.403 SodiumConfig.cmake 0.403 sodium-config.cmake

when using find_package(proxygen REQUIRED) after running [install.sh]

e.g when running cmake .. -DCMAKE_PREFIX_PATH=${DEPS_PATH}

for this:

# CMakeLists.txt
cmake_minimum_required(VERSION 3.15)
project(proxygen_server)

# Set C++17 as the default
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)

# Find required libraries
find_package(Proxygen REQUIRED)
jbeshay commented 7 months ago

Please use one of these scripts to build proxygen: https://github.com/facebook/proxygen/blob/main/proxygen/build.sh https://github.com/facebook/proxygen/blob/main/getdeps.sh

As you've already noticed in https://github.com/facebook/proxygen/issues/497, the build.sh installs the required dependencies including libsodium

jkammerland commented 7 months ago

Hello, thanks for the answer. I managed to to get it working with getdeps.sh. But it took alot of work to figure out a way to finally get it to build (out of the proxygen source dir), without too much dirty hacking.

As a user I want to be able to consume this library in an easy way. Perhaps you can understand what I do wrong by looking at my working example below. I have reduced and simplified as much as I possibly can. I made a Dockerfile to show all necessary other steps before you can start building (from a clean ubuntu:22.04). Please see the Dockerfile

FROM ubuntu:22.04

# Install required dependencies
RUN apt-get update && apt-get install -y git cmake g++ curl
WORKDIR /app

# Clone the Proxygen repository
RUN git clone https://github.com/facebook/proxygen.git

RUN apt-get install python3 python3-pip -y
RUN apt-get install -y openssl libssl-dev pkg-config
RUN apt-get install -y autoconf automake libtool

# Build and install Proxygen
WORKDIR /app/proxygen
RUN ./getdeps.sh

WORKDIR /app
COPY . .
RUN mkdir build && cd build && cmake .. && make -j$(nproc)

# Note you'll need to EXPOSE ports if you want to try the server outside the container

# Set the default command to run when the container starts
CMD ["./build/server"]

at https://github.com/jkammerland/proxygen-docker-example/blob/main/Dockerfile

Then for the CMakeLists.txt, I have made a comment on every line I needed to add to make it work

# The most minimal CMakeLists.txt file to build a proxygen server I could find

cmake_minimum_required(VERSION 3.15)
project(proxygen_server)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)

# Needed to find proxygen-config.cmake
list(APPEND CMAKE_PREFIX_PATH "/app/proxygen/_build")

# Needed to find sodium-config.cmake
list(APPEND CMAKE_MODULE_PATH "/app/proxygen/build/fbcode_builder/CMake")

# Otherwise you will not find sodium correctly. If you install with
# package-manager as well, you get warnings...
file(GLOB SODIUM_DIR "/app/proxygen/_build/libsodium-*")
if(SODIUM_DIR)
  list(APPEND CMAKE_PREFIX_PATH ${SODIUM_DIR})
else()
  message(FATAL_ERROR "Sodium directory not found")
endif()

# Find required libraries, for the eche server example
find_package(proxygen CONFIG REQUIRED)
find_package(gflags REQUIRED)
find_package(zstd CONFIG REQUIRED)
find_package(folly REQUIRED)
# find_package(sodium REQUIRED) # Will not work

add_executable(server EchoServer.cpp EchoHandler.cpp)

# Link the required libraries
target_link_libraries(server PUBLIC proxygen::proxygenhttpserver gflags zstd)

# This is needed to find libzstd, Using prefix path does not work
file(GLOB ZSTD_LIB_DIR "/app/proxygen/_build/zstd-*/lib")
if(ZSTD_LIB_DIR)
  target_link_directories(server PUBLIC ${ZSTD_LIB_DIR})
else()
  message(FATAL_ERROR "Zstd library directory not found")
endif()

at https://github.com/jkammerland/proxygen-docker-example/blob/main/CMakeLists.txt

I started trying to consume this lib through vcpkg, that also failed. I opened an issue over there too https://github.com/microsoft/vcpkg/issues/38086. So I came to try to figure out how to build it myself so I can maybe create a "working" vcpkg port.

Please have look and sanity check this. BR