]> git.proxmox.com Git - rustc.git/blob - src/tools/rust-analyzer/crates/proc-macro-srv-cli/src/main.rs
New upstream version 1.72.1+dfsg1
[rustc.git] / src / tools / rust-analyzer / crates / proc-macro-srv-cli / src / main.rs
1 //! A standalone binary for `proc-macro-srv`.
2 //! Driver for proc macro server
3 use std::io;
4
5 fn main() -> std::io::Result<()> {
6 let v = std::env::var("RUST_ANALYZER_INTERNALS_DO_NOT_USE");
7 match v.as_deref() {
8 Ok("this is unstable") => {
9 // very well, if you must
10 }
11 _ => {
12 eprintln!("If you're rust-analyzer, you can use this tool by exporting RUST_ANALYZER_INTERNALS_DO_NOT_USE='this is unstable'.");
13 eprintln!("If not, you probably shouldn't use this tool. But do what you want: I'm an error message, not a cop.");
14 std::process::exit(122);
15 }
16 }
17
18 run()
19 }
20
21 #[cfg(not(feature = "sysroot-abi"))]
22 fn run() -> io::Result<()> {
23 panic!("proc-macro-srv-cli requires the `sysroot-abi` feature to be enabled");
24 }
25
26 #[cfg(feature = "sysroot-abi")]
27 fn run() -> io::Result<()> {
28 use proc_macro_api::msg::{self, Message};
29
30 let read_request = |buf: &mut String| msg::Request::read(&mut io::stdin().lock(), buf);
31
32 let write_response = |msg: msg::Response| msg.write(&mut io::stdout().lock());
33
34 let mut srv = proc_macro_srv::ProcMacroSrv::default();
35 let mut buf = String::new();
36
37 while let Some(req) = read_request(&mut buf)? {
38 let res = match req {
39 msg::Request::ListMacros { dylib_path } => {
40 msg::Response::ListMacros(srv.list_macros(&dylib_path))
41 }
42 msg::Request::ExpandMacro(task) => msg::Response::ExpandMacro(srv.expand(task)),
43 msg::Request::ApiVersionCheck {} => {
44 msg::Response::ApiVersionCheck(proc_macro_api::msg::CURRENT_API_VERSION)
45 }
46 };
47 write_response(res)?
48 }
49
50 Ok(())
51 }