From 17a54ad62e217c1b6e3848efe522666f443809a2 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Tue, 29 Sep 2020 14:43:34 +0200 Subject: [PATCH] Add custom driver --- scripts/config.sh | 9 ++++-- src/bin/cg_clif.rs | 77 ++++++++++++++++++++++++++++++++++++++++++++++ test.sh | 9 +++--- 3 files changed, 88 insertions(+), 7 deletions(-) create mode 100644 src/bin/cg_clif.rs diff --git a/scripts/config.sh b/scripts/config.sh index 728667ec367..acd048893e9 100644 --- a/scripts/config.sh +++ b/scripts/config.sh @@ -32,15 +32,18 @@ if [[ "$HOST_TRIPLE" != "$TARGET_TRIPLE" ]]; then fi fi -export RUSTFLAGS=$linker' -Ztrim-diagnostic-paths=no -Cpanic=abort -Cdebuginfo=2 -Zpanic-abort-tests -Zcodegen-backend='$(pwd)'/target/'$CHANNEL'/librustc_codegen_cranelift.'$dylib_ext' --sysroot '$(pwd)'/build_sysroot/sysroot' -export RUSTDOCFLAGS=$RUSTFLAGS +export RUSTC=$(pwd)/"target/"$CHANNEL"/cg_clif" +export RUSTFLAGS=$linker +export RUSTDOCFLAGS=$linker' -Ztrim-diagnostic-paths=no -Cpanic=abort -Zpanic-abort-tests '\ +'-Zcodegen-backend='$(pwd)'/target/'$CHANNEL'/librustc_codegen_cranelift.'$dylib_ext' --sysroot '$(pwd)'/build_sysroot/sysroot' # FIXME remove once the atomic shim is gone if [[ `uname` == 'Darwin' ]]; then export RUSTFLAGS="$RUSTFLAGS -Clink-arg=-undefined -Clink-arg=dynamic_lookup" fi -export LD_LIBRARY_PATH="$(pwd)/target/out:$(pwd)/build_sysroot/sysroot/lib/rustlib/$TARGET_TRIPLE/lib" +export LD_LIBRARY_PATH="$(pwd)/target/out:$(pwd)/build_sysroot/sysroot/lib/rustlib/"$TARGET_TRIPLE"/lib:\ +$(pwd)/target/"$CHANNEL":$(rustc --print sysroot)/lib" export DYLD_LIBRARY_PATH=$LD_LIBRARY_PATH export CG_CLIF_DISPLAY_CG_TIME=1 diff --git a/src/bin/cg_clif.rs b/src/bin/cg_clif.rs new file mode 100644 index 00000000000..49279f8b921 --- /dev/null +++ b/src/bin/cg_clif.rs @@ -0,0 +1,77 @@ +#![feature(rustc_private)] + +extern crate rustc_data_structures; +extern crate rustc_driver; +extern crate rustc_interface; +extern crate rustc_session; +extern crate rustc_target; + +use rustc_data_structures::profiling::print_time_passes_entry; +use rustc_interface::interface; +use rustc_session::config::ErrorOutputType; +use rustc_session::early_error; +use rustc_target::spec::PanicStrategy; + +#[derive(Default)] +pub struct TimePassesCallbacks { + time_passes: bool, +} + +impl rustc_driver::Callbacks for TimePassesCallbacks { + 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); + + // FIXME workaround for an ICE + config.opts.debugging_opts.trim_diagnostic_paths = false; + + 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() + .parent() + .unwrap() + .join("build_sysroot") + .join("sysroot"), + ); + } +} + +fn main() { + let start = std::time::Instant::now(); + rustc_driver::init_rustc_env_logger(); + let mut callbacks = TimePassesCallbacks::default(); + rustc_driver::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::>(); + rustc_driver::run_compiler( + &args, + &mut callbacks, + None, + None, + Some(Box::new(|_| { + rustc_codegen_cranelift::__rustc_codegen_backend() + })), + ) + }); + // The extra `\t` is necessary to align this label with the others. + print_time_passes_entry(callbacks.time_passes, "\ttotal", start.elapsed()); + std::process::exit(exit_code) +} diff --git a/test.sh b/test.sh index 3028f5955ed..9b61a38ffe0 100755 --- a/test.sh +++ b/test.sh @@ -2,18 +2,19 @@ set -e # Build cg_clif +export RUSTFLAGS="-Zrun_dsymutil=no" if [[ "$1" == "--release" ]]; then export CHANNEL='release' - cargo rustc --release -- -Zrun_dsymutil=no + cargo build --release else export CHANNEL='debug' - cargo rustc -- -Zrun_dsymutil=no + cargo build --bin cg_clif fi # Config source scripts/config.sh export CG_CLIF_INCR_CACHE_DISABLED=1 -RUSTC="rustc $RUSTFLAGS -L crate=target/out --out-dir target/out" +RUSTC=$RUSTC" "$RUSTFLAGS" -L crate=target/out --out-dir target/out -Cdebuginfo=2" # Cleanup rm -r target/out || true @@ -86,7 +87,7 @@ pushd simple-raytracer if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then echo "[BENCH COMPILE] ebobby/simple-raytracer" hyperfine --runs ${RUN_RUNS:-10} --warmup 1 --prepare "cargo clean" \ - "RUSTFLAGS='' cargo build" \ + "RUSTC=rustc RUSTFLAGS='' cargo build" \ "../cargo.sh build" echo "[BENCH RUN] ebobby/simple-raytracer"