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 tests via `cargo test -p xtask`
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
11 #![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)]
23 path::{Path, PathBuf},
25 use xshell::{cmd, Shell};
27 fn main() -> anyhow::Result<()> {
28 let flags = flags::Xtask::from_env_or_exit();
30 let sh = &Shell::new()?;
31 sh.change_dir(project_root());
33 match flags.subcommand {
34 flags::XtaskCmd::Install(cmd) => cmd.run(sh),
35 flags::XtaskCmd::FuzzTests(_) => run_fuzzer(sh),
36 flags::XtaskCmd::Release(cmd) => cmd.run(sh),
37 flags::XtaskCmd::Promote(cmd) => cmd.run(sh),
38 flags::XtaskCmd::Dist(cmd) => cmd.run(sh),
39 flags::XtaskCmd::Metrics(cmd) => cmd.run(sh),
40 flags::XtaskCmd::Bb(cmd) => {
42 let _d = sh.push_dir("./crates/rust-analyzer");
43 cmd!(sh, "cargo build --release --features jemalloc").run()?;
46 "./target/release/rust-analyzer",
47 format!("./target/rust-analyzer-{}", cmd.suffix),
54 fn project_root() -> PathBuf {
56 &env::var("CARGO_MANIFEST_DIR").unwrap_or_else(|_| env!("CARGO_MANIFEST_DIR").to_owned()),
64 fn run_fuzzer(sh: &Shell) -> anyhow::Result<()> {
65 let _d = sh.push_dir("./crates/syntax");
66 let _e = sh.push_env("RUSTUP_TOOLCHAIN", "nightly");
67 if cmd!(sh, "cargo fuzz --help").read().is_err() {
68 cmd!(sh, "cargo install cargo-fuzz").run()?;
71 // Expecting nightly rustc
72 let out = cmd!(sh, "rustc --version").read()?;
73 if !out.contains("nightly") {
74 bail!("fuzz tests require nightly rustc")
77 cmd!(sh, "cargo fuzz run parser").run()?;
81 fn date_iso(sh: &Shell) -> anyhow::Result<String> {
82 let res = cmd!(sh, "date -u +%Y-%m-%d").read()?;
86 fn is_release_tag(tag: &str) -> bool {
87 tag.len() == "2020-02-24".len() && tag.starts_with(|c: char| c.is_ascii_digit())