Add custom driver

This commit is contained in:
bjorn3 2020-09-29 14:43:34 +02:00
parent c046ad017f
commit 17a54ad62e
3 changed files with 88 additions and 7 deletions

View File

@ -32,15 +32,18 @@ if [[ "$HOST_TRIPLE" != "$TARGET_TRIPLE" ]]; then
fi fi
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 RUSTC=$(pwd)/"target/"$CHANNEL"/cg_clif"
export RUSTDOCFLAGS=$RUSTFLAGS 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 # FIXME remove once the atomic shim is gone
if [[ `uname` == 'Darwin' ]]; then if [[ `uname` == 'Darwin' ]]; then
export RUSTFLAGS="$RUSTFLAGS -Clink-arg=-undefined -Clink-arg=dynamic_lookup" export RUSTFLAGS="$RUSTFLAGS -Clink-arg=-undefined -Clink-arg=dynamic_lookup"
fi 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 DYLD_LIBRARY_PATH=$LD_LIBRARY_PATH
export CG_CLIF_DISPLAY_CG_TIME=1 export CG_CLIF_DISPLAY_CG_TIME=1

77
src/bin/cg_clif.rs Normal file
View File

@ -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::<Vec<_>>();
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)
}

View File

@ -2,18 +2,19 @@
set -e set -e
# Build cg_clif # Build cg_clif
export RUSTFLAGS="-Zrun_dsymutil=no"
if [[ "$1" == "--release" ]]; then if [[ "$1" == "--release" ]]; then
export CHANNEL='release' export CHANNEL='release'
cargo rustc --release -- -Zrun_dsymutil=no cargo build --release
else else
export CHANNEL='debug' export CHANNEL='debug'
cargo rustc -- -Zrun_dsymutil=no cargo build --bin cg_clif
fi fi
# Config # Config
source scripts/config.sh source scripts/config.sh
export CG_CLIF_INCR_CACHE_DISABLED=1 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 # Cleanup
rm -r target/out || true rm -r target/out || true
@ -86,7 +87,7 @@ pushd simple-raytracer
if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then
echo "[BENCH COMPILE] ebobby/simple-raytracer" echo "[BENCH COMPILE] ebobby/simple-raytracer"
hyperfine --runs ${RUN_RUNS:-10} --warmup 1 --prepare "cargo clean" \ hyperfine --runs ${RUN_RUNS:-10} --warmup 1 --prepare "cargo clean" \
"RUSTFLAGS='' cargo build" \ "RUSTC=rustc RUSTFLAGS='' cargo build" \
"../cargo.sh build" "../cargo.sh build"
echo "[BENCH RUN] ebobby/simple-raytracer" echo "[BENCH RUN] ebobby/simple-raytracer"