Skip to content

cmake: Only refer to .pc files for GSS-API if found - #15535

Closed
diizzyy wants to merge 1 commit into
curl:masterfrom
diizzyy:patch-1
Closed

diizzyy wants to merge 1 commit into
curl:masterfrom
diizzyy:patch-1

Conversation

@diizzyy

@diizzyy diizzyy commented Nov 10, 2024

Copy link
Copy Markdown
Contributor

Only refer to pkg-config files if they're found otherwise omit adding reference to Requires.private in curl's .pc file

Only refer to pkg-config files if they're found otherwise omit adding reference to Requires.private in curl's .pc file
@diizzyy

diizzyy commented Nov 10, 2024 •

Copy link
Copy Markdown
Contributor Author

@vszakats
I think I understood the logic correctly

This is for example true if you're on FreeBSD and use "base" GSS-API (the version included in the distro itself)

@vszakats

vszakats commented Nov 10, 2024 •

Copy link
Copy Markdown
Member

Thanks for your report and patch.

Do I understand correctly that GSS is correctly detected, but you don't want this detection to trigger adding heimdal-gssapi to the Required.private list in this particular case? Does FreeBSD not have a heimdal-gssapi.pc file?

This case in CI:
cmake: https://github.com/curl/curl/actions/runs/11756680325/job/32753075659#step:4:539
autotools: https://github.com/curl/curl/actions/runs/11756680325/job/32753074908#step:3:1153

@diizzyy

diizzyy commented Nov 10, 2024 •

Copy link
Copy Markdown
Contributor Author

@vszakats
Yes, that's exactly the case but it should still validate irregardless how GSS was detected.

Edit:
To clarify, the ones installed from ports to however have pc files
https://www.freshports.org/security/krb5
https://www.freshports.org/security/heimdal

@vszakats

Copy link
Copy Markdown
Member

@vszakats Yes, that's exactly the case but it should still validate irregardless how GSS was detected.

Would it be a solution to skip adding this reference when the target OS is FreeBSD?
In both CMake and autotools.

Something like:

--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1246,7 +1246,9 @@ if(CURL_USE_GSSAPI)
     elseif(GSS_FLAVOUR STREQUAL "MIT")
       list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "mit-krb5-gssapi")
     else()  # Heimdal
-      list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "heimdal-gssapi")
+      if(NOT CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
+        list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "heimdal-gssapi")
+      endif()
     endif()
   else()
     message(WARNING "GSSAPI has been requested, but no supporting libraries found. Skipping.")
--- a/configure.ac
+++ b/configure.ac
@@ -2071,7 +2071,13 @@ if test x"$want_gss" = xyes; then
   if test -n "$gnu_gss"; then
     LIBCURL_PC_REQUIRES_PRIVATE="$LIBCURL_PC_REQUIRES_PRIVATE gss"
   elif test "x$not_mit" = "x1"; then
-    LIBCURL_PC_REQUIRES_PRIVATE="$LIBCURL_PC_REQUIRES_PRIVATE heimdal-gssapi"
+    case $host_os in
+      freebsd*)
+        ;;
+      *)
+        LIBCURL_PC_REQUIRES_PRIVATE="$LIBCURL_PC_REQUIRES_PRIVATE heimdal-gssapi"
+        ;;
+    esac
   else
     LIBCURL_PC_REQUIRES_PRIVATE="$LIBCURL_PC_REQUIRES_PRIVATE mit-krb5-gssapi"
   fi

@diizzyy

diizzyy commented Nov 10, 2024

Copy link
Copy Markdown
Contributor Author

@vszakats

Copy link
Copy Markdown
Member

That would break if you use the port which is a valid configuration, https://cgit.freebsd.org/ports/tree/security/heimdal/pkg-plist#n201 https://cgit.freebsd.org/ports/tree/Mk/Uses/gssapi.mk

There a "base-gssapi" package on FreeBSD which is installed by default, and a port that is heimdal-gssapi, is that correct?

If so, perhaps we should make a new "base-gssapi" GSS flavour, adjust detections to detect and return this flavour, then skip adding it to the pc dependency list for this flavour?

@diizzyy

diizzyy commented Nov 10, 2024

Copy link
Copy Markdown
Contributor Author

No, "base" refers to the bundled version included in the OS which is the one you see get detected in the CI logs.
The ported (packaged) versions needs to be installed as any other package.

@vszakats

Copy link
Copy Markdown
Member

No, "base" refers to the bundled version included in the OS which is the one you see get detected in the CI logs. The ported (packaged) versions needs to be installed as any other package.

That is what I meant, so I don't understand the "no". Is there is isn't two distinct kind of GSS implementations on FreeBSD? One with .pc files, one without?

@diizzyy

diizzyy commented Nov 10, 2024

Copy link
Copy Markdown
Contributor Author

You have 3 variants,
base: (heimdal, without .pc files)
ports: (heimdal and mit shipped with .pc files)
So validating by OS is incorrect and in general seems an odd choice instead of just doing a global check.

@vszakats

vszakats commented Nov 11, 2024 •

