hpkg 1.0.0

A native Rust crate to parse Haiku's binary package and repo formats
Documentation
extern crate hpkg;

use std::{env, process};
use hpkg::repository_writer::RepositoryWriter;
use hpkg::repository::PackageInfo;
use hpkg::hpkg_common::{B_HPKG_COMPRESSION_ZSTD, ARCH_X86_64};

/// Simple HPKR writer example: creates a sample repository cache file.
fn main() {
    let args: Vec<String> = env::args().collect();
    if args.len() != 2 {
        eprintln!("usage: hpkr_write <output.hpkr>");
        eprintln!();
        eprintln!("Creates a sample HPKR repository cache with inline package data.");
        process::exit(1);
    }

    let output = &args[1];

    let mut writer = RepositoryWriter::new(output);
    writer.set_name("HaikuPorts")
          .set_summary("The HaikuPorts package repository (sample)")
          .set_vendor("Haiku Project")
          .set_base_url("https://eu.hpkg.haiku-os.org/haikuports/master/x86_64/current")
          .set_architecture(ARCH_X86_64)
          .set_priority(1)
          .set_identifier("haikuports-x86_64")
          .set_compression(B_HPKG_COMPRESSION_ZSTD);

    // First package
    let mut pkg = PackageInfo::new();
    pkg.name = Some("gcc".to_string());
    pkg.summary = Some("The GNU Compiler Collection".to_string());
    pkg.description = Some("The GCC compiler suite includes compilers for C, C++, and more.".to_string());
    pkg.vendor = Some("GNU".to_string());
    pkg.packager = Some("Haiku Project".to_string());
    pkg.architecture = Some("x86_64".to_string());
    pkg.version_major = Some("14".to_string());
    pkg.version_minor = Some("2".to_string());
    pkg.version_micro = Some("0".to_string());
    pkg.version_revision = Some(1);
    pkg.licenses.push("GPL-3.0-or-later".to_string());
    pkg.provides.push("gcc = 14.2.0".to_string());
    pkg.provides.push("cmd:gcc = 14.2.0".to_string());
    pkg.requires.push("gmp".to_string());
    pkg.requires.push("mpfr".to_string());
    pkg.url = Some("https://gcc.gnu.org/".to_string());
    writer.add_package(pkg);

    // Second package
    let mut pkg2 = PackageInfo::new();
    pkg2.name = Some("python312".to_string());
    pkg2.summary = Some("The Python programming language".to_string());
    pkg2.description = Some("Python is a high-level, interpreted programming language.".to_string());
    pkg2.vendor = Some("Python Software Foundation".to_string());
    pkg2.architecture = Some("x86_64".to_string());
    pkg2.version_major = Some("3".to_string());
    pkg2.version_minor = Some("12".to_string());
    pkg2.version_micro = Some("5".to_string());
    pkg2.version_revision = Some(2);
    pkg2.copyrights.push("Copyright 2001-2024 Python Software Foundation".to_string());
    pkg2.licenses.push("PSF-2.0".to_string());
    pkg2.provides.push("python = 3.12.5".to_string());
    pkg2.provides.push("cmd:python3 = 3.12.5".to_string());
    pkg2.requires.push("gcc_libs".to_string());
    pkg2.url = Some("https://www.python.org/".to_string());
    writer.add_package(pkg2);

    // Finalize and write to disk
    writer.finish().unwrap_or_else(|e| {
        eprintln!("Error writing HPKR: {}", e);
        process::exit(1);
    });

    println!("Created {}", output);
}