diff --git a/Makefile b/Makefile index 00bb32b6..a1ed278e 100644 --- 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/template.pm b/Proxmox/Lib/template.pm deleted file mode 100644 index 9eb10cfb..00000000 --- a/Proxmox/Lib/template.pm +++ /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; diff --git a/common/pkg/Makefile b/common/pkg/Makefile index bf22a7b4..88ab0849 100644 --- a/common/pkg/Makefile +++ b/common/pkg/Makefile @@ -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/Proxmox/Lib/Common.pm b/common/pkg/Proxmox/Lib/Common.pm similarity index 100% rename from Proxmox/Lib/Common.pm rename to common/pkg/Proxmox/Lib/Common.pm diff --git a/common/scripts b/common/scripts deleted file mode 120000 index a339954d..00000000 --- a/common/scripts +++ /dev/null @@ -1 +0,0 @@ -../scripts \ No newline at end of file diff --git a/defines.mk b/defines.mk deleted file mode 100644 index b83abbf9..00000000 --- a/defines.mk +++ /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 diff --git a/pmg-rs/Makefile b/pmg-rs/Makefile index 8ca1cb76..28e1ea84 100644 --- a/pmg-rs/Makefile +++ b/pmg-rs/Makefile @@ -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 -ifeq ($(BUILD_MODE), release) -CARGO_BUILD_ARGS += --release -endif +PERLMOD_GENPACKAGE := /usr/lib/perlmod/genpackage.pl \ + --lib=pmg_rs \ + --lib-tag=proxmox \ + --lib-package=Proxmox::Lib::PMG \ + --lib-prefix=PMG -all: Proxmox/Lib/PMG.pm -ifneq ($(BUILD_MODE), skip) - cargo build $(CARGO_BUILD_ARGS) -endif - -PMG: ../scripts/genpackage.pl - perl ../scripts/genpackage.pl PMG \ +PERLMOD_PACKAGES := \ 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,../) +ifeq ($(BUILD_MODE), release) +CARGO_BUILD_ARGS += --release +TARGET_DIR=release +else +TARGET_DIR=debug +endif + +all: +ifneq ($(BUILD_MODE), skip) + cargo build $(CARGO_BUILD_ARGS) +endif + +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 index 00000000..60d3b0a6 --- /dev/null +++ b/pmg-rs/common @@ -0,0 +1 @@ +../common \ No newline at end of file diff --git a/pmg-rs/debian/control b/pmg-rs/debian/control index 8d4a1256..f0b31a63 100644 --- a/pmg-rs/debian/control +++ b/pmg-rs/debian/control @@ -5,6 +5,7 @@ Maintainer: Proxmox Support Team Build-Depends: debhelper (>= 12), dh-cargo (>= 24), + perlmod-bin, cargo:native , rustc:native , libstd-rust-dev , diff --git a/pmg-rs/src/lib.rs b/pmg-rs/src/lib.rs index 5914bc9e..86331365 100644 --- a/pmg-rs/src/lib.rs +++ b/pmg-rs/src/lib.rs @@ -1,4 +1,4 @@ -#[path = "../../common/src/mod.rs"] +#[path = "../common/src/mod.rs"] pub mod common; pub mod acme; diff --git a/pve-rs/Makefile b/pve-rs/Makefile index 9d12d58e..dd422e4f 100644 --- a/pve-rs/Makefile +++ b/pve-rs/Makefile @@ -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 index 00000000..60d3b0a6 --- /dev/null +++ b/pve-rs/common @@ -0,0 +1 @@ +../common \ No newline at end of file diff --git a/pve-rs/debian/control b/pve-rs/debian/control index b15ae7cc..fed874c8 100644 --- a/pve-rs/debian/control +++ b/pve-rs/debian/control @@ -4,6 +4,7 @@ Priority: optional Build-Depends: debhelper (>= 12), dh-cargo (>= 24), + perlmod-bin, cargo:native , rustc:native , libstd-rust-dev , diff --git a/pve-rs/src/lib.rs b/pve-rs/src/lib.rs index 671aad02..fc31b3aa 100644 --- a/pve-rs/src/lib.rs +++ b/pve-rs/src/lib.rs @@ -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 index ee7d98bf..00000000 --- a/scripts/genpackage.pl +++ /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); -}