[EPIC] Provide interface to test distributions in perl #12
Labels
accepted
Approved by maintainer
epic
Large task probably devided into subtasks
help wanted
Extra attention is needed
language-interface
this is about the perl/rust language interface
openQA Version
n/A
Impacted library
isototest
Proposal
To be able to talk to openQA, there needs to exist sort of a Rust stub which can execute the existing Perl code for as long as this Perl code still exists. There are two possiblities to do this:
libperl-rs
crate to execute the existing Perl code while pulling in the rust libraries.swig
andbindgen-rs
to create perl to rust bindings as a shared dynamic library. In practice this would possibly mean to create perl-C bindings and Rust-C bindings and putting them togetherInformation
If you want to go with the 2nd approach (which would probably be smarter as it would allow a granular rewrite of openQA's functionality into Perl while being able to keep the Perl code):
You can specify that a library should be compiled as a C-compatible dynamic library like this:
Edit your
Cargo.toml
file to specify that you're building a library. This involves setting the crate-type field tocdylib
, which tells Cargo to compile your library as a C-compatible dynamic library. Additionally, you'll need to define the functions you want to expose to users of your library. These functions should be marked with#[no_mangle]
to prevent them from being renamed during compilation, andpub extern "C"
to indicate that they have C linkage.Functions you want to expose would look like this:
Then, compile your library by running
cargo build --release
. This command compiles your library in release mode, producing a shared library file named<library_name>.so
on Linux,<library_name>.dll
on Windows, and<library_name>.dylib
on macOS.Using:
After compiling your library, you can use it in other projects by adding it as a dependency in those projects'
Cargo.toml
files. You can also manually load the shared library at runtime using thelibloading
crate.Considerations for this approach:
Ressources
libperl-rs
crate: https://crates.io/crates/libperl-rslibperl-rs
blogpost: https://hkoba.hatenablog.com/entry/2020/03/30/124746swig
Rust support issue: add rust support swig/swig#2734swig
Rust support discussion: Is there any plan to support Rust? swig/swig#1468rust-bindgen
: https://github.com/rust-lang/rust-bindgenDynaLoader
Dynamic .so loader: https://perldoc.perl.org/DynaLoaderThe text was updated successfully, but these errors were encountered: