]> git.proxmox.com Git - perlmod.git/commitdiff
perlmod-bin package for pm file generation
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Mon, 8 May 2023 07:38:47 +0000 (09:38 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 10 May 2023 08:11:51 +0000 (10:11 +0200)
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Makefile
perlmod-bin/debian/changelog [new file with mode: 0644]
perlmod-bin/debian/compat [new file with mode: 0644]
perlmod-bin/debian/control [new file with mode: 0644]
perlmod-bin/debian/copyright [new file with mode: 0644]
perlmod-bin/debian/install [new file with mode: 0644]
perlmod-bin/debian/rules [new file with mode: 0755]
perlmod-bin/genpackage.pl [new file with mode: 0755]
perlmod/debian/debcargo.toml

index 0aca19d4b0ad361df893bc2bb8e4a7605e8b990d..b47c584a3bd2e6921c85f84aab36d4778a4db611 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -17,6 +17,12 @@ dinstall:
        $(MAKE) deb
        sudo -k dpkg -i build/librust-*.deb
 
+perlmod-bin-deb:
+       mkdir build || true
+       rm -rf build/perlmod-bin-deb
+       git archive --format=tar HEAD perlmod-bin | tar -C build -xf -
+       cd build/perlmod-bin && dpkg-buildpackage --no-sign -b
+
 %-deb:
        ./build.sh $*
        touch $@
diff --git a/perlmod-bin/debian/changelog b/perlmod-bin/debian/changelog
new file mode 100644 (file)
index 0000000..502ebb9
--- /dev/null
@@ -0,0 +1,5 @@
+perlmod-bin (0.1.0-1) stable; urgency=medium
+
+  * initial packaging
+
+ -- Proxmox Support Team <support@proxmox.com>  Wed, 10 May 2023 10:11:13 +0200
diff --git a/perlmod-bin/debian/compat b/perlmod-bin/debian/compat
new file mode 100644 (file)
index 0000000..48082f7
--- /dev/null
@@ -0,0 +1 @@
+12
diff --git a/perlmod-bin/debian/control b/perlmod-bin/debian/control
new file mode 100644 (file)
index 0000000..77079d9
--- /dev/null
@@ -0,0 +1,21 @@
+Source: perlmod-bin
+Section: rust
+Priority: optional
+Build-Depends: debhelper (>= 12),
+ perl (>= 5.28.1) <!nocheck>
+Maintainer: Proxmox Support Team <support@proxmox.com>
+Standards-Version: 4.6.1
+Homepage: https://www.proxmox.com
+
+Package: perlmod-bin
+Architecture: all
+Depends:
+ ${perl:Depends},
+Recommends:
+ librust-perlmod+perlmod-macro-dev (= ${binary:Version})
+Description: Script to generate perl package files for perlmod libraries.
+ This contains the genpackage.pl helper script to produce a set of perl
+ packages which load cdylibs made with the perlmod crate. The generated files
+ will have a "main" library module which loads the .so file, and a set of
+ package files using the main module as a base, sothey all share the same
+ library descriptor.
diff --git a/perlmod-bin/debian/copyright b/perlmod-bin/debian/copyright
new file mode 100644 (file)
index 0000000..4fce23a
--- /dev/null
@@ -0,0 +1,16 @@
+Copyright (C) 2023 Proxmox Server Solutions GmbH
+
+This software is written by Proxmox Server Solutions GmbH <support@proxmox.com>
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU Affero General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU Affero General Public License for more details.
+
+You should have received a copy of the GNU Affero General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>.
diff --git a/perlmod-bin/debian/install b/perlmod-bin/debian/install
new file mode 100644 (file)
index 0000000..1df7289
--- /dev/null
@@ -0,0 +1 @@
+genpackage.pl usr/lib/perlmod
diff --git a/perlmod-bin/debian/rules b/perlmod-bin/debian/rules
new file mode 100755 (executable)
index 0000000..955dd78
--- /dev/null
@@ -0,0 +1,13 @@
+#!/usr/bin/make -f
+# -*- makefile -*-
+# Sample debian/rules that uses debhelper.
+# This file was originally written by Joey Hess and Craig Small.
+# As a special exception, when this file is copied by dh-make into a
+# dh-make output file, you may use that output file without restriction.
+# This special exception was added by Craig Small in version 0.37 of dh-make.
+
+# Uncomment this to turn on verbose mode.
+#export DH_VERBOSE=1
+
+%:
+       dh $@
diff --git a/perlmod-bin/genpackage.pl b/perlmod-bin/genpackage.pl
new file mode 100755 (executable)
index 0000000..5e13990
--- /dev/null
@@ -0,0 +1,215 @@
+#!/usr/bin/env perl
+
+# Create a perl package given a product and package name.
+
+use strict;
+use warnings;
+
+use File::Path qw(make_path);
+
+my @packages;
+
+my $opts = {
+    'lib-tag' => [
+        'TAG',
+        'An identifier used to avoid loading multiple libraries with the same shared code',
+    ],
+    'lib-package' => [
+        'Package',
+        'Main package to generate for loading the library',
+    ],
+    'lib-prefix' => [
+        'Prefix',
+        'Package prefix used for documentation in the library package.',
+    ],
+    'lib' => [
+        'LIBNAME',
+        "The .so name without the 'lib' prefix.",
+    ],
+    'debug-libpath' => [
+        'PATH',
+        "Path to a debug library, usually ./target/debug.",
+    ],
+};
+
+sub help {
+    my ($fd) = @_;
+
+    print {$fd} "usage: $0 OPTIONS <packages...>\n";
+    print {$fd} "mandatory OPTIONS are:\n";
+    for my $o (sort keys %$opts) {
+        my ($arg, $desc) = $opts->{$o}->@*;
+        my $p = "--$o=$arg";
+        printf {$fd} "  %20s   %s\n", $p, $desc;
+    }
+}
+
+if (!@ARGV) {
+    help(\*STDERR);
+    exit(1);
+}
+
+my $params = {};
+ARGPARSE: while (@ARGV) {
+    my $arg = shift @ARGV;
+
+    last if $arg eq '--';
+
+    if ($arg eq '-h' || $arg eq '--help') {
+        help(\*STDOUT);
+        exit(0);
+    }
+
+    for my $o (keys %$opts) {
+        if ($arg =~ /^(?:--\Q$o\E=)(.+)$/) {
+            my $arg = $1;
+            die "multiple --$o options provided\n" if defined($params->{$o});
+            $params->{$o} = $arg;
+            next ARGPARSE;
+        } elsif ($arg =~ /^--\Q$o\E$/) {
+            $arg = shift @ARGV;
+            die "multiple --$o options provided\n" if defined($params->{$o});
+            die "--$o requires an argument\n" if !defined($arg);
+            $params->{$o} = $arg;
+            next ARGPARSE;
+        }
+    }
+
+    if ($arg =~ /^-/) {
+        help(\*STDERR);
+        exit(1);
+    }
+
+    unshift @ARGV, $arg;
+    last;
+}
+
+my $lib_package = $params->{'lib-package'}
+    or die "missing --lib-package parameter\n";
+my $lib_prefix = $params->{'lib-prefix'}
+    or die "missing --lib-prefix parameter\n";
+my $lib = $params->{'lib'}
+    or die "missing --lib parameter\n";
+my $lib_tag = $params->{'lib-tag'};
+my $debug_libpath = $params->{'debug-libpath'} // '';
+
+sub pkg2file {
+    return ($_[0] =~ s@::@/@gr) . ".pm";
+}
+
+sub parentdir {
+    if ($_[0] =~ m@^(.*)/[^/]+@) {
+        return $1
+    } else {
+        die "bad path: '$_[0]', try adding a directory\n";
+    }
+}
+
+my $template = <<'EOF';
+package {{LIBRARY_PACKAGE}};
+
+=head1 NAME
+
+{{LIBRARY_PACKAGE}} - base module for {{LIBRARY_PREFIX}} rust bindings
+
+=head1 SYNOPSIS
+
+    package {{LIBRARY_PREFIX}}::RS::SomeBindings;
+
+    use base '{{LIBRARY_PACKAGE}}';
+
+    BEGIN { __PACKAGE__->bootstrap(); }
+
+    1;
+
+=head1 DESCRIPTION
+
+This is the base module of all {{LIBRARY_PREFIX}} bindings.
+Its job is to ensure the 'lib{{LIBRARY}}.so' library is loaded and provide a 'bootstrap'
+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 = ($::{'{{LIBRARY_TAG}}-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 = $::{'{{LIBRARY_TAG}}-rs-library'}
+       or die "rust library not available for '{{LIBRARY_PREFIX}}'\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;
+EOF
+$template =~ s/\{\{LIBRARY_PACKAGE\}\}/$lib_package/g;
+$template =~ s/\{\{LIBRARY_PREFIX\}\}/$lib_prefix/g;
+$template =~ s/\{\{LIBRARY_TAG\}\}/$lib_tag/g;
+$template =~ s/\{\{LIBRARY\}\}/$lib/g;
+$template =~ s/\{\{DEBUG_LIBPATH\}\}/$debug_libpath/g;
+
+if ($lib ne '-') {
+    my $path = pkg2file($lib_package);
+    print "Generating $path\n";
+
+    make_path(parentdir($path), { mode => 0755 });
+    open(my $fh, '>', $path) or die "failed to open '$path' for writing: $!\n";
+    print {$fh} $template;
+    close($fh);
+}
+
+for my $package (@ARGV) {
+    my $path = ($package =~ s@::@/@gr) . ".pm";
+
+    print "Generating $path\n";
+
+    $path =~ m@^(.*)/[^/]+@;
+    make_path($1, { mode => 0755 });
+
+    open(my $fh, '>', $path) or die "failed to open '$path' for writing: $!\n";
+    print {$fh} "package $package;\n";
+    print {$fh} "use base '$lib_package';\n";
+    print {$fh} "BEGIN { __PACKAGE__->bootstrap(); }\n";
+    print {$fh} "1;\n";
+    close($fh);
+}
index 5233c5c27a6c01d6a663851b660cebab0ac2e9ba..06e89e3ba546719ea6b79806041fb24bdd76f4d5 100644 (file)
@@ -1,6 +1,7 @@
 overlay = "."
 crate_src_path = ".."
 whitelist = [ "src/glue.c" ]
+excludes = [ "generators" ]
 
 [source]
 # TODO