Skip to content

Commit

Permalink
build(xtask): ➖ remove sh crate from xtask
Browse files Browse the repository at this point in the history
  • Loading branch information
Jisu-Woniu committed Jan 8, 2025
1 parent 144eeb7 commit bfc6ac0
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 102 deletions.
6 changes: 3 additions & 3 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[alias]
xtask = "run --package xtask --"
xtask-dbg = "run --package xtask --features dbg --"
xtask = "run --package xtask --locked --"
xtask-dbg = "run --package xtask --features dbg --locked --"

# Use custom linker for faster linking
# # Use custom linker for faster linking
# [build]
# rustflags = ["-Clink-arg=-fuse-ld=mold"]
99 changes: 24 additions & 75 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions dprint.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"plugins": [
"https://plugins.dprint.dev/json-0.19.4.wasm",
"https://plugins.dprint.dev/markdown-0.17.8.wasm",
"https://plugins.dprint.dev/toml-0.6.3.wasm",
"https://plugins.dprint.dev/exec-0.5.0.json@8d9972eee71fa1590e04873540421f3eda7674d0f1aae3d7c788615e7b7413d0",
"https://plugins.dprint.dev/toml-0.6.4.wasm",
"https://plugins.dprint.dev/exec-0.5.1.json@492414e39dea4dccc07b4af796d2f4efdb89e84bae2bd4e1e924c0cc050855bf",
"https://plugins.dprint.dev/g-plane/pretty_yaml-v0.5.0.wasm"
]
}
1 change: 0 additions & 1 deletion xtask/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ description = "A task runner for cargo workspaces"
[dependencies]
anyhow = "1.0.95"
clap = { version = "4.5.24", features = ["derive"] }
sh = "0.2.1"

[features]
dbg = []
39 changes: 18 additions & 21 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// SPDX-License-Identifier: Apache-2.0

use std::{env::set_current_dir, path::Path};
use std::{env::set_current_dir, io, path::Path, process::Command};

use clap::{Parser, ValueEnum};
use sh::cmd;

#[derive(Debug, ValueEnum, Clone, Copy, PartialEq, Eq)]
/// Package distribution-specific packages.
Expand All @@ -17,12 +16,12 @@ enum Package {
#[derive(Debug, Parser)]
#[clap(about, long_about)]
/// Build related tasks.
enum Command {
enum Args {
/// Package distribution-specific packages.
Dist {
/// Which package to build.
#[arg(value_enum)]
package: Package,
pkg: Package,
},
/// Build Docker image.
Docker,
Expand All @@ -31,30 +30,28 @@ enum Command {
Debug,
}

fn exec(program: &str, args: &[&str]) -> io::Result<()> {
Command::new(program).args(args).spawn()?.wait()?;
Ok(())
}

fn main() -> anyhow::Result<()> {
let command = Command::parse();
let args = Args::parse();

// chdir to the workspace root so that `cargo xtask` can be invoked from anywhere.
set_current_dir(Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap())?;

match command {
Command::Dist { package } => match package {
Package::Deb => cmd!(cargo deb "-v" "--locked"),
Package::Rpm => cmd! {
cargo build "--release" "--locked";
cargo "generate-rpm"
},
},
Command::Docker => cmd!(docker build "-t" rsjudge "."),

match args {
Args::Dist { pkg: Package::Deb } => exec("cargo", &["deb", "-v", "--locked"])?,
Args::Dist { pkg: Package::Rpm } => {
// `cargo-generate-rpm` does not invoke `cargo build` itself.
exec("cargo", &["build", "--release", "--locked"])?;
exec("cargo", &["generate-rpm"])?;
}
Args::Docker => exec("docker", &["build", "-t", "rsjudge", "."])?,
#[cfg(feature = "dbg")]
Command::Debug => return Ok(()),
Args::Debug => {}
}
.try_for_each(|cmd| {
#[cfg(feature = "dbg")]
eprintln!("Executing: {:?}", cmd);
cmd.exec()
})?;

Ok(())
}

0 comments on commit bfc6ac0

Please sign in to comment.