mirror of
https://git.proxmox.com/git/proxmox-perl-rs
synced 2025-05-23 21:40:23 +00:00

This commit sets up logging by hooking into module loading/bootstraping process to call a new `init` function exported by the `Proxmox::Lib::{PVE,PMG}` module, which initializes `env_logger` with its default settings. This allows us to use `log::*` macros from Rust code. Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
76 lines
1.7 KiB
Perl
76 lines
1.7 KiB
Perl
package Proxmox::Lib::{{PRODUCT}};
|
|
|
|
=head1 NAME
|
|
|
|
Proxmox::Lib::{{PRODUCT}} - base module for {{PRODUCT}} rust bindings
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
package {{PRODUCT}}::RS::SomeBindings;
|
|
|
|
use base 'Proxmox::Lib::{{PRODUCT}}';
|
|
|
|
BEGIN { __PACKAGE__->bootstrap(); }
|
|
|
|
1;
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
This is the base module of all {{PRODUCT}} bindings.
|
|
Its job is to ensure the 'lib{{LIBRARY}}.so' library is loaded and provide a 'bootstrap' class
|
|
method to load the actual code.
|
|
|
|
=cut
|
|
|
|
use DynaLoader;
|
|
|
|
sub library {
|
|
return '{{LIBRARY}}';
|
|
}
|
|
|
|
# Keep on a single line, modified by testsuite!
|
|
sub libdirs { return (map "-L$_/auto", @INC); }
|
|
|
|
sub load : prototype($) {
|
|
my ($pkg) = @_;
|
|
|
|
my $mod_name = $pkg->library();
|
|
|
|
my @dirs = $pkg->libdirs();
|
|
my $mod_file = DynaLoader::dl_findfile({{DEBUG_LIBPATH}}@dirs, $mod_name);
|
|
die "failed to locate shared library for $mod_name (lib${mod_name}.so)\n" if !$mod_file;
|
|
|
|
my $lib = DynaLoader::dl_load_file($mod_file)
|
|
or die "failed to load library '$mod_file'\n";
|
|
|
|
my $data = ($::{'proxmox-rs-library'} //= {});
|
|
$data->{$mod_name} = $lib;
|
|
$data->{-current} //= $lib;
|
|
$data->{-package} //= $pkg;
|
|
}
|
|
|
|
sub bootstrap {
|
|
my ($pkg) = @_;
|
|
|
|
my $mod_name = $pkg->library();
|
|
|
|
my $bootstrap_name = 'boot_' . ($pkg =~ s/::/__/gr);
|
|
|
|
my $lib = $::{'proxmox-rs-library'}
|
|
or die "rust library not available for '{PRODUCT}'\n";
|
|
$lib = $lib->{$mod_name};
|
|
|
|
my $sym = DynaLoader::dl_find_symbol($lib, $bootstrap_name);
|
|
die "failed to locate '$bootstrap_name'\n" if !defined $sym;
|
|
my $boot = DynaLoader::dl_install_xsub($bootstrap_name, $sym, "src/FIXME.rs");
|
|
$boot->();
|
|
}
|
|
|
|
BEGIN {
|
|
__PACKAGE__->load();
|
|
__PACKAGE__->bootstrap();
|
|
init();
|
|
}
|
|
|
|
1;
|