Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Shared library extensions #571

Copy link
Copy link
Open
Open
Copy link
@coolreader18

Description

@coolreader18
Issue body actions

I've been playing with the idea of being able to build a module/extension in Rust that plugs in to RustPython, and I think I've come up with a pretty decent way of doing it. I've drawn some inspiration/learned about Rust dynamic loading from this ffi guide.

  • Add libloading as a dependency.
  • Add a field to VirtualMachine that's a Vec of libloading::Librarys.
  • In the module resolution process, check if there's a *.so or *.dll on the PYTHONPATH, maybe have a specific prefix or suffix to designate that it's specifically a RustPython extension.
  • Load that library and store it in the Vec<Library>, and then load a fn from there with a name like rustpython_init_module and a signature along the lines of
    type ExtensionInitFn = unsafe extern fn(vm: &mut VirtualMachine);
  • Call that ExtensionInitFn.

I think it's pretty straightforward, but does anyone have any ideas for the parts that could be filled in, e.g. resolution along the PYTHONPATH?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-designAbout RustPython's own implementationAbout RustPython's own implementationC-enhancementNew feature or requestNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.