mini_portile icon indicating copy to clipboard operation
mini_portile copied to clipboard

explore alternatives to setting `LIBRARY_PATH`

Open flavorjones opened this issue 2 years ago • 11 comments

Description

Currently, mini_portile sets the environment variable LIBRARY_PATH in #activate. This behavior has been present since the first commit by Luis in 2011 (c06b4ab).

This is OK the vast majority of the time, however an interesting and unfortunate edge case has shown up when the target system is using Fedora's alternative pkgconf (more reading).

The problem is this: on Fedora, pkg-config --libs will not report any directories that are present in LIBRARY_PATH, which means that any extconf.rb that relies on a vendored library's .pc file to set paths correctly will fail to find the vendored library.

See https://github.com/sparklemotion/sqlite3-ruby/issues/354 for an example of where this has generated a bug report, and https://gitlab.kitware.com/cmake/cmake/-/issues/22148#note_980802 for a related discussion in a non-Ruby context.

Possible solutions

  1. mini_portile could automatically append_ldflags(lib_path)
  2. mini_portile could stop setting LIBRARY_PATH
  3. mini_portile could do both 1 and 2

I think any of these might be a reasonable solution, but only thorough testing against downstream projects is going to reveal whether we'll be introducing a subtle breaking change.

Next steps

Reproduce this issue in CI:

flavorjones avatar Oct 10 '22 21:10 flavorjones

@flavorjones, thank you for looking into this!

@eregon, does this impact Nokogiri on Red Hat too?

kwilczynski avatar Oct 12 '22 03:10 kwilczynski

Nokogiri isn't impacted because its extconf.rb does not read the .pc file for any of the vendored libraries.

Ruby-magic likely is affected (and I would say the same for rcee/packaged_tarball) but I haven't yet attempted to reproduce it in CI to confirm.

flavorjones avatar Oct 12 '22 11:10 flavorjones

(And I've updated the description to be clearer that this only affect projects that are relying on a vendored .pc file to set paths correctly.)

flavorjones avatar Oct 12 '22 11:10 flavorjones

See https://github.com/flavorjones/mini_portile/pull/131 where I'm working on this.

flavorjones avatar Sep 09 '23 16:09 flavorjones

Note for y'all who are following this issue: the approach I'm taking in #131 is for a new method, MiniPortile#mkmf_config which can a pkg-config file and sets $LDFLAGS and $CFLAGS.

flavorjones avatar Sep 09 '23 18:09 flavorjones

Going to create a release candidate with #131 and #133 in it.

flavorjones avatar Sep 13 '23 14:09 flavorjones

Reopening until I've made a final release that addresses this.

flavorjones avatar Sep 13 '23 21:09 flavorjones

See

  • https://github.com/sparklemotion/sqlite3-ruby/pull/405
  • https://github.com/sparklemotion/nokogiri/pull/2977

which are both green, but currently there is a high risk of pulling in system shared libraries inadvertently. I've got a few options, but need to find the time to finish this work.

flavorjones avatar Oct 02 '23 13:10 flavorjones

Note: the re2 gem worked around shared linking in https://github.com/mudge/re2/pull/93, there are probably lessons in there we can upstream.

flavorjones avatar Oct 22 '23 16:10 flavorjones

Picking this back up again this week after a related problem was raised in https://github.com/sparklemotion/nokogiri/issues/3133

flavorjones avatar Feb 22 '24 03:02 flavorjones

Note that the mkmf_config(static:) call that's in mini_portile 2.8.5 seems to fix the issue with accidentally dynamically linking. Need to fully test it across a few gems but I think it's mostly there.

flavorjones avatar Feb 22 '24 03:02 flavorjones