Skip to content

prefer loading from extension_dir if gem spec is an active stub#31

Open
anthraxx wants to merge 1 commit intoffi:masterfrom
anthraxx:extention-dir-support
Open

prefer loading from extension_dir if gem spec is an active stub#31
anthraxx wants to merge 1 commit intoffi:masterfrom
anthraxx:extention-dir-support

Conversation

@anthraxx
Copy link

extension_dir is the modern place to put the native libraries for a gem that is distributed. Try finding and loading the requested library first from this extension dir, in case the library path is covered by an active sub. This makes sure the extension we are trying to load is not just matched based on the gem-name, as there may be multiple versions, but its actually loading a gem spec from a potentially active stub that matches the expected gem version as provided by the gem's dependency constraints.

In case the loader can't find a matching platform library inside an active extension dir, fall back to regular lib path lookup which is glob scanning the ascending path. This makes sure the ffi-compiler loader can also be used for legacy lib paths as well as simple local checkouts and folders.

This is the safest approach that tries to prefer loading from modern extension_dir while still making sure any other use case remains functional.

extension_dir is the modern place to put the native libraries for a gem
that is distributed. Try finding and loading the requested library first
from this extension dir, in case the library path is covered by an
active sub. This makes sure the extension we are trying to load is not
just matched based on the gem-name, as there may be multiple versions,
but its actually loading a gem spec from a potentially active stub that
matches the expected gem version as provided by the gem's dependency
constraints.

In case the loader can't find a matching platform library inside an
active extension dir, fall back to regular lib path lookup which
is glob scanning the ascending path. This makes sure the ffi-compiler
loader can also be used for legacy lib paths as well as simple local
checkouts and folders.

This is the safest approach that tries to prefer loading from modern
extension_dir while still making sure any other use case remains
functional.

Signed-off-by: Levente Polyak <levente@leventepolyak.net>
@anthraxx
Copy link
Author

This supersedes #30 with a much simpler approach finding the actual library in question, without making any assumptions about how the library-name relates to the gem-name.
Still fall back to the regular glob based path lookup if this modern fast-path fails.

@davispuh
Copy link
Collaborator

Looks good to me! I don't see any reason not to merge this if it works correctly/as expected and no one has any objections.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants