Copied from Miri Returns the "default sysroot" if no `--sysroot` flag is set. Should be a compile-time constant.
()
| 2 | /// Returns the "default sysroot" if no `--sysroot` flag is set. |
| 3 | /// Should be a compile-time constant. |
| 4 | pub fn compile_time_sysroot() -> Option<String> { |
| 5 | if option_env!("RUSTC_STAGE").is_some() { |
| 6 | // This is being built as part of rustc, and gets shipped with rustup. |
| 7 | // We can rely on the sysroot computation in librustc. |
| 8 | return None; |
| 9 | } |
| 10 | // For builds outside rustc, we need to ensure that we got a sysroot |
| 11 | // that gets used as a default. The sysroot computation in librustc would |
| 12 | // end up somewhere in the build dir. |
| 13 | // Taken from PR <https://github.com/Manishearth/rust-clippy/pull/911>. |
| 14 | let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME")); |
| 15 | let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN")); |
| 16 | Some(match (home, toolchain) { |
| 17 | (Some(home), Some(toolchain)) => format!("{}/toolchains/{}", home, toolchain), |
| 18 | _ => option_env!("RUST_SYSROOT") |
| 19 | .expect("To build Miri without rustup, set the `RUST_SYSROOT` env var at build time") |
| 20 | .to_owned(), |
| 21 | }) |
| 22 | } |
no test coverage detected