Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PG source dir to system includes #6590

Merged
merged 1 commit into from
Feb 7, 2024

Conversation

erimatnor
Copy link
Contributor

@erimatnor erimatnor commented Feb 1, 2024

Add a CMake option to add the PostgreSQL source directory as a system include for the build system. This will ensure that the PG source include directory will end up in a generated compile_commands.json, which can be used by language servers (e.g., clangd) to navigate from the TimescaleDB source directly to the PostgreSQL source.

Disable-check: force-changelog-file

@erimatnor erimatnor added the build Issues related to building TimescaleDB or using its binaries label Feb 1, 2024
CMakeLists.txt Outdated
# includes BEFORE the installed PG include files. This will allow the LSP
# (e.g., clangd) to navigate to the PostgreSQL source instead of the install
# path directory that only has the headers.
include_directories(BEFORE SYSTEM ${PG_SOURCE_DIR}/src/include)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have include_directories(SYSTEM ${PG_INCLUDEDIR_SERVER}) in build-defs.cmake already, I wonder why it doesn't work for clangd.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using includes from source might be slightly confusing, because Timescale is compiled against the ${PG_INCLUDEDIR_SERVER}, which doesn't necessarily match the source includes. E.g. if you're using several out-of-source builds for Postgres with different configurations, the pg_config.h will be different.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have include_directories(SYSTEM ${PG_INCLUDEDIR_SERVER}) in build-defs.cmake already, I wonder why it doesn't work for clangd.

include_directories(SYSTEM ${PG_INCLUDEDIR_SERVER}) points to a different directory.

Good point about the pg_config.h. We could make this an optional override on the command line to protect against it.

I also tried using CMAKE_C_STANDARD_INCLUDE_DIRECTORIES on the command line but that always puts the PG source include after the installed header include directory, which won't help.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that your IDE can't go to definition from the installed headers, right? That's why you want the ones from source. Personally I just added the entire PG source into the IDE project and it works, but I'm using QT Creator, not sure how this translates to clangd.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's the problem. I am using Emacs + clangd, although I think it is a problem for all IDEs that use language server protocol (LSP) based on compile_commands.json unless they build their own index using some other method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@akuzm Added an option (default OFF) to enable this behavior. Now it won't interfere with out-of-source builds.

Add a CMake option to add the PostgreSQL source directory as a system
include for the build system. This will ensure that the PG source
include directory will end up in a generated `compile_commands.json`,
which can be used by language servers (e.g., clangd) to navigate from
the TimescaleDB source directly to the PostgreSQL source.
@erimatnor erimatnor changed the title Add PG source dir to system include Add PG source dir to system includes Feb 5, 2024
@erimatnor erimatnor requested a review from akuzm February 5, 2024 08:29
@erimatnor erimatnor marked this pull request as ready for review February 5, 2024 08:30
Copy link

github-actions bot commented Feb 5, 2024

@antekresic, @nikkhils: please review this pull request.

Powered by pull-review

@erimatnor erimatnor requested review from mkindahl and removed request for nikkhils February 5, 2024 08:31
Copy link

codecov bot commented Feb 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (cddb4e9) 79.82% compared to head (469a2b6) 79.52%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6590      +/-   ##
==========================================
- Coverage   79.82%   79.52%   -0.30%     
==========================================
  Files         190      190              
  Lines       37285    36972     -313     
  Branches     9458     9373      -85     
==========================================
- Hits        29761    29403     -358     
- Misses       3122     3146      +24     
- Partials     4402     4423      +21     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@mkindahl mkindahl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks safe to me, but I am surprised that there is no existing method to deal with this.

@erimatnor erimatnor merged commit c5fd41c into timescale:main Feb 7, 2024
53 checks passed
@erimatnor erimatnor deleted the include-pg-source-dir branch February 7, 2024 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Issues related to building TimescaleDB or using its binaries
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants