Skip to content

Add optional pkg-config support for PostgreSQL #14540

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

Merged
merged 1 commit into from
Jun 21, 2024

Conversation

petk
Copy link
Member

@petk petk commented Jun 11, 2024

The pkg-config (libpq.pc file) was added in PostgreSQL 9.3. This adds a common setup M4 macro PHP_SETUP_PGSQL to find libpq on the system with pkg-config. If not found, it falls back to pg_config to find the libpq library and its headers in common locations as before.

When using pkg-config, the PGSQL_CFLAGS and PGSQL_LIBS environment variables can override the paths to libpq installation:

./configure --with-pgsql --with-pdo-pgsql \
    PGSQL_CFLAGS=-I/path/to/libpq \
    PGSQL_LIBS="-L/path/to/libpq -lpq"

Follow-up of GH-4235 (Use PKG_CHECK_MODULES to detect the pq library)

@devnexen
Copy link
Member

The pkg-config (libpq.pc file) was added in PostgreSQL 9.3.

I think we can move up the minimal requirement a "tad", 9.3 is already 10 years+.

@petk
Copy link
Member Author

petk commented Jun 11, 2024

The pkg-config (libpq.pc file) was added in PostgreSQL 9.3.

I think we can move up the minimal requirement a "tad", 9.3 is already 10 years+.

We could probably, yes. According to Wikipedia PostgreSQL 11 is EOL and 12 will be EOL in November 2024. Something between 9.3 and 11, I guess: https://pkgs.org/search/?q=libpq

Which version would it be?

@remicollet do you have any concerns/suggestions about bumping minimum PostgreSQL version for PHP?

P.S.: Windows version is I think at the moment 11.4: https://github.com/winlibs/postgresql

@petk
Copy link
Member Author

petk commented Jun 11, 2024

  • In this PR there also comes soon one more LIBS and LDFLAGS adjustment for the custom paths...

@petk petk force-pushed the patch-pgsql-pkgconfig branch from a029549 to 6b18540 Compare June 13, 2024 14:05
@devnexen
Copy link
Member

The pkg-config (libpq.pc file) was added in PostgreSQL 9.3.

I think we can move up the minimal requirement a "tad", 9.3 is already 10 years+.

We could probably, yes. According to Wikipedia PostgreSQL 11 is EOL and 12 will be EOL in November 2024. Something between 9.3 and 11, I guess: https://pkgs.org/search/?q=libpq

Which version would it be?

@remicollet do you have any concerns/suggestions about bumping minimum PostgreSQL version for PHP?

P.S.: Windows version is I think at the moment 11.4: https://github.com/winlibs/postgresql

Maybe we can based on Centos 8 version (since 7 will be EOL soon), 9.6 or even 10.0.

@petk
Copy link
Member Author

petk commented Jun 14, 2024

Maybe we can based on Centos 8 version (since 7 will be EOL soon), 9.6 or even 10.0.

Yes, I think 10 it is quite a good pick. It's EOL for 2 years now so it's pretty safe pick in case of CentOS 8. I'll post it to internals mailing list also in case people still forget to open GitHub here. :D

Edit: Posted at https://news-web.php.net/php.internals/123609

@petk petk force-pushed the patch-pgsql-pkgconfig branch 2 times, most recently from 4281ebc to e5fcd13 Compare June 16, 2024 19:37
@petk
Copy link
Member Author

petk commented Jun 16, 2024

Here, one last thing remaining for the time being is the priority of the passed --with-*pgsql=DIR argument over the pkg-config. For example, if there is libpq library installed on the system and user wants to override the check with DIR argument (--with-pgsql=/custom/path/to/libpq/installation) then the pkg-config check should be done after the DIR check.

I'd also split the minimum version bump to a separate PR so the changes are more clear. For the PostgreSQL 10.0 check there is ideal function PQencryptPasswordConn to replace the PQlibVersion check. It was added to 10.0.

Coming up in the near future...

