[pve-devel] [pbs-devel] [RFC v5 pve-rs 16/23] add perlmod crate with initial APT module

Wolfgang Bumiller w.bumiller at proxmox.com
Mon May 31 15:07:30 CEST 2021


On Fri, May 28, 2021 at 04:29:55PM +0200, Fabian Ebner wrote:
> and disable diskmanage for now, whose Cargo.toml references local paths.
> 
> Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
> ---
> 
> New in v5.
> 
>  Cargo.toml                      |  3 +-
>  perlmod/Cargo.toml              | 17 ++++++++++
>  perlmod/src/apt/mod.rs          |  1 +
>  perlmod/src/apt/repositories.rs | 55 +++++++++++++++++++++++++++++++++
>  perlmod/src/lib.rs              |  1 +
>  5 files changed, 76 insertions(+), 1 deletion(-)
>  create mode 100644 perlmod/Cargo.toml
>  create mode 100644 perlmod/src/apt/mod.rs
>  create mode 100644 perlmod/src/apt/repositories.rs
>  create mode 100644 perlmod/src/lib.rs
> 
> diff --git a/Cargo.toml b/Cargo.toml
> index d16a498..0ffd4a2 100644
> --- a/Cargo.toml
> +++ b/Cargo.toml
> @@ -1,4 +1,5 @@
>  [workspace]
>  members = [
> -    "diskmanage",
> +#    "diskmanage",
> +    "perlmod",
>  ]
> diff --git a/perlmod/Cargo.toml b/perlmod/Cargo.toml
> new file mode 100644
> index 0000000..397f444
> --- /dev/null
> +++ b/perlmod/Cargo.toml
> @@ -0,0 +1,17 @@
> +[package]
> +name = "pve-rs"
> +version = "0.1.0"
> +authors = ["Proxmox Support Team <support at proxmox.com>"]
> +edition = "2018"
> +license = "AGPL-3"
> +description = "Perl bindings for proxmox-apt"
> +homepage = "https://www.proxmox.com"
> +
> +[lib]
> +crate-type = [ "cdylib" ]
> +
> +[dependencies]
> +anyhow = "1.0"
> +proxmox = { version = "0.11.5" }
> +proxmox-apt = "0.1.0"
> +perlmod = { version = "0.4.3", features = [ "exporter" ] }
> diff --git a/perlmod/src/apt/mod.rs b/perlmod/src/apt/mod.rs
> new file mode 100644
> index 0000000..574c1a7
> --- /dev/null
> +++ b/perlmod/src/apt/mod.rs
> @@ -0,0 +1 @@
> +mod repositories;
> diff --git a/perlmod/src/apt/repositories.rs b/perlmod/src/apt/repositories.rs
> new file mode 100644
> index 0000000..37a62f2
> --- /dev/null
> +++ b/perlmod/src/apt/repositories.rs
> @@ -0,0 +1,55 @@
> +#[perlmod::package(name = "PVE::RS::APT::Repositories", lib = "pve_rs")]
> +mod export {
> +    use anyhow::{bail, Error};
> +
> +    use perlmod::{to_value, Value};
> +
> +    #[export(raw_return)]
> +    fn repositories() -> Result<(Value, Value, Value), Error> {

Please also add some documentation to exported methods, especially if
you skip writing out the return type.
Ideally we'd also add some kind of doc generation to perlmod in the
future which could in theory also link to the types from the foreign
crates you're returning here, so please assume that that's already the
case ;-)

Come to think of it, since we need a `mod` statement anyway, it probably
makes sense to use `pub fn` for exported functions (since the `mod`
itself is not-`pub`).
This also means we could utilize `#![deny(missing_docs)]` inside those
`mod`s ;-)

> +        let (files, errors) = proxmox_apt::repositories::repositories()?;
> +
> +        if files.is_empty() {
> +            bail!("no APT repository files could be parsed!");
> +        }
> +
> +        let common_digest = proxmox_apt::repositories::common_digest(&files);
> +
> +        let hex_digest = proxmox::tools::digest_to_hex(&common_digest);
> +
> +        Ok((
> +            to_value(&files)?,
> +            to_value(&errors)?,
> +            to_value(&hex_digest)?,
> +        ))
> +    }
> +
> +    #[export(raw_return)]
> +    fn check_repositories(digest: String) -> Result<(Value, Value, Value), Error> {

^ same





More information about the pve-devel mailing list