Repository navigation
Description
Describe the bug, including details regarding any error messages, version, and platform.
I have been having to manually edit arrow.pc from a vcpkg installation of a static build of arrow (using triplet x64-windows-static-md) for a few reasons. #14869 was a start, but now for the tricky (to me) one - missing dependencies. It doesn't seem to be a vcpkg issue, as non-vcpkg builds also generate "unconsumable" pkg-config files, so I'm posting here. Or maybe it goes all the way up to cmake, I don't know (I'm a cmake avoider...).
The following is using arrow master as of a0d1630.
For example, using VS2022 (17.4.3) (and cmake 3.24.202208181-MSVC_2 from there) configured as:
cmake -G Ninja -DVCPKG_TARGET_TRIPLET=x64-windows-static-md -DARROW_WITH_BROTLI=ON -DARROW_WITH_BZ2=ON
-DARROW_WITH_LZ4=ON -DARROW_WITH_SNAPPY=ON -DARROW_WITH_ZLIB=ON -DARROW_WITH_ZSTD=ON
-DARROW_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=/path/to/somewhere -DARROW_DEPENDENCY_SOURCE=VCPKG
-DARROW_BUILD_STATIC=ON -DARROW_BUILD_SHARED=OFF -DARROW_BUILD_TESTS=OFF
-DARROW_DEPENDENCY_USE_SHARED=OFF -DARROW_WITH_BACKTRACE=OFF
-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDebugDLL -DCMAKE_BUILD_TYPE=Debug ../..
when built and installed generates arrow.pc:
...
Requires:
Requires.private:
Libs: -L${libdir} -larrow /path/to/arrow.git/cpp/vcpkg_installed/x64-windows-static-md/lib/snappy.lib optimized;/path/to/arrow.git/cpp/vcpkg_installed/x64-windows-static-md/lib/bz2.lib;debug;/path/to/arrow.git/cpp/vcpkg_installed/x64-windows-static-md/debug/lib/bz2d.lib
Libs.private:
Cflags: -I${includedir} -DARROW_STATIC
Cflags.private:
This is essentially the same as an install via vcpkg. There are a few problems here:
-
Most of the compression deps are missing (libbrotlidec libbrotlienc zlib liblz4 libzstd).The cmake invocation generates the following:
-- pkg-config package for libbrotlidec for static link isn't found -- pkg-config package for libbrotlienc for static link isn't found -- pkg-config package for zlib for static link isn't found ...so not surprising, I suppose! pc files are there in the
vcpkg_installed/x64-windows-static-md/debug/lib/pkgconfigdir, however (and the libs themselves a level up). -
Libshasbz2andsnappywithout-land with a file extension and path prefix. I don't think this is ideal, as without the-lthe file may be treated as a plain object file rather than import library causing issues with certain toolchains. Ultimately this could be worked around in meson, maybe, (or libpkgconf I think it uses) but... -
bzip2should ideally be aRequirestoo - since there are separate release and debug pkgconfig dirs they will cope with the file naming difference. -
And
snappytoo, but its .pc file is also broken (missing completely here;Libs: -L${libdir} -l, i.e. not-lsnappy, with a vcpkg install of arrow).
I haven't investigated that at all yet, so keep inLibs, but without a path.
I.e. a usable arrow.pc would look something like:
...
Requires: bzip2 libzstd liblz4 zlib libbrotlidec libbrotlienc libbrotlicommon
Libs: -L${libdir} -larrow -lsnappy
Cflags: -I"${includedir}" -DARROW_STATIC
Now I'm sure there are a gazillion of other cases to cope with where doing this would be wrong, but at least in the "get everything via vcpkg" case this arrow.pc works for me (and similarly editied arrow.pc from a vcpkg install of arrow).
As an aside, the same set up of options (except no CMAKE_MSVC_RUNTIME_LIBRARY and x64-linux triplet) on Fedora 37 (cmake 3.25.1) generates:
...
Requires: snappy libbrotlidec libbrotlienc zlib liblz4 libzstd
Requires.private:
Libs: -L${libdir} -larrow optimized;/path/to/arrow.git/cpp/vcpkg_installed/x64-linux/lib/libbz2.a;debug;/path/to/arrow.git/cpp/vcpkg_installed/x64-linux/debug/lib/libbz2d.a -larrow_bundled_dependencies
Libs.private:
Cflags: -I${includedir} -DARROW_STATIC
Cflags.private:
This is more reasonable, though I personally think bzip2 is handled wrong (for the same reasons as above), even if it "works". The debug/optimized stuff is still problematic but vcpkg are adding support for that there (microsoft/vcpkg#23898), so will start to work at some point - but obviously potentially not if consuming the pc file via another route.
I have spent some time hacking ThirdpartyToolchain.cmake to see if I could make the pc files more sane, but unsuccessfully. The best I could do was getting bzip2 "better" with:
if(ARROW_WITH_BZ2)
resolve_dependency(BZip2
PC_PACKAGE_NAMES
bzip2)
# resolve_dependency(BZip2)
# if(${BZip2_SOURCE} STREQUAL "SYSTEM")
# string(APPEND ARROW_PC_LIBS_PRIVATE " ${BZIP2_LIBRARIES}")
# endif()
# if(NOT TARGET BZip2::BZip2)
# add_library(BZip2::BZip2 UNKNOWN IMPORTED)
# set_target_properties(BZip2::BZip2
# PROPERTIES IMPORTED_LOCATION "${BZIP2_LIBRARIES}"
# INTERFACE_INCLUDE_DIRECTORIES "${BZIP2_INCLUDE_DIR}")
# endif()
endif()
but what that breaks I've no idea for other cases. As I say, not a cmake person and would like to keep it that way 😀 Happy to try any suggestions, though.
Thanks!
Component(s)
C++
Activity
kou commentedon Dec 31, 2022
Could you show the full output of
cmake?Could you show the output of
pkg-config --list-all --debug?kou commentedon Dec 31, 2022
Could you try the following for bzip2?
lukester1975 commentedon Jan 2, 2023
cmake-cfg.txt
I don't have a
PKG_CONFIG_PATHset, so essentially nothing:(As an aside, I wondered if the Fedora build generates a sane looking pc file because it's finding the compression deps using system-wide pkg-config. However, I tried unsetting
PKG_CONFIG_PATHand the generated arrow.pc file still looks good...)Regarding the patch for bzip2, that doesn't work quite right.
BZIP2_LIBRARY_RELEASE,BZIP2_LIBRARY_DEBUGandBZIP2_LIBRARYare all set, so it's just a function of ordering as to what gets generated (so I ended up with bz2 rather than bz2d for a debug build).FWIW, this largely fixes a cmake build (again I'm sure it's bad for other reasons, so just for info):
Generates a resaonable
arrow.pc:(snappy weirdness would presumably go away if a snappy.pc actually existed)
I tried adding this as a patch to vcpkg's arrow portfile but no joy (still missing compression deps). I notice it uses
-DARROW_DEPENDENCY_SOURCE=SYSTEM -DARROW_PACKAGE_KIND=vcpkgthere rather than-DARROW_DEPENDENCY_SOURCE=vcpkgwhich I haven't investigated but presumably explains why this patch doesn't work there, somehow...Thanks
lukester1975 commentedon Jan 2, 2023
Fixing snappy at source is a no-go: google/snappy#86
Hopefully vcpkg will fix theirs: microsoft/vcpkg#28675
kou commentedon Jan 2, 2023
Could you try the following patch with
PKG_CONFIG_PATH=D:/dev/checkouts/external/arrow.git/cpp/vcpkg_installed/x64-windows-static-md/lib/pkgconfig?BTW, how did you install
pkg-config? vcpkg? Chocolatey? If you use Chocolatey not vcpkg, could you trypkgconfvcpkg port instead?lukester1975 commentedon Jan 4, 2023
PKG_CONFIG_PATH=/path/to/arrow/cpp/vcpkg_installed/<triplet>/[debug]/lib/pkgconfigworks in thatRequires: libbrotlidec libbrotlienc zlib liblz4 libzstdgets generated. I assume the intention is not to have to do that, though? Pretty unpleasant (especially given the debug/release specific location)!PKG_CONFIG_PATH="" cmake ...isn't sufficient to ignore the system paths. So it was generating a sensible pc file by accident when arrow's deps are available system wide.>- I assume it needs to bestring(APPEND ARROW_PC_LIBS_PRIVATE " debug[$<$<CONFIG:DEBUG>:${BZIP2_LIBRARY_DEBUG}>]")Libs: -L${libdir} -larrow D:/dev/checkouts/external/arrow.git/cpp/vcpkg_installed/x64-windows-static-md/lib/snappy.lib release[] debug[D:/dev/checkouts/external/arrow.git/cpp/vcpkg_installed/x64-windows-static-md/debug/lib/bz2d.lib] other[]-DARROW_DEPENDENCY_SOURCE=SYSTEM -DARROW_PACKAGE_KIND=vcpkg...Thanks
kou commentedon Jan 4, 2023
It's expected. I thought that
Requires: libbrotlidec libbrotlienc zlib liblz4 libzstdwill be generated withPKG_CONFIG_PATH=....Ah, wait. could you show
Get-ChildItem -Recurse D:/dev/checkouts/external/arrow.git/cpp/vcpkg_installed/x64-windows-static-md/?You can disable system
pkg-configsearch path byPKG_CONFIG_LIBDIR= pkg-config --list-all.Sorry.
XXX[...]is just for debug on my environment...Could you try the following?
It will generate
Libs: -L${libdir} -larrow D:/dev/checkouts/external/arrow.git/cpp/vcpkg_installed/x64-windows-static-md/lib/snappy.lib D:/dev/checkouts/external/arrow.git/cpp/vcpkg_installed/x64-windows-static-md/debug/lib/bz2d.lib. Does this work? Do we need to change*.libto something?lukester1975 commentedon Jan 16, 2023
Apologies for the delayed response, fighting a bout of the you-know-what.
Hmm, OK. Shame! Should the
pkg-config package for ... for static link isn't founds become hard errors? It doesn't seem very nice for config / build / install to suceed withoutPKG_CONFIG_PATHbut for the generated pc files to be missing dependencies. I suppose the instructions could do with an update to explain thePKG_CONFIG_PATHrequirement.Sure, it's a bit of a beast of a listing given the includes, so zipped. I wasn't sure from what state you wanted the listing, so it is after a vcpkg install & cmake configure (without the
PKG_CONFIG_PATH).Patch as below (needed a tiny tweak) did indeed generate that
Libsline. I think it's OK, though given the bzip2 pc files from vcpkg are OK it would seem cleaner to be to justRequiresbzip2, but I guess this is coping with non-vcpkg bzip2 too and you'd rather not special case, or something?(I honestly can't remember when or how I tripped over lib files being linked as plain object files causing problems, so happy to ignore that until it happens again ... sorry for the noise.)
Thanks!
kou commentedon Jan 17, 2023
Thanks for confirming the patch!
#33712 fixes this.
apacheGH-15139: [C++] Improve bzip2 static library path detection for…
lukester1975 commentedon Jan 18, 2023
OK. FWIW, I added this patch to vcpkg (along with microsoft/vcpkg#23898) and tried an install of arrow. It generates:
Libs: "-L${libdir}" -larrow "${prefix}/lib/snappy.lib" "$<$<CONFIG:RELEASE>:${prefix}/lib/bz2.lib>" "$<$<CONFIG:DEBUG>:${prefix}/lib/bz2d.lib>" "$<$<NOT:$<OR:$<CONFIG:RELEASE>,$<CONFIG:DEBUG>>>:optimized" "${prefix}/lib/bz2.lib" "${prefix}/lib/bz2d.lib>"which doesn't look great.
As a quick hack I added
z_vcpkg_setup_pkgconfig_path(BASE_DIRS "${CURRENT_INSTALLED_DIR}/debug")to the portfile before thevcpkg_cmake_configureand end up with:which looks spot on to me.
I'm not sure where to go with this now - a new issue in the vcpkg repo? Whilst
vcpkg_configure_cmake.cmakehas no calls toz_vcpkg_setup_pkgconfig_path(whereasvcpkg_configure_make.cmake,vcpkg_configure_meson.cmakeetc. do) I assume that's not an oversight...GH-15139: [C++] Improve bzip2 static library path detection for arrow…
kou commentedon Jan 18, 2023
Oh, sorry. I merged the pull request before I see your last comment.
It seems that CMake's generate expression isn't evaluated.
Implementation: https://github.com/apache/arrow/blob/master/cpp/cmake_modules/BuildUtils.cmake#L947-L951
What is the difference between #15139 (comment) and #15139 (comment) ?
lukester1975 commentedon Jan 20, 2023
Sorry, not sure I really understand the question but the first comment was regarding configuring and building arrow from the arrow source (which looks ok now), second was from
vcpkg installwith a simplevcpkg.jsonwith just arrow:Setting
PKG_CONFIG_PATHbeforevcpkg installdidn't help so I looked in to the vcpkg source to see what might work andz_vcpkg_setup_pkgconfig_pathseemed to fit the bill, though I'm sure isn't correct (aside from anything else, my hack doesn't distinguish debug/release pkgconfig dirs)...Thanks
kou commentedon Jan 21, 2023
Hmm. It seems that it's related to vcpkg. Could you open an issue on vcpkg?
lukester1975 commentedon Jan 21, 2023
Sure, that's what I was asking. I'll try!