Skip to content
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

FFI: Loading libraries as dependencies/URLs #12943

Open
kriszyp opened this issue Nov 30, 2021 · 2 comments
Open

FFI: Loading libraries as dependencies/URLs #12943

kriszyp opened this issue Nov 30, 2021 · 2 comments
Labels
FFI Related to Foreign Function Interface APIs suggestion suggestions for new features (yet to be agreed)

Comments

@kriszyp
Copy link

kriszyp commented Nov 30, 2021

Currently Deno.dlopen takes a file path to load a binary library for use with FFI. However, in developing third party packages that use FFI, it seems like we would want the binary library to be treated like another dependency, like modules, accessible as a URL as part of the distribution (either absolutely or relatively). If I understand correctly, Deno works hard to abstract away the concept of "files" when dealing with modules, preferring to access them through URLs (and caching them in its own directory). It seems somewhat antithetical that FFI should be based on direct access to files. In particular, this seems like it creates a problematic distribution process; in order to load the binary library as part third-party package, we would need to:

  • Check if the binary library file exists
  • If it does not exists, fetch it from the source URL
  • Save it to the file system (and figure out a good place to save it)

All of this is basically reinventing the wheel of dependency fetching/caching that Deno usually provides, and requires unnecessarily elevated permissions to accomplish.

Perhaps I am missing something about how this is supposed to work? Or should there be a way to access and load FFI binary libraries in a similar referencing manner as other dependencies/modules?

I know this has been discussed a little bit previously, so there may already be ideas for how this should work, but if you are looking for suggestions, maybe something like this would be a reasonable way to load an FFI library:

// URL/path is pretty much always going to be dynamic
const urlForBinary = 'https://cdn.com/lib.' + (os == 'windows' ? 'dll' : 'so');
const binaryFile = await import(urlForBinary, { assert: { type: 'binary' } });
const lib = Deno.dlopen(binaryFile, { ... all my symbols ... });

(binaryFile could be a File or something completely opaque that Deno could use to pass the cached file path to the OS to load the library).

@lucacasonato
Copy link
Member

Also see #3448

@bartlomieju bartlomieju added FFI Related to Foreign Function Interface APIs suggestion suggestions for new features (yet to be agreed) labels Dec 1, 2021
@kriszyp
Copy link
Author

kriszyp commented Dec 2, 2021

I guess this also very closely related to #12770 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FFI Related to Foreign Function Interface APIs suggestion suggestions for new features (yet to be agreed)
Projects
None yet
Development

No branches or pull requests

3 participants