Skip to content

Commit 6768ee6

Browse files
authored
Merge pull request #601 from Nadrieril/no-pass-sysroot
Don't manage the sysroot ourselves
2 parents ec96b6b + c6989e4 commit 6768ee6

File tree

3 files changed

+12
-30
lines changed

3 files changed

+12
-30
lines changed

charon/src/bin/charon-driver/driver.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,11 @@ use rustc_driver::{Callbacks, Compilation};
99
use rustc_interface::{interface::Compiler, Queries};
1010
use std::fmt;
1111
use std::ops::Deref;
12-
use std::path::PathBuf;
1312
use std::sync::atomic::{AtomicBool, Ordering};
1413

1514
/// The callbacks for Charon
1615
pub struct CharonCallbacks {
1716
pub options: options::CliOpts,
18-
/// The root of the toolchain.
19-
pub sysroot: PathBuf,
2017
/// This is to be filled during the extraction; it contains the translated crate.
2118
transform_ctx: Option<TransformCtx>,
2219
pub error_count: usize,
@@ -46,10 +43,9 @@ impl fmt::Display for CharonFailure {
4643
}
4744

4845
impl CharonCallbacks {
49-
pub fn new(options: options::CliOpts, sysroot: PathBuf) -> Self {
46+
pub fn new(options: options::CliOpts) -> Self {
5047
Self {
5148
options,
52-
sysroot,
5349
transform_ctx: None,
5450
error_count: 0,
5551
}
@@ -141,15 +137,19 @@ impl Callbacks for CharonCallbacks {
141137
/// "built" MIR (which results from the conversion to HIR to MIR) to become unaccessible.
142138
/// Because we require built MIR at the moment, we hook ourselves before MIR-based analysis
143139
/// passes.
144-
fn after_expansion<'tcx>(&mut self, _: &Compiler, queries: &'tcx Queries<'tcx>) -> Compilation {
140+
fn after_expansion<'tcx>(
141+
&mut self,
142+
compiler: &Compiler,
143+
queries: &'tcx Queries<'tcx>,
144+
) -> Compilation {
145145
// Set up our own `DefId` debug routine.
146146
rustc_hir::def_id::DEF_ID_DEBUG
147147
.swap(&(def_id_debug as fn(_, &mut fmt::Formatter<'_>) -> _));
148148

149-
let tranform_ctx = queries.global_ctxt().unwrap().get_mut().enter(|tcx| {
150-
translate_crate_to_ullbc::translate(&self.options, tcx, self.sysroot.clone())
149+
let transform_ctx = queries.global_ctxt().unwrap().get_mut().enter(|tcx| {
150+
translate_crate_to_ullbc::translate(&self.options, tcx, compiler.sess.sysroot.clone())
151151
});
152-
self.transform_ctx = Some(tranform_ctx);
152+
self.transform_ctx = Some(transform_ctx);
153153
Compilation::Continue
154154
}
155155
fn after_analysis<'tcx>(

charon/src/bin/charon-driver/main.rs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,6 @@ fn main() {
5151
);
5252
trace!("original arguments (computed by cargo): {:?}", origin_args);
5353

54-
// Compute the sysroot (the path to the executable of the compiler):
55-
// - if it is already in the command line arguments, just retrieve it from there
56-
// - otherwise retrieve the sysroot from a call to rustc
57-
let sysroot_arg = arg_values(&origin_args, "--sysroot").next();
58-
let has_sysroot_arg = sysroot_arg.is_some();
59-
let sysroot = if has_sysroot_arg {
60-
sysroot_arg.unwrap().to_string()
61-
} else {
62-
let out = std::process::Command::new("rustc")
63-
.arg("--print=sysroot")
64-
.current_dir(".")
65-
.output()
66-
.unwrap();
67-
let sysroot = std::str::from_utf8(&out.stdout).unwrap().trim();
68-
sysroot.to_string()
69-
};
70-
7154
// Compute the compiler arguments for Rustc.
7255
// We first use all the arguments received by charon-driver, except the first two.
7356
// Rem.: the first argument is the path to the charon-driver executable.
@@ -97,9 +80,6 @@ fn main() {
9780
}
9881
};
9982

100-
if !has_sysroot_arg {
101-
compiler_args.extend(vec!["--sysroot".to_string(), sysroot.clone()]);
102-
}
10383
if options.use_polonius {
10484
compiler_args.push("-Zpolonius".to_string());
10585
}
@@ -252,7 +232,7 @@ fn main() {
252232
trace!("Compiler arguments: {:?}", compiler_args);
253233

254234
// Call the Rust compiler with our custom callback.
255-
let mut callback = CharonCallbacks::new(options, sysroot.into());
235+
let mut callback = CharonCallbacks::new(options);
256236
let mut callback_ = panic::AssertUnwindSafe(&mut callback);
257237
let res = panic::catch_unwind(move || callback_.run_compiler(compiler_args))
258238
.map_err(|_| CharonFailure::Panic)

docs/limitations.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ Tracked here: https://github.com/AeneasVerif/charon/issues/142
2323

2424
## Missing information in the translated output
2525

26+
- Bodies of functions in foreign crates often cause errors (https://github.com/AeneasVerif/charon/issues/543);
27+
- Bodies of std functions (https://github.com/AeneasVerif/charon/issues/545);
2628
- Drops (https://github.com/AeneasVerif/charon/issues/152);
2729
- Layout information (https://github.com/AeneasVerif/charon/issues/581);
2830
- Lifetime information inside function bodies (not planned).

0 commit comments

Comments
 (0)