Skip to content

Commit 17a54ad

Browse files
committed
Add custom driver
1 parent c046ad0 commit 17a54ad

File tree

3 files changed

+88
-7
lines changed

3 files changed

+88
-7
lines changed

scripts/config.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,18 @@ if [[ "$HOST_TRIPLE" != "$TARGET_TRIPLE" ]]; then
3232
fi
3333
fi
3434

35-
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'
36-
export RUSTDOCFLAGS=$RUSTFLAGS
35+
export RUSTC=$(pwd)/"target/"$CHANNEL"/cg_clif"
36+
export RUSTFLAGS=$linker
37+
export RUSTDOCFLAGS=$linker' -Ztrim-diagnostic-paths=no -Cpanic=abort -Zpanic-abort-tests '\
38+
'-Zcodegen-backend='$(pwd)'/target/'$CHANNEL'/librustc_codegen_cranelift.'$dylib_ext' --sysroot '$(pwd)'/build_sysroot/sysroot'
3739

3840
# FIXME remove once the atomic shim is gone
3941
if [[ `uname` == 'Darwin' ]]; then
4042
export RUSTFLAGS="$RUSTFLAGS -Clink-arg=-undefined -Clink-arg=dynamic_lookup"
4143
fi
4244

43-
export LD_LIBRARY_PATH="$(pwd)/target/out:$(pwd)/build_sysroot/sysroot/lib/rustlib/$TARGET_TRIPLE/lib"
45+
export LD_LIBRARY_PATH="$(pwd)/target/out:$(pwd)/build_sysroot/sysroot/lib/rustlib/"$TARGET_TRIPLE"/lib:\
46+
$(pwd)/target/"$CHANNEL":$(rustc --print sysroot)/lib"
4447
export DYLD_LIBRARY_PATH=$LD_LIBRARY_PATH
4548

4649
export CG_CLIF_DISPLAY_CG_TIME=1

src/bin/cg_clif.rs

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#![feature(rustc_private)]
2+
3+
extern crate rustc_data_structures;
4+
extern crate rustc_driver;
5+
extern crate rustc_interface;
6+
extern crate rustc_session;
7+
extern crate rustc_target;
8+
9+
use rustc_data_structures::profiling::print_time_passes_entry;
10+
use rustc_interface::interface;
11+
use rustc_session::config::ErrorOutputType;
12+
use rustc_session::early_error;
13+
use rustc_target::spec::PanicStrategy;
14+
15+
#[derive(Default)]
16+
pub struct TimePassesCallbacks {
17+
time_passes: bool,
18+
}
19+
20+
impl rustc_driver::Callbacks for TimePassesCallbacks {
21+
fn config(&mut self, config: &mut interface::Config) {
22+
// If a --prints=... option has been given, we don't print the "total"
23+
// time because it will mess up the --prints output. See #64339.
24+
self.time_passes = config.opts.prints.is_empty()
25+
&& (config.opts.debugging_opts.time_passes || config.opts.debugging_opts.time);
26+
27+
// FIXME workaround for an ICE
28+
config.opts.debugging_opts.trim_diagnostic_paths = false;
29+
30+
config.opts.cg.panic = Some(PanicStrategy::Abort);
31+
config.opts.debugging_opts.panic_abort_tests = true;
32+
config.opts.maybe_sysroot = Some(
33+
std::env::current_exe()
34+
.unwrap()
35+
.parent()
36+
.unwrap()
37+
.parent()
38+
.unwrap()
39+
.parent()
40+
.unwrap()
41+
.join("build_sysroot")
42+
.join("sysroot"),
43+
);
44+
}
45+
}
46+
47+
fn main() {
48+
let start = std::time::Instant::now();
49+
rustc_driver::init_rustc_env_logger();
50+
let mut callbacks = TimePassesCallbacks::default();
51+
rustc_driver::install_ice_hook();
52+
let exit_code = rustc_driver::catch_with_exit_code(|| {
53+
let args = std::env::args_os()
54+
.enumerate()
55+
.map(|(i, arg)| {
56+
arg.into_string().unwrap_or_else(|arg| {
57+
early_error(
58+
ErrorOutputType::default(),
59+
&format!("Argument {} is not valid Unicode: {:?}", i, arg),
60+
)
61+
})
62+
})
63+
.collect::<Vec<_>>();
64+
rustc_driver::run_compiler(
65+
&args,
66+
&mut callbacks,
67+
None,
68+
None,
69+
Some(Box::new(|_| {
70+
rustc_codegen_cranelift::__rustc_codegen_backend()
71+
})),
72+
)
73+
});
74+
// The extra `\t` is necessary to align this label with the others.
75+
print_time_passes_entry(callbacks.time_passes, "\ttotal", start.elapsed());
76+
std::process::exit(exit_code)
77+
}

test.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22
set -e
33

44
# Build cg_clif
5+
export RUSTFLAGS="-Zrun_dsymutil=no"
56
if [[ "$1" == "--release" ]]; then
67
export CHANNEL='release'
7-
cargo rustc --release -- -Zrun_dsymutil=no
8+
cargo build --release
89
else
910
export CHANNEL='debug'
10-
cargo rustc -- -Zrun_dsymutil=no
11+
cargo build --bin cg_clif
1112
fi
1213

1314
# Config
1415
source scripts/config.sh
1516
export CG_CLIF_INCR_CACHE_DISABLED=1
16-
RUSTC="rustc $RUSTFLAGS -L crate=target/out --out-dir target/out"
17+
RUSTC=$RUSTC" "$RUSTFLAGS" -L crate=target/out --out-dir target/out -Cdebuginfo=2"
1718

1819
# Cleanup
1920
rm -r target/out || true
@@ -86,7 +87,7 @@ pushd simple-raytracer
8687
if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then
8788
echo "[BENCH COMPILE] ebobby/simple-raytracer"
8889
hyperfine --runs ${RUN_RUNS:-10} --warmup 1 --prepare "cargo clean" \
89-
"RUSTFLAGS='' cargo build" \
90+
"RUSTC=rustc RUSTFLAGS='' cargo build" \
9091
"../cargo.sh build"
9192

9293
echo "[BENCH RUN] ebobby/simple-raytracer"

0 commit comments

Comments
 (0)