{"id":15015447,"url":"https://github.com/foursixnine/ruperl","last_synced_at":"2025-04-09T19:24:34.255Z","repository":{"id":237337329,"uuid":"794324987","full_name":"foursixnine/ruperl","owner":"foursixnine","description":"Run perl from within rust","archived":false,"fork":false,"pushed_at":"2024-08-15T13:32:42.000Z","size":24,"stargazers_count":10,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-23T21:22:54.366Z","etag":null,"topics":["embedded","ffi","perl","rust"],"latest_commit_sha":null,"homepage":"http://foursixnine.io","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/foursixnine.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-30T22:42:57.000Z","updated_at":"2025-03-14T08:17:17.000Z","dependencies_parsed_at":"2024-04-30T23:45:19.382Z","dependency_job_id":"9c838cd5-c5f9-4c60-a705-7e984e878232","html_url":"https://github.com/foursixnine/ruperl","commit_stats":null,"previous_names":["foursixnine/ruperl"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foursixnine%2Fruperl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foursixnine%2Fruperl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foursixnine%2Fruperl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foursixnine%2Fruperl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/foursixnine","download_url":"https://codeload.github.com/foursixnine/ruperl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248096396,"owners_count":21047045,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["embedded","ffi","perl","rust"],"created_at":"2024-09-24T19:47:28.869Z","updated_at":"2025-04-09T19:24:34.220Z","avatar_url":"https://github.com/foursixnine.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RuPerl - Rust with embedded Perl\n\nThis is something that shouldn't exist; but it does. It's a Perl interpreter embedded in Rust.\n\nOnce cloned, you can run the following commands to see it in action:\n\n- `cargo run --verbose -- hello.pm showtime`\n- `cargo run --verbose -- hello.pm get_quick_headers`\n\n## How it works\n\nThere is a lot of autogenerated code, mainly for two things:\n\n- `bindings.rs` and `wrapper.h`; I made a lot of assumptions and `perlxsi.c` may or may not be necessary in the future (see `main::xs_init_rust`), depends on how bad or terrible my `C` knowledge is by the time you're reading this.\n- `xs_init_rust` function is the one that does the magic, as far as my understanding goes, by hooking up `boot_DynaLoader` to [DynaLoader](https://metacpan.org/pod/DynaLoader) in Perl via ffi.\n\nWith those two bits in place, and thanks to the magic of the `bindgen` crate, and after some initialization, I decided to use `Perl_call_argv`, do note that `Perl_` in this case comes from bindgen, I might change later the convention to `ruperl` or something to avoid confusion between that a and `perl_parse` or `perl_alloc` which (if I understand correctly) are exposed directly by the ffi interface.\n\nWhat I ended up doing, is passing the same list of arguments (for now, or at least for this PoC), directly to `Perl_call_argv`, which will in turn, take the third argument and pass it verbatim as the [call_argv](https://perldoc.perl.org/perlcall#Using-call_argv) \n\n```\n        Perl_call_argv(myperl, perl_sub, flags_ptr, perl_parse_args.as_mut_ptr());\n```\n\nRight now hello.pm defines two sub routines, one to open a file, write something and print the time to stdout, and a second one that will query my blog, and show the headers. This is only example code, but enough\nto demostrate that the DynaLoader works, and that the embedding also works :)\n\n![itsalive](https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExd3pkbzJweGl3aG8waG0xeHJpZDU5bXQ4bnRqdjlmdGNjdXA1eXRteCZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/tze1mGedykiuk/giphy.gif)\n\nI got most of this working by following the [perlembed](https://perldoc.perl.org/perlembed) guide.\n\n## Why?\n\n\u003e Why not?.\n\nI want to see if I can embed also python in the same binary, so I can call native perl, from native python and see how I can fiddle all that into [os-autoinst](https://github.com/os-autoinst/os-autoinst)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffoursixnine%2Fruperl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffoursixnine%2Fruperl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffoursixnine%2Fruperl/lists"}