summaryrefslogtreecommitdiffstats
path: root/xtask/src/main.rs
diff options
context:
space:
mode:
authorToby Vincent <tobyv13@gmail.com>2023-06-01 16:22:10 -0500
committerToby Vincent <tobyv13@gmail.com>2023-06-01 19:03:25 -0500
commit7201e443e19b45a2feb24ef470c6380b0859e52f (patch)
tree6c5fc66926db06faa29101cb8f57793ed9e9ba2c /xtask/src/main.rs
parenteaf5c71873705b9593ec0e6b34d7e529d74a9269 (diff)
build: improve build tooling and add CD
Implement a xtask pattern tool for packaging into distributable. Add build script to generate completion scripts and man page. Improve PKGBUILDs and CI to use new tooling and upload artifact to tag after successful CI build. Make minor changes in cli config to facilitate the new build.rs script.
Diffstat (limited to 'xtask/src/main.rs')
-rw-r--r--xtask/src/main.rs65
1 files changed, 65 insertions, 0 deletions
diff --git a/xtask/src/main.rs b/xtask/src/main.rs
new file mode 100644
index 0000000..2282efd
--- /dev/null
+++ b/xtask/src/main.rs
@@ -0,0 +1,65 @@
+//! See <https://github.com/matklad/cargo-xtask/>.
+//!
+//! This binary defines various auxiliary build commands, which are not
+//! expressible with just `cargo`.
+//!
+//! This binary is integrated into the `cargo` command line by using an alias in
+//! `.cargo/config`.
+
+use std::path::PathBuf;
+
+use anyhow::Result;
+use clap::{Parser, Subcommand};
+
+fn main() -> Result<()> {
+ let cli = Cli::parse();
+
+ match cli.command {
+ Commands::Dist { tag } => {
+ let targz = xtask::generate_tar_gz(&cli.directory, &cli.profile, tag.as_deref())?;
+ println!("{}", targz.display());
+ }
+ Commands::OutDir => {
+ let profile_dir = cli.directory.join("target").join(&cli.profile);
+ let out_dir = xtask::find_out_dir(profile_dir)?;
+ println!("{}", out_dir.display());
+ }
+ };
+
+ Ok(())
+}
+
+#[derive(Debug, Clone, Parser)]
+#[command(author, version, about)]
+struct Cli {
+ #[command(subcommand)]
+ command: Commands,
+
+ /// Cargo profile to use.
+ #[arg(short, long, default_value = "release")]
+ profile: String,
+
+ /// Path to root directory of package.
+ #[arg(short='C', long, default_value_os_t = get_package_dir())]
+ directory: PathBuf,
+}
+
+#[derive(Debug, Clone, Subcommand)]
+enum Commands {
+ /// Print the default value of OUT_DIR used by cargo when building the package.
+ OutDir,
+
+ /// Generate distributable package and print it's path
+ Dist {
+ /// Verify the package version matches the provided tag.
+ #[arg(short, long)]
+ tag: Option<String>,
+ },
+}
+
+fn get_package_dir() -> PathBuf {
+ std::path::Path::new(&env!("CARGO_MANIFEST_DIR"))
+ .parent()
+ .unwrap()
+ .to_path_buf()
+}