Zillowe FoundationZillowe Documentation

Library API

How to integrate Zoi's package management features into your own Rust applications.

Zoi is not just a command-line tool; it's also a Rust library that you can use to programmatically build and manage packages. This allows you to embed Zoi's powerful packaging capabilities directly into your own applications.

Docs.rs. Crates.io.

Getting Started

To use Zoi as a library, add it as a dependency in your project:

cargo add zoi-rs

Or in your Cargo.toml file:

[dependencies]
zoi-rs = "1" # Check crates.io for the latest version

Core Functions

These are the primary functions for building and managing packages.


build function

This function builds a Zoi package from a .pkg.lua definition file for one or more target platforms.

Signature

pub fn build(
    package_file: &Path,
    build_type: &str,
    platforms: &[String],
    sign_key: Option<String>,
) -> Result<()>

Parameters

ParameterTypeDescription
package_file&PathThe path to the .pkg.lua file that defines the package.
build_type&strThe type of package to build (e.g. "source", "pre-compiled"). This must be supported by the package.
platforms&[String]A slice of platform strings to build for (e.g. ["linux-amd64", "windows-amd64"]).
sign_keyOption<String>An optional PGP key name or fingerprint to sign the resulting package archive.

install_package function

Installs a Zoi package from a local .pkg.tar.zst archive file.

Signature

pub fn install_package(
    package_file: &Path,
    scope_override: Option<Scope>,
    registry_handle: &str,
    yes: bool,
    sub_packages: Option<Vec<String>>,
) -> Result<Vec<String>>

Parameters

ParameterTypeDescription
package_file&PathThe path to the local package archive (.pkg.tar.zst).
scope_overrideOption<Scope>An optional Scope (User, System, Project) to override the default scope defined in the package.
registry_handle&strThe handle of the registry this package belongs to. Use "local" for packages not from a registry.
yesboolAutomatically answer "yes" to any confirmation prompts (e.g. file conflicts).
sub_packagesOption<Vec<String>>For split packages, optionally specify which sub-packages to install.

uninstall_package function

Removes a package that was previously installed by Zoi.

Signature

pub fn uninstall_package(
    package_name: &str,
    scope_override: Option<Scope>
) -> Result<()>

Parameters

ParameterTypeDescription
package_name&strThe name of the package to uninstall.
scope_overrideOption<Scope>Optionally specify the scope to uninstall from. If None, Zoi will search for the package in all scopes.

For complete, runnable examples, please see the Library Examples page.


Last updated on