yolo_rustc_bootstrap/
lib.rs

1#[proc_macro]
2pub fn do_crimes(_: proc_macro::TokenStream) -> proc_macro::TokenStream {
3    if !std::env::args_os().any(|arg| arg == "--cfg=yolo_rustc_bootstrap") {
4        let version = String::from_utf8(
5            std::process::Command::new(std::env::args_os().next().unwrap())
6                .arg("--version")
7                .output()
8                .unwrap()
9                .stdout,
10        )
11        .unwrap();
12        let version = version.split(' ').nth(1).unwrap();
13        let trick = !version.ends_with("-nightly");
14
15        if trick {
16            println!("\x1b[1;32m   Hijacking\x1b[m this rustc process");
17            println!("\x1b[1;32m     Abusing\x1b[m proc macros");
18            println!("\x1b[1;32m    Enabling\x1b[m the forbidden environment variable");
19            println!("\x1b[1;32m    Tricking\x1b[m rustc {}", version);
20            if let (Ok(c), Ok(v)) = (
21                std::env::var("CARGO_PKG_NAME"),
22                std::env::var("CARGO_PKG_VERSION"),
23            ) {
24                println!("\x1b[1;32m Recompiling\x1b[m {} v{}", c, v);
25            } else {
26                println!("\x1b[1;32m Recompiling\x1b[m your crate");
27            }
28        }
29
30        let mut args = std::env::args_os();
31        let status = std::process::Command::new(args.next().unwrap())
32            .arg("--cfg=yolo_rustc_bootstrap")
33            .args(args)
34            .env("RUSTC_BOOTSTRAP", "1")
35            .status()
36            .unwrap();
37
38        if trick && status.success() {
39            println!("\x1b[1;32m    Finished\x1b[m the dirty work");
40            println!("\x1b[1;32m      Hiding\x1b[m all the evidence");
41            println!("\x1b[1;32m  Continuing\x1b[m as if nothing happened");
42        }
43
44        std::process::exit(status.code().unwrap_or(101));
45    }
46
47    println!("\x1b[1;32m  Destroying\x1b[m stability guarantees");
48
49    Default::default()
50}