-
-
Notifications
You must be signed in to change notification settings - Fork 52
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
mkmf_config support for pkg-config files with multiple library directories #138
Comments
Looking at mini_portile/lib/mini_portile2/mini_portile.rb Lines 327 to 334 in 52fb0bc
.pc files so there isn't a single file to reference and pre-populate $MINI_PORTILE_STATIC_LIBS with before loading RE2's re2.pc (viz. if I were able to use mkmf_config(static:) with Abseil first, perhaps using it with RE2 would be able to generate the correct static flags already).
That said, perhaps changing |
Thank you for opening this! Hoping to looking into it in the next week. |
FWIW we explicitly restrict our search for static replacements of libraries to the two |
In case it is of any use, I had some time today to try and spike a mix of how your ENV["PKG_CONFIG_ALLOW_SYSTEM_CFLAGS"] = "t"
pkg_config_paths = [
"#{abseil_recipe.path}/lib/pkgconfig",
"#{re2_recipe.path}/lib/pkgconfig"
]
# Set up pkg-config to prefer our vendored RE2 and Abseil
pkg_config_paths.prepend(ENV['PKG_CONFIG_PATH']) if ENV['PKG_CONFIG_PATH']
ENV['PKG_CONFIG_PATH'] = pkg_config_paths.join(File::PATH_SEPARATOR)
pc_file = File.join(re2_recipe.path, 'lib', 'pkgconfig', 're2.pc')
# Collect static -L directories to resolve static libraries
library_dirs = xpopen(['pkg-config', '--libs-only-L', '--static', pc_file], err: %i[child out], &:read).strip
static_library_dirs = library_dirs.shellsplit.map { |flag| flag.sub(/\A-L/, "") }
puts "Static library dirs are #{static_library_dirs.inspect}"
# Convert -l flags to static links within the collected static directories where possible
libflags = xpopen(['pkg-config', '--libs-only-l', '--static', pc_file], err: %i[child out], &:read)
.shellsplit
.map do |flag|
next flag unless flag.start_with?("-l")
static_lib = "lib#{flag[2..]}.#{$LIBEXT}"
static_lib_dir = static_library_dirs.find { |dir| File.exist?(File.join(dir, static_lib)) }
next flag unless static_lib_dir
File.join(static_lib_dir, static_lib)
end
# Prepend all flags (including the static replacements) to $libs
$libs = [libflags, $libs].join(" ").strip
# Prepend the original -L flags to LDFLAGS otherwise the final linking step fails with "library 're2' not found"
$LDFLAGS = [library_dirs, $LDFLAGS].join(" ").strip
# Prepend INCFLAGS
incflags = xpopen(['pkg-config', '--cflags-only-I', pc_file], err: %i[child out], &:read).strip
$INCFLAGS = [incflags, $INCFLAGS].join(" ").strip
# Append CFLAGS and CXXFLAGS
cflags = xpopen(['pkg-config', '--cflags-only-other', pc_file], err: %i[child out], &:read).strip
$CFLAGS = [$CFLAGS, cflags].join(" ").strip
$CXXFLAGS = [$CXXFLAGS, cflags].join(" ").strip Inspecting the resulting
I'm not sure what the significance of having to set Update: it might be worth adding that we’re currently relying on Here's another version of the last few lines that only sets # Set $libs with all the flags including our static replacements
$libs = [libflags, $libs].join(" ").strip
# Tell Ruby where to find the libraries
$LIBPATH = static_library_dirs | $LIBPATH
# Add INCFLAGS
incflags = xpopen(['pkg-config', '--cflags-only-I', pc_file], err: %i[child out], &:read).strip
$INCFLAGS = [incflags, $INCFLAGS].join(" ").strip |
I’ve now distilled this into mudge/re2@ac14e8f |
It’s worth noting that preferring |
@mudge thanks for all your work here. i've been heads-down during my OSS time trying to work on a few urgent things and haven't been able to get back to this yet. this topic is at the top of my backlog, though, and I hope to get to it in the next week or two. |
You’re welcome, there’s no rush from my side. I had some time this weekend to spend on it hence the over-communication both here and on my (now draft) PR in re2. The main thing I’d like to understand more is the significance between It has been tricky because so many |
Quick update: I think I got to the bottom of why I saw a regression in re2 and it was to do with using |
Having churned on this a bit, I ended up releasing re2 2.10.0 with the refactored pkg-config logic. In summary:
This way, I hope that we include the bare minimum necessary and use the “highest” possible level of abstraction (e.g. the more intention-revealing I’m not sure our strategy of searching for static libraries in every |
If nothing else, it’d be quite nice to delete my copy of |
As mentioned in mudge/re2#138 (comment), the
re2.pc
pkg-config file generated by RE2 contains libraries from two directories: RE2 itself and its sole dependency, Abseil (note I’ve populatedPKG_CONFIG_PATH
prior to this so that it prefers the Abseil inports
over my system install):At the moment, this doesn’t feel compatible with MiniPortile2’s new
mkmf_config(static:)
functionality as it assumes the.pc
file only specifies libraries within its own directory (seemini_portile/lib/mini_portile2/mini_portile.rb
Line 319 in 52fb0bc
pc
file for a library (Abseil ships with over 180 individual ones for each library).What I actually want here is to turn all of the
-l
flags into static, absolute paths by looking for the matching file in each of the library directories specified by the two-L
flags, e.g.Becomes:
Would it be possible to extend the API to support this use case (potentially also including setting
PKG_CONFIG_PATH
)?The text was updated successfully, but these errors were encountered: