zoi/cmd/package/
build.rs

1use anyhow::Result;
2use clap::Parser;
3use std::path::PathBuf;
4
5#[derive(Parser, Debug)]
6pub struct BuildCommand {
7    /// Path to the package file (e.g. path/to/name.pkg.lua)
8    #[arg(required = true)]
9    pub package_file: PathBuf,
10
11    /// The type of package to build (e.g. 'source', 'pre-compiled').
12    #[arg(long, required = true)]
13    pub r#type: String,
14
15    /// The platform to build for (e.g. 'linux-amd64', 'windows-arm64', 'all', 'current').
16    /// Can be specified multiple times.
17    #[arg(long, short, num_args = 1.., default_values_t = vec!["current".to_string()])]
18    pub platform: Vec<String>,
19
20    /// The sub-packages to build.
21    #[arg(long, num_args = 1..)]
22    pub sub: Option<Vec<String>>,
23
24    /// Sign the package with the given PGP key (name or fingerprint)
25    #[arg(long)]
26    pub sign: Option<String>,
27
28    /// Run tests before building
29    #[arg(long)]
30    pub test: bool,
31
32    /// Directory to output the built package to
33    #[arg(long, short = 'o')]
34    pub output_dir: Option<PathBuf>,
35}
36
37pub fn run(args: BuildCommand) -> Result<()> {
38    if args.test {
39        println!("Running tests before building...");
40        crate::pkg::package::test::run(&args)?;
41        println!("Tests passed, proceeding with build...");
42    }
43
44    crate::pkg::package::build::run(
45        &args.package_file,
46        &args.r#type,
47        &args.platform,
48        args.sign,
49        args.output_dir.as_deref(),
50        None,
51        args.sub,
52        false,
53    )
54}