diff --git a/.cargo/config.toml b/.cargo/config.toml index 7f6e8105529..8b35c3e70ee 100755 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -7,6 +7,7 @@ lint = "clippy --workspace --all-targets -- --deny warnings" # AKA `test-update`, handy cargo rst update without install `cargo-rst` binary t = "test --no-fail-fast" tu = "run -p cargo-rst -- update" +xtask = "run --package xtask --" [target.'cfg(all())'] rustflags = [ diff --git a/Cargo.lock b/Cargo.lock index 279351836d5..8c374cddf1c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -82,6 +82,55 @@ dependencies = [ "libc", ] +[[package]] +name = "anstream" +version = "0.6.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" + +[[package]] +name = "anstyle-parse" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" +dependencies = [ + "anstyle", + "windows-sys 0.52.0", +] + [[package]] name = "any_ascii" version = "0.1.7" @@ -418,6 +467,46 @@ dependencies = [ "windows-targets 0.52.0", ] +[[package]] +name = "clap" +version = "4.5.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e5a21b8495e732f1b3c364c9949b201ca7bae518c502c80256c96ad79eaf6ac" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8cf2dd12af7a047ad9d6da2b6b249759a22a7abc0f474c1dae1777afa4b21a73" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim 0.11.1", +] + +[[package]] +name = "clap_derive" +version = "4.5.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "501d359d5f3dcaf6ecdeee48833ae73ec6e42723a1e52419c79abf9507eec0a0" +dependencies = [ + "heck 0.5.0", + "proc-macro2", + "quote", + "syn 2.0.63", +] + +[[package]] +name = "clap_lex" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" + [[package]] name = "color-backtrace" version = "0.6.1" @@ -428,6 +517,12 @@ dependencies = [ "termcolor", ] +[[package]] +name = "colorchoice" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" + [[package]] name = "concat-string" version = "1.0.1" @@ -753,7 +848,7 @@ dependencies = [ "ident_case", "proc-macro2", "quote", - "strsim", + "strsim 0.10.0", "syn 1.0.109", ] @@ -1632,6 +1727,12 @@ version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "616cde7c720bb2bb5824a224687d8f77bfd38922027f01d825cd7453be5099fb" +[[package]] +name = "is_terminal_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" + [[package]] name = "itertools" version = "0.10.5" @@ -4515,6 +4616,12 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + [[package]] name = "sugar_path" version = "1.2.0" @@ -6248,6 +6355,12 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5190c9442dcdaf0ddd50f37420417d219ae5261bbf5db120d0f9bab996c9cba1" +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + [[package]] name = "uuid" version = "1.4.1" @@ -7189,6 +7302,14 @@ dependencies = [ "libc", ] +[[package]] +name = "xtask" +version = "0.1.0" +dependencies = [ + "anyhow", + "clap", +] + [[package]] name = "xxhash-rust" version = "0.8.10" diff --git a/Cargo.toml b/Cargo.toml index 43ffb7f1fc9..c9a06d0851d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,8 @@ cargo-features = ["trim-paths"] [workspace] -members = ["crates/*"] -resolver = "2" # See https://doc.rust-lang.org/cargo/reference/resolver.html#feature-resolver-version-2 +members = ["crates/*", "xtask"] +resolver = "2" # See https://doc.rust-lang.org/cargo/reference/resolver.html#feature-resolver-version-2 [workspace.package] authors = ["Rspack Teams"] diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml new file mode 100644 index 00000000000..207239cb37f --- /dev/null +++ b/xtask/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "xtask" +version = "0.1.0" +edition = "2021" +publish = false +authors.workspace = true +categories.workspace = true +documentation.workspace = true +homepage.workspace = true +license.workspace = true +repository.workspace = true + +[dependencies] +anyhow = { workspace = true } +clap = { version = "4.4.6", features = ["derive"] } + +[lints] +workspace = true diff --git a/xtask/src/commands/api_extractor.rs b/xtask/src/commands/api_extractor.rs new file mode 100644 index 00000000000..8cc8ba62c1b --- /dev/null +++ b/xtask/src/commands/api_extractor.rs @@ -0,0 +1,36 @@ +use anyhow::{Context, Result}; +use clap::{Parser, Subcommand}; + +use crate::utils::command::run_command; + +#[derive(Debug, Parser)] +pub struct ApiExtractorCmd { + #[clap(subcommand)] + sub_cmd: ApiExtractorSubCmd, +} + +#[derive(Debug, Subcommand)] +pub enum ApiExtractorSubCmd { + Update, + Ci, +} + +impl ApiExtractorCmd { + pub fn run(&self) -> Result<()> { + match &self.sub_cmd { + ApiExtractorSubCmd::Update => { + run_command("pnpm", &["-w", "build:js"])?; + run_command( + "pnpm", + &["--filter", "@rspack/*", "api-extractor", "--local"], + )?; + } + ApiExtractorSubCmd::Ci => { + run_command("pnpm", &["--filter", "@rspack/*", "api-extractor:ci"]).with_context(|| { + "Api-extractor testing failed. Did you forget to update the snapshots locally?\nRun the command below locally to fix this error (in the *ROOT* of rspack workspace).\n$ ./x api-extractor update" + })?; + } + } + Ok(()) + } +} diff --git a/xtask/src/commands/mod.rs b/xtask/src/commands/mod.rs new file mode 100644 index 00000000000..3920408ff21 --- /dev/null +++ b/xtask/src/commands/mod.rs @@ -0,0 +1 @@ +pub mod api_extractor; diff --git a/xtask/src/main.rs b/xtask/src/main.rs new file mode 100644 index 00000000000..2e65527f9cc --- /dev/null +++ b/xtask/src/main.rs @@ -0,0 +1,31 @@ +use anyhow::Result; +use clap::{Parser, Subcommand}; +use commands::*; + +mod commands; +mod utils; + +#[derive(Debug, Parser)] +#[clap( + name = "Rspack Development CLI", + version = "1.0", + about = "CLI for development of Rspack" +)] +struct CliArgs { + #[clap(subcommand)] + cmd: Cmd, +} + +#[derive(Debug, Subcommand)] +enum Cmd { + #[clap(name = "api-extractor")] + ApiExtractor(api_extractor::ApiExtractorCmd), +} + +fn main() -> Result<()> { + let args = CliArgs::parse(); + + match args.cmd { + Cmd::ApiExtractor(cmd) => cmd.run(), + } +} diff --git a/xtask/src/utils/command.rs b/xtask/src/utils/command.rs new file mode 100644 index 00000000000..08908ca9beb --- /dev/null +++ b/xtask/src/utils/command.rs @@ -0,0 +1,30 @@ +use std::process::Command; + +use anyhow::{Context, Result}; + +#[cfg(windows)] +const PNPM: &str = "pnpm.cmd"; +#[cfg(not(windows))] +const PNPM: &str = "pnpm"; + +pub fn run_command(command: &str, args: &[&str]) -> Result<()> { + let program = match command { + "pnpm" => PNPM, + other => other, + }; + + let status = Command::new(program) + .args(args) + .status() + .context("Failed to execute command")?; + + if status.success() { + Ok(()) + } else { + Err(anyhow::anyhow!( + "Command `{}` failed with status code: {}", + command, + status.code().unwrap_or(-1) + )) + } +} diff --git a/xtask/src/utils/mod.rs b/xtask/src/utils/mod.rs new file mode 100644 index 00000000000..9fe79612b68 --- /dev/null +++ b/xtask/src/utils/mod.rs @@ -0,0 +1 @@ +pub mod command;