2019-10-26 09:20:44 -05:00
|
|
|
//! See https://github.com/matklad/cargo-xtask/.
|
|
|
|
//!
|
|
|
|
//! This binary defines various auxiliary build commands, which are not
|
|
|
|
//! expressible with just `cargo`. Notably, it provides `cargo xtask codegen`
|
2019-10-30 15:17:27 -05:00
|
|
|
//! for code generation and `cargo xtask install` for installation of
|
2019-10-26 09:20:44 -05:00
|
|
|
//! rust-analyzer server and client.
|
|
|
|
//!
|
|
|
|
//! This binary is integrated into the `cargo` command line by using an alias in
|
|
|
|
//! `.cargo/config`.
|
2019-09-10 06:56:45 -05:00
|
|
|
|
2020-01-07 07:42:56 -06:00
|
|
|
use std::env;
|
2019-11-20 00:47:14 -06:00
|
|
|
|
2020-08-18 12:31:06 -05:00
|
|
|
use codegen::CodegenCmd;
|
2019-09-10 06:56:45 -05:00
|
|
|
use pico_args::Arguments;
|
2020-10-16 12:46:03 -05:00
|
|
|
use xshell::pushd;
|
2019-10-17 11:36:55 -05:00
|
|
|
use xtask::{
|
2019-10-23 10:13:40 -05:00
|
|
|
codegen::{self, Mode},
|
2020-07-24 08:59:01 -05:00
|
|
|
dist::DistCmd,
|
2020-10-16 17:35:06 -05:00
|
|
|
install::{InstallCmd, Malloc, ServerOpt},
|
2020-07-24 17:16:21 -05:00
|
|
|
metrics::MetricsCmd,
|
2020-08-18 03:38:57 -05:00
|
|
|
pre_cache::PreCacheCmd,
|
2020-06-08 06:58:54 -05:00
|
|
|
pre_commit, project_root,
|
2020-07-07 11:12:22 -05:00
|
|
|
release::{PromoteCmd, ReleaseCmd},
|
2020-08-18 03:38:57 -05:00
|
|
|
run_clippy, run_fuzzer, run_rustfmt, Result,
|
2018-12-31 07:14:06 -06:00
|
|
|
};
|
2018-07-30 06:06:22 -05:00
|
|
|
|
|
|
|
fn main() -> Result<()> {
|
2019-11-20 00:47:14 -06:00
|
|
|
if env::args().next().map(|it| it.contains("pre-commit")) == Some(true) {
|
2020-01-07 07:42:56 -06:00
|
|
|
return pre_commit::run_hook();
|
2019-11-18 06:22:51 -06:00
|
|
|
}
|
|
|
|
|
2020-10-16 12:46:03 -05:00
|
|
|
let _d = pushd(project_root())?;
|
2020-03-04 10:58:22 -06:00
|
|
|
|
2020-01-08 04:27:31 -06:00
|
|
|
let mut args = Arguments::from_env();
|
|
|
|
let subcommand = args.subcommand()?.unwrap_or_default();
|
2020-01-07 07:42:56 -06:00
|
|
|
|
|
|
|
match subcommand.as_str() {
|
2019-10-17 11:36:55 -05:00
|
|
|
"install" => {
|
2020-01-07 07:42:56 -06:00
|
|
|
if args.contains(["-h", "--help"]) {
|
|
|
|
eprintln!(
|
|
|
|
"\
|
|
|
|
cargo xtask install
|
|
|
|
Install rust-analyzer server or editor plugin.
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
cargo xtask install [FLAGS]
|
|
|
|
|
|
|
|
FLAGS:
|
2020-10-20 15:37:02 -05:00
|
|
|
--client[=CLIENT] Install only VS Code plugin.
|
2020-12-08 13:28:32 -06:00
|
|
|
CLIENT is one of 'code', 'code-exploration', 'code-insiders', 'codium', or 'code-oss'
|
2020-10-20 15:37:02 -05:00
|
|
|
--server Install only the language server
|
|
|
|
--mimalloc Use mimalloc for server
|
|
|
|
-h, --help Prints help information
|
2020-01-07 07:42:56 -06:00
|
|
|
"
|
|
|
|
);
|
2019-09-10 10:17:11 -05:00
|
|
|
return Ok(());
|
|
|
|
}
|
2020-01-07 07:42:56 -06:00
|
|
|
let server = args.contains("--server");
|
2020-10-20 15:37:02 -05:00
|
|
|
let client_code = args.contains("--client");
|
2019-09-10 10:17:11 -05:00
|
|
|
if server && client_code {
|
2020-01-07 07:42:56 -06:00
|
|
|
eprintln!(
|
2020-10-20 15:37:02 -05:00
|
|
|
"error: The argument `--server` cannot be used with `--client`\n\n\
|
2020-01-07 07:42:56 -06:00
|
|
|
For more information try --help"
|
|
|
|
);
|
2019-09-10 06:56:45 -05:00
|
|
|
return Ok(());
|
|
|
|
}
|
2020-01-07 07:42:56 -06:00
|
|
|
|
2020-07-22 06:40:45 -05:00
|
|
|
let malloc =
|
|
|
|
if args.contains("--mimalloc") { Malloc::Mimalloc } else { Malloc::System };
|
2020-01-07 07:42:56 -06:00
|
|
|
|
2020-10-20 15:37:02 -05:00
|
|
|
let client_opt = args.opt_value_from_str("--client")?;
|
2020-10-16 17:35:06 -05:00
|
|
|
|
2020-01-07 07:42:56 -06:00
|
|
|
args.finish()?;
|
|
|
|
|
|
|
|
InstallCmd {
|
2020-10-16 17:35:06 -05:00
|
|
|
client: if server { None } else { Some(client_opt.unwrap_or_default()) },
|
2020-07-13 19:12:49 -05:00
|
|
|
server: if client_code { None } else { Some(ServerOpt { malloc }) },
|
2020-01-07 07:42:56 -06:00
|
|
|
}
|
|
|
|
.run()
|
2019-09-10 06:56:45 -05:00
|
|
|
}
|
2019-10-17 11:36:55 -05:00
|
|
|
"codegen" => {
|
2020-08-18 12:31:06 -05:00
|
|
|
let features = args.contains("--features");
|
2020-01-07 07:42:56 -06:00
|
|
|
args.finish()?;
|
2020-08-18 12:31:06 -05:00
|
|
|
CodegenCmd { features }.run()
|
2019-09-10 06:56:45 -05:00
|
|
|
}
|
2020-01-07 07:42:56 -06:00
|
|
|
"format" => {
|
|
|
|
args.finish()?;
|
|
|
|
run_rustfmt(Mode::Overwrite)
|
2019-09-10 06:56:45 -05:00
|
|
|
}
|
2020-01-07 07:42:56 -06:00
|
|
|
"install-pre-commit-hook" => {
|
|
|
|
args.finish()?;
|
|
|
|
pre_commit::install_hook()
|
2019-09-18 06:24:20 -05:00
|
|
|
}
|
2020-01-07 07:42:56 -06:00
|
|
|
"lint" => {
|
|
|
|
args.finish()?;
|
|
|
|
run_clippy()
|
|
|
|
}
|
|
|
|
"fuzz-tests" => {
|
|
|
|
args.finish()?;
|
|
|
|
run_fuzzer()
|
|
|
|
}
|
2020-01-07 09:01:41 -06:00
|
|
|
"pre-cache" => {
|
|
|
|
args.finish()?;
|
2020-08-18 03:38:57 -05:00
|
|
|
PreCacheCmd.run()
|
2020-01-07 09:01:41 -06:00
|
|
|
}
|
2020-02-10 08:32:03 -06:00
|
|
|
"release" => {
|
2020-02-14 11:33:30 -06:00
|
|
|
let dry_run = args.contains("--dry-run");
|
2020-02-10 08:32:03 -06:00
|
|
|
args.finish()?;
|
2020-06-08 07:00:30 -05:00
|
|
|
ReleaseCmd { dry_run }.run()
|
2020-02-10 08:32:03 -06:00
|
|
|
}
|
2020-07-07 11:12:22 -05:00
|
|
|
"promote" => {
|
|
|
|
let dry_run = args.contains("--dry-run");
|
|
|
|
args.finish()?;
|
|
|
|
PromoteCmd { dry_run }.run()
|
|
|
|
}
|
2020-03-04 10:58:22 -06:00
|
|
|
"dist" => {
|
2020-04-08 04:47:40 -05:00
|
|
|
let nightly = args.contains("--nightly");
|
|
|
|
let client_version: Option<String> = args.opt_value_from_str("--client")?;
|
2020-03-04 10:58:22 -06:00
|
|
|
args.finish()?;
|
2020-07-24 08:59:01 -05:00
|
|
|
DistCmd { nightly, client_version }.run()
|
2020-03-04 10:58:22 -06:00
|
|
|
}
|
2020-07-24 17:16:21 -05:00
|
|
|
"metrics" => {
|
|
|
|
let dry_run = args.contains("--dry-run");
|
|
|
|
args.finish()?;
|
|
|
|
MetricsCmd { dry_run }.run()
|
|
|
|
}
|
2020-01-07 07:42:56 -06:00
|
|
|
_ => {
|
|
|
|
eprintln!(
|
|
|
|
"\
|
|
|
|
cargo xtask
|
|
|
|
Run custom build command.
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
cargo xtask <SUBCOMMAND>
|
|
|
|
|
|
|
|
SUBCOMMANDS:
|
|
|
|
format
|
|
|
|
install-pre-commit-hook
|
|
|
|
fuzz-tests
|
|
|
|
codegen
|
|
|
|
install
|
2020-03-04 10:58:22 -06:00
|
|
|
lint
|
2020-07-24 08:59:01 -05:00
|
|
|
dist
|
|
|
|
promote"
|
2020-01-07 07:42:56 -06:00
|
|
|
);
|
|
|
|
Ok(())
|
2019-11-14 02:11:32 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|