]> git.lizzy.rs Git - rust.git/blob - xtask/src/flags.rs
Merge #11564
[rust.git] / xtask / src / flags.rs
1 #![allow(unreachable_pub)]
2
3 use crate::install::{ClientOpt, Malloc, ServerOpt};
4
5 xflags::xflags! {
6     src "./src/flags.rs"
7
8     /// Run custom build command.
9     cmd xtask {
10         default cmd help {
11             /// Print help information.
12             optional -h, --help
13         }
14
15         /// Install rust-analyzer server or editor plugin.
16         cmd install {
17             /// Install only VS Code plugin.
18             optional --client
19             /// One of 'code', 'code-exploration', 'code-insiders', 'codium', or 'code-oss'.
20             optional --code-bin name: String
21
22             /// Install only the language server.
23             optional --server
24             /// Use mimalloc allocator for server
25             optional --mimalloc
26             /// Use jemalloc allocator for server
27             optional --jemalloc
28         }
29
30         cmd fuzz-tests {}
31
32         cmd release {
33             optional --dry-run
34         }
35         cmd promote {
36             optional --dry-run
37         }
38         cmd dist {
39             optional --client-patch-version version: String
40         }
41         cmd metrics {
42             optional --dry-run
43         }
44         /// Builds a benchmark version of rust-analyzer and puts it into `./target`.
45         cmd bb
46             required suffix: String
47         {}
48     }
49 }
50
51 // generated start
52 // The following code is generated by `xflags` macro.
53 // Run `env UPDATE_XFLAGS=1 cargo build` to regenerate.
54 #[derive(Debug)]
55 pub struct Xtask {
56     pub subcommand: XtaskCmd,
57 }
58
59 #[derive(Debug)]
60 pub enum XtaskCmd {
61     Help(Help),
62     Install(Install),
63     FuzzTests(FuzzTests),
64     Release(Release),
65     Promote(Promote),
66     Dist(Dist),
67     Metrics(Metrics),
68     Bb(Bb),
69 }
70
71 #[derive(Debug)]
72 pub struct Help {
73     pub help: bool,
74 }
75
76 #[derive(Debug)]
77 pub struct Install {
78     pub client: bool,
79     pub code_bin: Option<String>,
80     pub server: bool,
81     pub mimalloc: bool,
82     pub jemalloc: bool,
83 }
84
85 #[derive(Debug)]
86 pub struct FuzzTests;
87
88 #[derive(Debug)]
89 pub struct Release {
90     pub dry_run: bool,
91 }
92
93 #[derive(Debug)]
94 pub struct Promote {
95     pub dry_run: bool,
96 }
97
98 #[derive(Debug)]
99 pub struct Dist {
100     pub client_patch_version: Option<String>,
101 }
102
103 #[derive(Debug)]
104 pub struct Metrics {
105     pub dry_run: bool,
106 }
107
108 #[derive(Debug)]
109 pub struct Bb {
110     pub suffix: String,
111 }
112
113 impl Xtask {
114     pub const HELP: &'static str = Self::HELP_;
115
116     #[allow(dead_code)]
117     pub fn from_env() -> xflags::Result<Self> {
118         Self::from_env_()
119     }
120
121     #[allow(dead_code)]
122     pub fn from_vec(args: Vec<std::ffi::OsString>) -> xflags::Result<Self> {
123         Self::from_vec_(args)
124     }
125 }
126 // generated end
127
128 impl Install {
129     pub(crate) fn server(&self) -> Option<ServerOpt> {
130         if self.client && !self.server {
131             return None;
132         }
133         let malloc = if self.mimalloc {
134             Malloc::Mimalloc
135         } else if self.jemalloc {
136             Malloc::Jemalloc
137         } else {
138             Malloc::System
139         };
140         Some(ServerOpt { malloc })
141     }
142     pub(crate) fn client(&self) -> Option<ClientOpt> {
143         if !self.client && self.server {
144             return None;
145         }
146         Some(ClientOpt { code_bin: self.code_bin.clone() })
147     }
148 }