diff options
| author | bjorn3 <bjorn3@users.noreply.github.com> | 2022-04-30 13:34:40 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-30 13:34:40 +0200 |
| commit | 9152ded3bfd11d9bd3273a1e35dac1565545c7ca (patch) | |
| tree | 6d4700f4845bd4ed6441f0653cb6c7a56004e6a6 /src | |
| parent | 944a48d3afb0fa27390ecbd2ceb0f1c666cf4c5b (diff) | |
| parent | 88d058fef3a1b583edf86b326265ed59c614da2e (diff) | |
| download | rust-9152ded3bfd11d9bd3273a1e35dac1565545c7ca.tar.gz rust-9152ded3bfd11d9bd3273a1e35dac1565545c7ca.zip | |
Merge pull request #1225 from bjorn3/build_system_rework
Use -Zcodegen-backend instead of a custom rustc driver
Diffstat (limited to 'src')
| -rw-r--r-- | src/bin/cg_clif.rs | 94 | ||||
| -rw-r--r-- | src/bin/cg_clif_build_sysroot.rs | 93 |
2 files changed, 0 insertions, 187 deletions
diff --git a/src/bin/cg_clif.rs b/src/bin/cg_clif.rs deleted file mode 100644 index 5984ec8412a..00000000000 --- a/src/bin/cg_clif.rs +++ /dev/null @@ -1,94 +0,0 @@ -#![feature(rustc_private)] -#![warn(rust_2018_idioms)] -#![warn(unused_lifetimes)] -#![warn(unreachable_pub)] - -extern crate rustc_data_structures; -extern crate rustc_driver; -extern crate rustc_interface; -extern crate rustc_session; -extern crate rustc_target; - -use std::panic; - -use rustc_data_structures::profiling::{get_resident_set_size, print_time_passes_entry}; -use rustc_interface::interface; -use rustc_session::config::{ErrorOutputType, TrimmedDefPaths}; -use rustc_session::early_error; -use rustc_target::spec::PanicStrategy; - -// FIXME use std::lazy::SyncLazy once it stabilizes -use once_cell::sync::Lazy; - -const BUG_REPORT_URL: &str = "https://github.com/bjorn3/rustc_codegen_cranelift/issues/new"; - -static DEFAULT_HOOK: Lazy<Box<dyn Fn(&panic::PanicInfo<'_>) + Sync + Send + 'static>> = - Lazy::new(|| { - let hook = panic::take_hook(); - panic::set_hook(Box::new(|info| { - // Invoke the default handler, which prints the actual panic message and optionally a backtrace - (*DEFAULT_HOOK)(info); - - // Separate the output with an empty line - eprintln!(); - - // Print the ICE message - rustc_driver::report_ice(info, BUG_REPORT_URL); - })); - hook - }); - -#[derive(Default)] -pub struct CraneliftPassesCallbacks { - time_passes: bool, -} - -impl rustc_driver::Callbacks for CraneliftPassesCallbacks { - fn config(&mut self, config: &mut interface::Config) { - // If a --prints=... option has been given, we don't print the "total" - // time because it will mess up the --prints output. See #64339. - self.time_passes = config.opts.prints.is_empty() - && (config.opts.debugging_opts.time_passes || config.opts.debugging_opts.time); - - config.opts.cg.panic = Some(PanicStrategy::Abort); - config.opts.debugging_opts.panic_abort_tests = true; - config.opts.maybe_sysroot = Some(config.opts.maybe_sysroot.clone().unwrap_or_else(|| { - std::env::current_exe().unwrap().parent().unwrap().parent().unwrap().to_owned() - })); - - config.opts.trimmed_def_paths = TrimmedDefPaths::GoodPath; - } -} - -fn main() { - let start_time = std::time::Instant::now(); - let start_rss = get_resident_set_size(); - rustc_driver::init_rustc_env_logger(); - let mut callbacks = CraneliftPassesCallbacks::default(); - Lazy::force(&DEFAULT_HOOK); // Install ice hook - let exit_code = rustc_driver::catch_with_exit_code(|| { - let args = std::env::args_os() - .enumerate() - .map(|(i, arg)| { - arg.into_string().unwrap_or_else(|arg| { - early_error( - ErrorOutputType::default(), - &format!("Argument {} is not valid Unicode: {:?}", i, arg), - ) - }) - }) - .collect::<Vec<_>>(); - let mut run_compiler = rustc_driver::RunCompiler::new(&args, &mut callbacks); - run_compiler.set_make_codegen_backend(Some(Box::new(move |_| { - Box::new(rustc_codegen_cranelift::CraneliftCodegenBackend { config: None }) - }))); - run_compiler.run() - }); - - if callbacks.time_passes { - let end_rss = get_resident_set_size(); - print_time_passes_entry("total", start_time.elapsed(), start_rss, end_rss); - } - - std::process::exit(exit_code) -} diff --git a/src/bin/cg_clif_build_sysroot.rs b/src/bin/cg_clif_build_sysroot.rs deleted file mode 100644 index bde4d71b9a3..00000000000 --- a/src/bin/cg_clif_build_sysroot.rs +++ /dev/null @@ -1,93 +0,0 @@ -//! The only difference between this and cg_clif.rs is that this binary defaults to using cg_llvm -//! instead of cg_clif and requires `--clif` to use cg_clif and that this binary doesn't have JIT -//! support. -//! This is necessary as with Cargo `RUSTC` applies to both target crates and host crates. The host -//! crates must be built with cg_llvm as we are currently building a sysroot for cg_clif. -//! `RUSTFLAGS` however is only applied to target crates, so `--clif` would only be passed to the -//! target crates. - -#![feature(rustc_private)] -#![warn(rust_2018_idioms)] -#![warn(unused_lifetimes)] -#![warn(unreachable_pub)] - -extern crate rustc_driver; -extern crate rustc_interface; -extern crate rustc_session; -extern crate rustc_target; - -use std::path::PathBuf; - -use rustc_interface::interface; -use rustc_session::config::ErrorOutputType; -use rustc_session::early_error; -use rustc_target::spec::PanicStrategy; - -fn find_sysroot() -> String { - // Taken from https://github.com/Manishearth/rust-clippy/pull/911. - let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME")); - let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN")); - match (home, toolchain) { - (Some(home), Some(toolchain)) => format!("{}/toolchains/{}", home, toolchain), - _ => option_env!("RUST_SYSROOT") - .expect("need to specify RUST_SYSROOT env var or use rustup or multirust") - .to_owned(), - } -} - -pub struct CraneliftPassesCallbacks { - use_clif: bool, -} - -impl rustc_driver::Callbacks for CraneliftPassesCallbacks { - fn config(&mut self, config: &mut interface::Config) { - if !self.use_clif { - config.opts.maybe_sysroot = Some(PathBuf::from(find_sysroot())); - return; - } - - config.opts.cg.panic = Some(PanicStrategy::Abort); - config.opts.debugging_opts.panic_abort_tests = true; - config.opts.maybe_sysroot = - Some(std::env::current_exe().unwrap().parent().unwrap().parent().unwrap().to_owned()); - } -} - -fn main() { - rustc_driver::init_rustc_env_logger(); - rustc_driver::install_ice_hook(); - let exit_code = rustc_driver::catch_with_exit_code(|| { - let mut use_clif = false; - - let args = std::env::args_os() - .enumerate() - .map(|(i, arg)| { - arg.into_string().unwrap_or_else(|arg| { - early_error( - ErrorOutputType::default(), - &format!("Argument {} is not valid Unicode: {:?}", i, arg), - ) - }) - }) - .filter(|arg| { - if arg == "--clif" { - use_clif = true; - false - } else { - true - } - }) - .collect::<Vec<_>>(); - - let mut callbacks = CraneliftPassesCallbacks { use_clif }; - - let mut run_compiler = rustc_driver::RunCompiler::new(&args, &mut callbacks); - if use_clif { - run_compiler.set_make_codegen_backend(Some(Box::new(move |_| { - Box::new(rustc_codegen_cranelift::CraneliftCodegenBackend { config: None }) - }))); - } - run_compiler.run() - }); - std::process::exit(exit_code) -} |
