Skip to content

Commit

Permalink
Introduce cargo xtasks pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
mkaput committed Jul 21, 2023
1 parent c7b2e34 commit 146096f
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[alias]
xtask = "run --quiet --package xtask --"

# On Windows MSVC, statically link the C runtime so that the resulting EXE does
# not depend on the vcruntime DLL.
[target.'cfg(windows)']
Expand Down
17 changes: 13 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ members = [
"utils/create-output-dir",
"utils/scarb-test-support",
"utils/test-for-each-example",
"xtask",
]

[workspace.package]
Expand Down Expand Up @@ -83,6 +84,7 @@ typed-builder = "0.14.0"
url = { version = "2.3.1", features = ["serde"] }
walkdir = "2.3.3"
which = "4.4.0"
xshell = "0.2.5"
xxhash-rust = { version = "0.8.6", features = ["xxh3"] }
zip = { version = "0.6.6", default-features = false, features = ["deflate"] }

Expand Down
2 changes: 1 addition & 1 deletion pkg/archive/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mkdir -p \
"$STAGING/bin/" \
"$STAGING/doc/"

for crate in $(pkg/list-binaries.sh); do
for crate in $(cargo xtask list-binaries); do
cp "target/$TARGET/release/${crate}${bin_ext}" "$STAGING/bin/"
done

Expand Down
5 changes: 0 additions & 5 deletions pkg/list-binaries.sh

This file was deleted.

10 changes: 10 additions & 0 deletions xtask/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "xtask"
version = "1.0.0"
edition.workspace = true
publish = false

[dependencies]
anyhow.workspace = true
clap.workspace = true
xshell.workspace = true
11 changes: 11 additions & 0 deletions xtask/src/list_binaries.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use anyhow::Result;
use std::fs;

pub fn main() -> Result<()> {
println!("scarb");
for entry in fs::read_dir("extensions")? {
let entry = entry?;
println!("{}", entry.file_name().to_string_lossy());
}
Ok(())
}
22 changes: 22 additions & 0 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use anyhow::Result;
use clap::{Parser, Subcommand};

mod list_binaries;

#[derive(Parser)]
struct Args {
#[command(subcommand)]
command: Command,
}

#[derive(Subcommand, Clone, Debug)]
pub enum Command {
ListBinaries,
}

fn main() -> Result<()> {
let args = Args::parse();
match args.command {
Command::ListBinaries => list_binaries::main(),
}
}

0 comments on commit 146096f

Please sign in to comment.