1 //! See https://github.com/matklad/cargo-xtask/.
3 //! This binary defines various auxiliary build commands, which are not
4 //! expressible with just `cargo`. Notably, it provides `cargo xtask codegen`
5 //! for code generation and `cargo xtask install` for installation of
6 //! rust-analyzer server and client.
8 //! This binary is integrated into the `cargo` command line by using an alias in
13 use codegen::CodegenCmd;
14 use pico_args::Arguments;
17 codegen::{self, Mode},
19 install::{InstallCmd, Malloc, ServerOpt},
21 pre_cache::PreCacheCmd,
22 pre_commit, project_root,
23 release::{PromoteCmd, ReleaseCmd},
24 run_clippy, run_fuzzer, run_rustfmt, Result,
27 fn main() -> Result<()> {
28 if env::args().next().map(|it| it.contains("pre-commit")) == Some(true) {
29 return pre_commit::run_hook();
32 let _d = pushd(project_root())?;
34 let mut args = Arguments::from_env();
35 let subcommand = args.subcommand()?.unwrap_or_default();
37 match subcommand.as_str() {
39 if args.contains(["-h", "--help"]) {
43 Install rust-analyzer server or editor plugin.
46 cargo xtask install [FLAGS]
49 --client[=CLIENT] Install only VS Code plugin.
50 CLIENT is one of 'code', 'code-exploration', 'code-insiders', 'codium', or 'code-oss'
51 --server Install only the language server
52 --mimalloc Use mimalloc for server
53 -h, --help Prints help information
58 let server = args.contains("--server");
59 let client_code = args.contains("--client");
60 if server && client_code {
62 "error: The argument `--server` cannot be used with `--client`\n\n\
63 For more information try --help"
69 if args.contains("--mimalloc") { Malloc::Mimalloc } else { Malloc::System };
71 let client_opt = args.opt_value_from_str("--client")?;
76 client: if server { None } else { Some(client_opt.unwrap_or_default()) },
77 server: if client_code { None } else { Some(ServerOpt { malloc }) },
82 let features = args.contains("--features");
84 CodegenCmd { features }.run()
88 run_rustfmt(Mode::Overwrite)
90 "install-pre-commit-hook" => {
92 pre_commit::install_hook()
107 let dry_run = args.contains("--dry-run");
109 ReleaseCmd { dry_run }.run()
112 let dry_run = args.contains("--dry-run");
114 PromoteCmd { dry_run }.run()
117 let nightly = args.contains("--nightly");
118 let client_version: Option<String> = args.opt_value_from_str("--client")?;
120 DistCmd { nightly, client_version }.run()
123 let dry_run = args.contains("--dry-run");
125 MetricsCmd { dry_run }.run()
131 Run custom build command.
134 cargo xtask <SUBCOMMAND>
138 install-pre-commit-hook