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.
Getting Started
To use Zoi as a library, add it as a dependency in your project:
cargo add zoi-rsOr in your Cargo.toml file:
[dependencies]
zoi-rs = "1" # Check crates.io for the latest versionCore Functions
These are the primary functions for building and managing packages.
build
Builds a Zoi package from a local .pkg.lua file.
install_package
Installs a Zoi package from a local package archive.
uninstall_package
Uninstalls a Zoi package.
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
| Parameter | Type | Description |
|---|---|---|
package_file | &Path | The path to the .pkg.lua file that defines the package. |
build_type | &str | The 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_key | Option<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
| Parameter | Type | Description |
|---|---|---|
package_file | &Path | The path to the local package archive (.pkg.tar.zst). |
scope_override | Option<Scope> | An optional Scope (User, System, Project) to override the default scope defined in the package. |
registry_handle | &str | The handle of the registry this package belongs to. Use "local" for packages not from a registry. |
yes | bool | Automatically answer "yes" to any confirmation prompts (e.g. file conflicts). |
sub_packages | Option<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
| Parameter | Type | Description |
|---|---|---|
package_name | &str | The name of the package to uninstall. |
scope_override | Option<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
