-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
[vcpkg] Avoid duplication of Libs in vcpkg_fixup_pkgconfig #17748
Conversation
cc @Neumann-A Could you please help review this PR? Thanks. |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
Edit: I wrote this looking at the output in your top comment, not actually looking at the implementation. Looking at the implementation, this may be fine. I think you need to keep the last instance of a link -- consider the following: A -> B, C the duplicated list would look like A B D C D With keeping the first instance, you have A B D C and any symbols from D needed by C will not be found (because D isn't linked after it). If instead the last instance is kept, A B C D We get the desired behavior |
# If the software already merges Libs.private into Libs (e.g. curl), avoid duplication. | ||
set(_libs_private "${CMAKE_MATCH_1}") | ||
string(REGEX REPLACE "\nLibs: *([^\n]*[^ \n])" "\nLibs: @VCPKG_FIXUP_LIBS@" _contents "${_contents}") | ||
string(REPLACE " ${_libs_private} " " " _libs " ${CMAKE_MATCH_1} ") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assumes a space will be present after the _libs_private
sequence in Libs:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that there is an extra space before and after ${CMAKE_MATCH_1}
here, so the assumption will hold.
Sorry for the late comment here. I think this work is great, and I very much appreciate any improvements to the pkgconfig situation in vcpkg. However, I wonder if it's worth trying to patch the curl .pc file for vcpkg and/or get this patched upstream, as I cannot think of a reason why any flag would ever need to be specified in both Libs and Libs.private (although see curl/curl#5373 which seems to be the origin of the duplication). An educated guess tells me that only This could also be related: https://curl.se/docs/knownbugs.html#curl_config_libs_contains_priv |
@mcmtroffaes https://curl.se/docs/knownbugs.html#curl_config_libs_contains_priv is unrelated because it is about LDFLAGS feed into curl configuration being carried through into the pc file AFAIU. curl is doing its attributes right already, and that's why I don't want to patch curl. I don't want to claim this is the only possible approach. There are alternatives:
|
Many thanks for the explanation and educating me, and I apologize if I'm a bit slow on the uptake. I can see now why having identical Libs and Libs.private entries for statically built libraries makes sense, say if you're building an application which intends to link dynamically against its dependencies (thus, might call pkg-config without --static), but must still link against some static dependency, which will use its Libs and not its Libs.private. I don't think most projects even try to support this scenario: the assumption appears to be that static libraries are only used when the entire project is built statically. Now, what vcpkg is trying to do is to get rid of Libs.private entirely, and just have the correct link flags specified in Libs for the triplet being used. Since there are distinct triplets and thus distinct .pc files for static and dynamic builds anyway, this works just fine. I hope I'm summarizing this correctly, and would be happy to stand corrected. |
My explanations here are also written down for review. I have difficulties to find good examples of how to use pkg-config correctly in some cases. At least when mixing static and dynamic linkage, I would love to find a good reference. |
the idea is to never have to pass |
Thanks for clarification. This seem to be a conscious decision for vcpkg, not just an idea. I would like to see this written down in a reference document, at least in the At the moment, |
It was implemented with Be aware most of |
Yeah, I digged the history a few times. It is a little bit hard to contribute because of competing PRs and long CI runs. But it is getting off-topic. |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
|
As far as curl is concerned, the duplication is going to be resolved by #18971. |
The curl particularities are solved now in port curl. I don't think this PR is still needed. Most ports seem to need pc file patching anyway. Better contribute back upstream than micro-optimize here. |
What does your PR fix?
This PR modifies
vcpkg_fixup_pkgconfig
, static linkage, to not duplicate Libs.private in Libs if its already present there.E.g. for curl, x64-linux, instead of
Libs: -L"${libdir}" -lcurl-d -lgcc -lgcc_s -lc -lgcc -lgcc_s -ldl -lpthread -lssl -lcrypto -lz -lgcc -lgcc_s -lc -lgcc -lgcc_s -ldl -lpthread -lssl -lcrypto -lz
curl.pc is now:
Libs: -L"${libdir}" -lcurl-d -lgcc -lgcc_s -lc -lgcc -lgcc_s -ldl -lpthread -lssl -lcrypto -lz
This helps when reviewing build logs (as I'm doing for gdal at the moment).
Which triplets are supported/not supported? Have you updated the CI baseline?
all, no
Does your PR follow the maintainer guide?
yes
If you have added/updated a port: Have you run
./vcpkg x-add-version --all
and committed the result?-/-