[AC_DEFINE([HAVE_PG_LO64], [1], [PostgreSQL 9.3 or later])],,
[$PGSQL_LIBS])
PHP_CHECK_LIBRARY([pq], [PQsetErrorContextVisibility],
[AC_DEFINE([HAVE_PG_CONTEXT_VISIBILITY], [1], [PostgreSQL 9.6 or later])],,
Copy link
Contributor

Choose a reason for hiding this comment

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

If you aim for 10.0, perhaps checks and ifdefs for HAVE_PG_LO64 and HAVE_PG_CONTEXT_VISIBILITY can be removed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, this will be cleaned up. In this PR I'd only refactor the check into a separate macro. In the follow up PR, this would be bumped to 10.0 and these conditions removed. And also the PQlibVersion check would be replaced there with PQencryptPasswordConn (added in 10.0).

@petk petk force-pushed the patch-pgsql-pkgconfig branch 3 times, most recently from 2efb2da to 9720927 Compare June 20, 2024 19:09
@petk
Copy link
Member Author

petk commented Jun 20, 2024

This is now wrapped up. Tested with installed libpq on the system, with pkg-config, without pkg-config, libpq installed in a custom directory, shared extensions, configure directory argument, PGSQL_CFLAGS and PGSQL_LIBS environment variables. So, this is ready for merge coming up then in the near future. The minimum libpq version bump to 10.0 will follow also shortly in a new PR...

The pkg-config (libpq.pc file) was added in PostgreSQL 9.3. This adds a
common setup M4 macro PHP_SETUP_PGSQL to find client PostgreSQL library
libpq on the system with pkg-config. If not found, check falls back to
pg_config to find the libpq and its headers in common locations as
before.

The PGSQL_CFLAGS and PGSQL_LIBS environment variables can override the
libpq installation paths:

    ./configure --with-pgsql --with-pdo-pgsql \
        PGSQL_CFLAGS=-I/path/to/libpq \
        PGSQL_LIBS="-L/path/to/libpq -lpq"

Passing manual, non-standard PostgreSQL installation path can be done
with configure option arguments:

    ./configure \
        --with-pgsql=/any/path/to/postgresql \
        --with-pdo-postgresql=/any/path/to/postgresql

If this DIR argument (PostgreSQL installation directory or path to the
pg_config) is passed, it takes precedence over the pkg-config, when
installed on the system.

This also removes the unused HAVE_LIBPQ symbol and passing the
PGSQL_INCLUDE and PGSQL_LIBDIR environment variable to configure in
favor of PGSQL_CFLAGS and PGSQL_LIBS.

Instead of the obsolete backticks the recommended $(...) is used when
invoking the pg_config.

Follow-up of phpGH-4235 (Use PKG_CHECK_MODULES to detect the pq library)
@petk petk force-pushed the patch-pgsql-pkgconfig branch from 9720927 to 88c91c6 Compare June 21, 2024 16:34
@petk
Copy link
Member Author

petk commented Jun 21, 2024

Branch rebased against master. Merging this and adjusting it further for the version bump.

@petk petk merged commit f4ce50d into php:master Jun 21, 2024
6 of 11 checks passed
@petk petk deleted the patch-pgsql-pkgconfig branch June 21, 2024 16:35
petk added a commit to petk/php-src that referenced this pull request Jun 21, 2024
This bumps the libpq client-side PostgreSQL library minimum required
version from 9.1 to 10.0.

- Sanity check: PQlibVersion -> PQencryptPasswordConn (available since
  libpq 10.0)
- PQsetErrorContextVisibility (available since libpq 9.6)
- lo_truncate64 (available since libpq 9.3), if 32-bit system doesn't
  support lo_*64 functions, error is returned and functions are always
  available

Additionally, the conditional functions usages in pdo_pgsql and pgsql
extensions that got piled up are cleaned and synced:

- pg_prepare (PQprepare available since libpq 7.4)
- pg_query_params (PQexecParams available since libpq 7.4)
- pg_result_error_field (PQresultErrorField available since libpq 7.4)
- pg_send_prepare (PQsendPrepare available since libpq 7.4)
- pg_send_query_params (PQsendQueryParams available since libpq 7.4)
- pg_set_error_verbosity (PQsetErrorVerbosity available since libpq 7.4)
- pg_transaction_status (PQtransactionStatus available since libpq 7.4)

The Windows libpq version updated to current 11.4 available at
https://github.com/winlibs/postgresql

Discussion: https://news-web.php.net/php.internals/123609
Follow-up of phpGH-14540
petk added a commit to petk/php-src that referenced this pull request Jun 23, 2024
This bumps the libpq client-side PostgreSQL library minimum required
version from 9.1 to 10.0.

- Sanity check: PQlibVersion -> PQencryptPasswordConn (available since
  libpq 10.0)
- PQsetErrorContextVisibility (available since libpq 9.6)
- lo_truncate64 (available since libpq 9.3), if 32-bit system doesn't
  support lo_*64 functions, error is returned and functions are always
  available

Additionally, the conditional functions usages in pdo_pgsql and pgsql
extensions that got piled up are cleaned and synced:

- pg_prepare (PQprepare available since libpq 7.4)
- pg_query_params (PQexecParams available since libpq 7.4)
- pg_result_error_field (PQresultErrorField available since libpq 7.4)
- pg_send_prepare (PQsendPrepare available since libpq 7.4)
- pg_send_query_params (PQsendQueryParams available since libpq 7.4)
- pg_set_error_verbosity (PQsetErrorVerbosity available since libpq 7.4)
- pg_transaction_status (PQtransactionStatus available since libpq 7.4)

The Windows libpq version updated to current 11.4 available at
https://github.com/winlibs/postgresql

Discussion: https://news-web.php.net/php.internals/123609
Follow-up of phpGH-14540
petk added a commit to petk/php-src that referenced this pull request Jun 23, 2024
This bumps the libpq client-side PostgreSQL library minimum required
version from 9.1 to 10.0.

- Sanity check: PQlibVersion -> PQencryptPasswordConn (available since
  libpq 10.0)
- PQsetErrorContextVisibility (available since libpq 9.6)
- lo_truncate64 (available since libpq 9.3), if 32-bit system doesn't
  support lo_*64 functions, error is returned and functions are always
  available

Additionally, the conditional functions usages in pdo_pgsql and pgsql
extensions that got piled up are cleaned and synced:

- pg_prepare (PQprepare available since libpq 7.4)
- pg_query_params (PQexecParams available since libpq 7.4)
- pg_result_error_field (PQresultErrorField available since libpq 7.4)
- pg_send_prepare (PQsendPrepare available since libpq 7.4)
- pg_send_query_params (PQsendQueryParams available since libpq 7.4)
- pg_set_error_verbosity (PQsetErrorVerbosity available since libpq 7.4)
- pg_transaction_status (PQtransactionStatus available since libpq 7.4)

The Windows libpq version is currently at version 11.4:
https://github.com/winlibs/postgresql

Discussion: https://news-web.php.net/php.internals/123609
Follow-up of phpGH-14540
petk added a commit that referenced this pull request Jun 25, 2024
This bumps the libpq client-side PostgreSQL library minimum required
version from 9.1 to 10.0.

- Sanity check: PQlibVersion -> PQencryptPasswordConn (available since
  libpq 10.0)
- PQsetErrorContextVisibility (available since libpq 9.6)
- lo_truncate64 (available since libpq 9.3), if 32-bit system doesn't
  support lo_*64 functions, error is returned and functions are always
  available

Additionally, the conditional functions usages in pdo_pgsql and pgsql
extensions that got piled up are cleaned and synced:

- pg_prepare (PQprepare available since libpq 7.4)
- pg_query_params (PQexecParams available since libpq 7.4)
- pg_result_error_field (PQresultErrorField available since libpq 7.4)
- pg_send_prepare (PQsendPrepare available since libpq 7.4)
- pg_send_query_params (PQsendQueryParams available since libpq 7.4)
- pg_set_error_verbosity (PQsetErrorVerbosity available since libpq 7.4)
- pg_transaction_status (PQtransactionStatus available since libpq 7.4)

The Windows libpq version is currently at version 11.4:
https://github.com/winlibs/postgresql

Discussion: https://news-web.php.net/php.internals/123609
Follow-up of GH-14540
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants