Skip to content

Commit

Permalink
cc build: check that postgres and libpq versions don't diverge
Browse files Browse the repository at this point in the history
commit_hash:4d2e31002a018e3693df1734d3d0272bbc1d0b70
  • Loading branch information
Anton3 committed Dec 20, 2024
1 parent 75e9928 commit 0cea353
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
4 changes: 3 additions & 1 deletion cmake/ModuleHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -360,14 +360,16 @@ macro(_userver_module_end)
endmacro()

function(_userver_macos_set_default_dir variable command_args)
set(default_value "")
if(CMAKE_SYSTEM_NAME MATCHES "Darwin" AND NOT DEFINED ${variable})
execute_process(
COMMAND ${command_args}
OUTPUT_VARIABLE output
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set("${variable}" "${output}" CACHE PATH "")
set(default_value "${output}")
endif()
set("${variable}" "${default_value}" CACHE PATH "")
endfunction()

function(_userver_print_features_list)
Expand Down
3 changes: 1 addition & 2 deletions cmake/install/userver-postgresql-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ find_package(userver REQUIRED COMPONENTS
core
)

find_package(PostgreSQL REQUIRED)

if(EXISTS "${USERVER_CMAKE_DIR}/SetupPostgresqlDeps.cmake")
message(STATUS "libpq patch applied")
include("${USERVER_CMAKE_DIR}/SetupPostgresqlDeps.cmake")
else()
message(STATUS "libpq patches disabled")
find_package(PostgreSQL REQUIRED)
endif()

include("${USERVER_CMAKE_DIR}/UserverSql.cmake")
Expand Down
2 changes: 2 additions & 0 deletions cmake/install/userver-ydb-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ find_package(userver REQUIRED COMPONENTS

# include("${USERVER_CMAKE_DIR}/ydb-cpp-sdk.cmake")

include("${USERVER_CMAKE_DIR}/UserverSql.cmake")

set(userver_ydb_FOUND TRUE)
18 changes: 18 additions & 0 deletions postgresql/src/storages/postgres/detail/pg_connection_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@ auto PQXsendQueryPrepared(PGconn* conn, const char* stmtName, int nParams, const
#include <userver/storages/postgres/io/traits.hpp>
#include <userver/storages/postgres/message.hpp>

#if !defined(USERVER_NO_LIBPQ_PATCHES)
static_assert(
USERVER_LIBPQ_VERSION / 10000 == PG_VERSION_NUM / 10000,
"\n\n"
"======================================================================\n"
"Versions of postgres and libpq have diverged, check the output of cmake configure.\n"
"Either:\n"
" a) set USERVER_FEATURE_PATCH_LIBPQ to OFF\n"
" https://userver.tech/d5/d3d/md_en_2userver_2build_2options.html#cmake_options\n"
" b) install libpq of the same version as postgres server\n"
" and pass USERVER_PG_INCLUDE_DIR and USERVER_PG_LIBRARY_DIR cmake options to userver\n"
" https://userver.tech/de/db9/md_en_2userver_2build_2dependencies.html#autotoc_md183\n"
" c) build using the provided Docker containers or Conan\n"
" https://userver.tech/de/dab/md_en_2userver_2build_2build.html#postgres_deps_versions\n"
"======================================================================\n"
);
#endif

// NOLINTNEXTLINE(cppcoreguidelines-macro-usage): uses file/line info
#define PGCW_LOG_TRACE() LOG_TRACE() << log_extra_
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage): uses file/line info
Expand Down
6 changes: 4 additions & 2 deletions scripts/docs/en/userver/build/dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,11 @@ Feel free to provide a PR with instructions for your favorite platform at https:
If there's a strong need to build \b only the userver and run its tests, then see
@ref scripts/docs/en/userver/build/userver.md

@anchor postgres_deps_versions
## PostgreSQL versions
If CMake option USERVER_FEATURE_PATCH_LIBPQ is on, then the same developer version of libpq, libpgport and libpgcommon libraries
should be available on the system. If there are multiple versions of those libraries use `USERVER_PG_*` @ref cmake_options "CMake options"

If CMake option `USERVER_FEATURE_PATCH_LIBPQ` is on, then the same developer version of libpq, libpgport and libpgcommon libraries
should be available on the system. If there are multiple versions of those libraries, use `USERVER_PG_*` @ref cmake_options "CMake options"
to aid the build system in finding the right version.

You could also install any version of the above libraries by explicitly pinning the version. For example in Debian/Ubuntu pinning
Expand Down

0 comments on commit 0cea353

Please sign in to comment.