]> git.proxmox.com Git - proxmox-perl-rs.git/commitdiff
major build system upgrade
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Tue, 9 May 2023 09:29:05 +0000 (11:29 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 10 May 2023 09:44:44 +0000 (11:44 +0200)
- Add a 'common' symlink inside pve-rs/pmg-rs
- Have the `build/` target replace it with a dir and copy
  `common/src` into it.
- Depend on perlmod-bin to generate the perl package files.

now pve-rs and pmg-rs can be built directly from within via
dpkg-buildpackage

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
16 files changed:
Makefile
Proxmox/Lib/Common.pm [deleted file]
Proxmox/Lib/template.pm [deleted file]
common/pkg/Makefile
common/pkg/Proxmox/Lib/Common.pm [new file with mode: 0644]
common/scripts [deleted symlink]
defines.mk [deleted file]
pmg-rs/Makefile
pmg-rs/common [new symlink]
pmg-rs/debian/control
pmg-rs/src/lib.rs
pve-rs/Makefile
pve-rs/common [new symlink]
pve-rs/debian/control
pve-rs/src/lib.rs
scripts/genpackage.pl [deleted file]

index 00bb32b6413d365a19bd28e2f403a235fce66ac1..a1ed278e450622f4d788169625690509a3e9b602 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,3 @@
-include defines.mk
-
 CARGO ?= cargo
 
 ifeq ($(BUILD_MODE), release)
@@ -38,17 +36,15 @@ build:
        mkdir build
        echo system >build/rust-toolchain
        cp -a ./Cargo.toml ./build
-       cp -a ./scripts ./build
        cp -a ./common ./build
        cp -a ./pve-rs ./build
        cp -a ./pmg-rs ./build
-       cp -a ./Proxmox ./build
-       cp defines.mk ./build
-       mv ./build/Proxmox ./build/common/pkg
-# The template.pm is required by the products to produce their Proxmox::Lib
-       mkdir ./build/Proxmox
-       mkdir ./build/Proxmox/Lib
-       cp ./Proxmox/Lib/template.pm ./build/Proxmox/Lib
+# Replace the symlinks with copies of the common code in pve/pmg:
+       cd build; for i in pve pmg; do \
+         rm ./$$i-rs/common ; \
+         mkdir ./$$i-rs/common ; \
+         cp -R ./common/src ./$$i-rs/common/src ; \
+       done
 # So the common packages end up in ./build, rather than ./build/common
        mv ./build/common/pkg ./build/common-pkg
 
diff --git a/Proxmox/Lib/Common.pm b/Proxmox/Lib/Common.pm
deleted file mode 100644 (file)
index 1e6b26d..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-package Proxmox::Lib::Common;
-
-=head1 NAME
-
-Proxmox::Lib::Common - base module for rust bindings common between PVE and PMG
-
-=head1 SYNOPSIS
-
-    package Proxmox::RS::CalendarEvent;
-
-    use base 'Proxmox::Lib::Common';
-
-    BEGIN { __PACKAGE__->bootstrap(); }
-
-    1;
-
-=head1 DESCRIPTION
-
-This is the base modules for bindings which are provided by both PVE and PMG. This will ensure that
-either Proxmox::Lib::PVE or Proxmox::Lib::PMG have been loaded (in that order) and then use
-whichever was loaded.
-
-=cut
-
-use vars qw(@ISA);
-
-sub library {
-    return '-current';
-}
-
-BEGIN {
-    my $data = ($::{'proxmox-rs-library'} //= {});
-    my $base = $data->{-package};
-    if ($base) {
-        push @ISA, $base;
-    } else {
-        eval { require Proxmox::Lib::PVE and push @ISA, 'Proxmox::Lib::PVE'; };
-        eval { require Proxmox::Lib::PMG and push @ISA, 'Proxmox::Lib::PMG'; } if $@;
-        die $@ if $@;
-    }
-}
-
-1;
diff --git a/Proxmox/Lib/template.pm b/Proxmox/Lib/template.pm
deleted file mode 100644 (file)
index 9eb10cf..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-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;
index bf22a7b4ef76d7d67a00546f95347ebb8947dcf7..88ab0849346f22a30a6f5969848377b8507d34b6 100644 (file)
@@ -12,9 +12,15 @@ DEB=${PACKAGE}_${DEB_VERSION}_${ARCH}.deb
 
 DESTDIR=
 
+PERLMOD_GENPACKAGE := /usr/lib/perlmod/genpackage.pl \
+       --lib=- \
+       --lib-tag=proxmox \
+       --lib-package=Proxmox::Lib::Common \
+       --lib-prefix=Proxmox
+
 # Point to any generated pm file (Proxmox/ dir is already present in this package)
-Proxmox/RS/CalendarEvent.pm: ../scripts/genpackage.pl
-       perl ../scripts/genpackage.pl Common \
+Proxmox/RS/CalendarEvent.pm:
+       $(PERLMOD_GENPACKAGE) \
          Proxmox::RS::APT::Repositories \
          Proxmox::RS::CalendarEvent \
          Proxmox::RS::Subscription
@@ -27,7 +33,6 @@ install: Proxmox/RS/CalendarEvent.pm
        install -d -m755 $(DESTDIR)$(PERL_INSTALLVENDORLIB)
        find PVE \! -type d -print -exec install -Dm644 '{}' $(DESTDIR)$(PERL_INSTALLVENDORLIB)'/{}' ';'
        find Proxmox \! -type d -print -exec install -Dm644 '{}' $(DESTDIR)$(PERL_INSTALLVENDORLIB)'/{}' ';'
-       rm $(DESTDIR)$(PERL_INSTALLVENDORLIB)'/Proxmox/Lib/template.pm'
 
 .PHONY: deb
 deb: $(DEB)
diff --git a/common/pkg/Proxmox/Lib/Common.pm b/common/pkg/Proxmox/Lib/Common.pm
new file mode 100644 (file)
index 0000000..1e6b26d
--- /dev/null
@@ -0,0 +1,43 @@
+package Proxmox::Lib::Common;
+
+=head1 NAME
+
+Proxmox::Lib::Common - base module for rust bindings common between PVE and PMG
+
+=head1 SYNOPSIS
+
+    package Proxmox::RS::CalendarEvent;
+
+    use base 'Proxmox::Lib::Common';
+
+    BEGIN { __PACKAGE__->bootstrap(); }
+
+    1;
+
+=head1 DESCRIPTION
+
+This is the base modules for bindings which are provided by both PVE and PMG. This will ensure that
+either Proxmox::Lib::PVE or Proxmox::Lib::PMG have been loaded (in that order) and then use
+whichever was loaded.
+
+=cut
+
+use vars qw(@ISA);
+
+sub library {
+    return '-current';
+}
+
+BEGIN {
+    my $data = ($::{'proxmox-rs-library'} //= {});
+    my $base = $data->{-package};
+    if ($base) {
+        push @ISA, $base;
+    } else {
+        eval { require Proxmox::Lib::PVE and push @ISA, 'Proxmox::Lib::PVE'; };
+        eval { require Proxmox::Lib::PMG and push @ISA, 'Proxmox::Lib::PMG'; } if $@;
+        die $@ if $@;
+    }
+}
+
+1;
diff --git a/common/scripts b/common/scripts
deleted file mode 120000 (symlink)
index a339954..0000000
+++ /dev/null
@@ -1 +0,0 @@
-../scripts
\ No newline at end of file
diff --git a/defines.mk b/defines.mk
deleted file mode 100644 (file)
index b83abbf..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-define package_template
-       sed -r \
-         -e 's/\{\{PRODUCT\}\}/$(1)/g;' \
-         -e 's/\{\{LIBRARY\}\}/$(2)/g;' \
-         -e 's|\{\{DEBUG_LIBPATH\}\}|$(DEBUG_LIBPATH)|g;' \
-         $(3)Proxmox/Lib/template.pm \
-         >Proxmox/Lib/$(1).pm
-endef
index 8ca1cb76ec35e21b2d5add6614179efe1864e407..28e1ea847298e93b9a36f69d96cab8bd9f1fc553 100644 (file)
@@ -1,4 +1,3 @@
-include ../defines.mk
 include /usr/share/dpkg/default.mk
 
 PACKAGE=libpmg-rs-perl
@@ -17,26 +16,34 @@ DESTDIR=
 
 PM_DIR := PMG
 
+PERLMOD_GENPACKAGE := /usr/lib/perlmod/genpackage.pl \
+       --lib=pmg_rs \
+       --lib-tag=proxmox \
+       --lib-package=Proxmox::Lib::PMG \
+       --lib-prefix=PMG
+
+PERLMOD_PACKAGES := \
+         PMG::RS::APT::Repositories \
+         PMG::RS::Acme \
+         PMG::RS::CSR \
+         PMG::RS::OpenId \
+         PMG::RS::TFA
+
 ifeq ($(BUILD_MODE), release)
 CARGO_BUILD_ARGS += --release
+TARGET_DIR=release
+else
+TARGET_DIR=debug
 endif
 
-all: Proxmox/Lib/PMG.pm
+all:
 ifneq ($(BUILD_MODE), skip)
        cargo build $(CARGO_BUILD_ARGS)
 endif
 
-PMG: ../scripts/genpackage.pl
-       perl ../scripts/genpackage.pl PMG \
-         PMG::RS::APT::Repositories \
-         PMG::RS::Acme \
-         PMG::RS::CSR \
-         PMG::RS::OpenId \
-         PMG::RS::TFA
-
-Proxmox/Lib/PMG.pm: ../Proxmox/Lib/template.pm
-       mkdir -p Proxmox/Lib
-       $(call package_template,PMG,pmg_rs,../)
+PMG: Proxmox/Lib/PMG.pm
+Proxmox/Lib/PMG.pm:
+       $(PERLMOD_GENPACKAGE) $(PERLMOD_PACKAGES)
 
 .PHONY: install
 install: ../target/release/libpmg_rs.so Proxmox/Lib/PMG.pm PMG
diff --git a/pmg-rs/common b/pmg-rs/common
new file mode 120000 (symlink)
index 0000000..60d3b0a
--- /dev/null
@@ -0,0 +1 @@
+../common
\ No newline at end of file
index 8d4a12561ce67832ec8b073b3bbddb2d0261a223..f0b31a636adb7f0c8809c9ef5bc2fce53d26fd97 100644 (file)
@@ -5,6 +5,7 @@ Maintainer: Proxmox Support Team <support@proxmox.com>
 Build-Depends:
  debhelper (>= 12),
  dh-cargo (>= 24),
+ perlmod-bin,
  cargo:native <!nocheck>,
  rustc:native <!nocheck>,
  libstd-rust-dev <!nocheck>,
index 5914bc9e343d8bf1d742cabdd93017dbeb3b3e43..86331365ed916735963775ee387517149fcf9d6b 100644 (file)
@@ -1,4 +1,4 @@
-#[path = "../../common/src/mod.rs"]
+#[path = "../common/src/mod.rs"]
 pub mod common;
 
 pub mod acme;
index 9d12d58e432c215f1a50c7ab9d89844e149ecfcb..dd422e4f42960bffcb96c81d5560a4414c15b271 100644 (file)
@@ -1,4 +1,3 @@
-include ../defines.mk
 include /usr/share/dpkg/default.mk
 
 PACKAGE=libpve-rs-perl
@@ -18,6 +17,18 @@ DESTDIR=
 
 PM_DIR := PVE
 
+PERLMOD_GENPACKAGE := /usr/lib/perlmod/genpackage.pl \
+       --lib=pve_rs \
+       --lib-tag=proxmox \
+       --lib-package=Proxmox::Lib::PVE \
+       --lib-prefix=PVE
+
+PERLMOD_PACKAGES := \
+         PVE::RS::APT::Repositories \
+         PVE::RS::OpenId \
+         PVE::RS::ResourceScheduling::Static \
+         PVE::RS::TFA
+
 ifeq ($(BUILD_MODE), release)
 CARGO_BUILD_ARGS += --release
 TARGET_DIR=release
@@ -25,7 +36,7 @@ else
 TARGET_DIR=debug
 endif
 
-all: PVE Proxmox/Lib/PVE.pm
+all: PVE
 ifneq ($(BUILD_MODE), skip)
        cargo build $(CARGO_BUILD_ARGS)
        mkdir -p test/Proxmox/Lib
@@ -34,16 +45,9 @@ ifneq ($(BUILD_MODE), skip)
          Proxmox/Lib/PVE.pm >test/Proxmox/Lib/PVE.pm
 endif
 
-PVE: ../scripts/genpackage.pl
-       perl ../scripts/genpackage.pl PVE \
-         PVE::RS::APT::Repositories \
-         PVE::RS::OpenId \
-         PVE::RS::ResourceScheduling::Static \
-         PVE::RS::TFA
-
-Proxmox/Lib/PVE.pm: ../Proxmox/Lib/template.pm
-       mkdir -p Proxmox/Lib
-       $(call package_template,PVE,pve_rs,../)
+PVE: Proxmox/Lib/PVE.pm
+Proxmox/Lib/PVE.pm:
+       $(PERLMOD_GENPACKAGE) $(PERLMOD_PACKAGES)
 
 check: all
        $(MAKE) -C test test
diff --git a/pve-rs/common b/pve-rs/common
new file mode 120000 (symlink)
index 0000000..60d3b0a
--- /dev/null
@@ -0,0 +1 @@
+../common
\ No newline at end of file
index b15ae7cc132b87e7d59edff3b924b8a43d16056c..fed874c8881f67cdb00771ccfd5aba50a5ed61ba 100644 (file)
@@ -4,6 +4,7 @@ Priority: optional
 Build-Depends:
  debhelper (>= 12),
  dh-cargo (>= 24),
+ perlmod-bin,
  cargo:native <!nocheck>,
  rustc:native <!nocheck>,
  libstd-rust-dev <!nocheck>,
index 671aad02a52d6da1609747a86cbf17707f6d0bd3..fc31b3aa9a52832a3adc1a5f988f6bd9957ee675 100644 (file)
@@ -1,6 +1,6 @@
 //! Rust library for the Proxmox VE code base.
 
-#[path = "../../common/src/mod.rs"]
+#[path = "../common/src/mod.rs"]
 pub mod common;
 
 pub mod apt;
diff --git a/scripts/genpackage.pl b/scripts/genpackage.pl
deleted file mode 100755 (executable)
index ee7d98b..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-#!/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 $product = shift @ARGV or die "missing product name (PVE, PMG or Common)\n";
-
-die "missing package name\n" if !@ARGV;
-
-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} <<"EOF";
-package $package;
-use base 'Proxmox::Lib::$product';
-BEGIN { __PACKAGE__->bootstrap(); }
-1;
-EOF
-
-    close($fh);
-}