Copy link
Copy Markdown
Member

You have 3 variants, base: (heimdal, without .pc files) ports: (heimdal and mit shipped with .pc files) So validating by OS is incorrect and in general seems an odd choice instead of just doing a global check.

We want to depend on the .pc file regardless of how GSS was detected on the build host. On another machine GSS may be available via .pc file, even if it wasn't on the build host.

Except on FreeBSD where there seem to be multiple flavours of heimdal, one with a .pc file, one without, and they cannot be mixed with each other, if I understand correctly.

If that's the case we have not 3 but 4 "flavours".

@diizzyy

diizzyy commented Nov 12, 2024

Copy link
Copy Markdown
Contributor Author

I really don't see where this would be an issue in practice where you'd have a "desynced" build root/host compaed to run host, if you insist make it a toggle instead of adding os/distro specific hacks?

@vszakats

vszakats commented Nov 12, 2024 •

Copy link
Copy Markdown
Member

I really don't see where this would be an issue in practice where you'd have a "desynced" build root/host compaed to run host, if you insist make it a toggle instead of adding os/distro specific hacks?

Thinking in generic terms, are you saying that a .pc reference should only be added to the Requires list if we detected the dependency via pkg-config?

@diizzyy

diizzyy commented Nov 12, 2024

Copy link
Copy Markdown
Contributor Author

Yes, that's what I'm suggesting

@vszakats

vszakats commented Nov 12, 2024 •

Copy link
Copy Markdown
Member

This might be a way to deal with, but it assumes that curl itself and its dependents are
built in the same build environment. This is not true in some envs, notably non-unix ones,
certain cross-builds, possibly more. Question if .pc files are used in these scenarios,
or this would be something undesired in such env.

It also flies in the face of idea that a .pc file should describe the dependencies and it's
up to the user (builder) to ignore what's missing and use whatever parts of the config
that helps completing a build. This might be my idea, but it's kind of hard to figure out
what the original intention is (there is almost no documentation).

Such solution will also result in different .pc files depending on the private details
of how a certain dependency was detected in a build, for builds that are otherwise
identical.

In practice it also means that implementation details of curl's autotools and cmake
dependency detection will affect the generated .pc files. Even such tiny ones as
the detection order when using multiple methods for a given dependency.
(I think this might be okay, pkg-config is done first most if not all of the time.)

CMake doesn't yet have pkg-config-based detection for certain dependencies.
This has been worked on recently and pending completion in #15408. Scheduled
for the next release. (edit: turns out autotools is also missing some, and there
is no pending PR to add them.)

Assuming we want to go with this solution, this is important to merge first, otherwise
these components would always miss their Require entry when using CMake. As
would have many others before implementing native pkg-support for them earlier.

Such change will be a relatively large one because we'd need to keep track of the
detection method for all dependencies in both autotools and cmake, and change
the logic to update the requires list based on that.

A lighter solution is to implement this solely for the problematic ones, which seem
to be (so far) GSS, LDAP, mbedTLS, Rustls and msh3.

Of these, LDAP is also pending a detection overhaul in CMake: #15273, adding
pkg-config support too.

@vszakats

Copy link
Copy Markdown
Member

Patch proposal: #15573

@vszakats vszakats closed this in d511ec8 Nov 14, 2024
pps83 pushed a commit to pps83/curl that referenced this pull request Apr 26, 2025
The idea of linking dependencies found to `libcurl.pc` turns out not
to work in practice in some cases.

Specifically: gss, ldap, mbedtls, libmsh3, rustls

A `.pc` may not work or be missing for a couple of reasons:
- not all build methods generate it: mbedTLS, Rustls
- generated file is broken: msh3
  Ref: nibanks/msh3#225
- installed package flavour isn't shipping with one:
  FreeBSD GSS, OmniOS LDAP, macOS LDAP

The effect of such issues shall be subtle in theory, because
`libcurl.pc` normally lists these dependencies in the `Requires.private`
section meant for static linking. But, e.g. `pkg-config --exists`
requires these to be present, and builds sometimes use this check
regardless of build type. This bug is not present in `pkgconf`; it only
checks for them when `--static` is also passed.

Fix these by adding affected `.pc` references to `libcurl.pc` only when
we detected the dependency via `pkg-config`.

There are a few side-effects of this solution:
- references are never added for dependencies where curl doesn't
  implement `pkg-config` detection. These are:
  - autotools: ldap, mbedtls, msh3
  - cmake: ldap (pending curl#15273)
- generated `libcurl.pc` depends on the build-time environment.
- generated `libcurl.pc` depends on curl build tool (cmake, autotools).
- generated `libcurl.pc` depends on curl build implementation details.

Make an exception for GNU GSS, where I blindly guess that `gss.pc` is
always available, as no issues were reported.

Other, not mentioned, dependencies continue to be added regardless
of the detection method.

Reported-by: Harmen Stoppels, Thomas, Daniel Engberg, Andy Fiddaman
Fixes curl#15469
Fixes curl#15507
Fixes curl#15535
Fixes curl#15163 (comment)
Closes curl#15573
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants