summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_interface
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_interface')
-rw-r--r--compiler/rustc_interface/Cargo.toml8
-rw-r--r--compiler/rustc_interface/src/interface.rs4
-rw-r--r--compiler/rustc_interface/src/lib.rs1
-rw-r--r--compiler/rustc_interface/src/passes.rs68
-rw-r--r--compiler/rustc_interface/src/proc_macro_decls.rs15
-rw-r--r--compiler/rustc_interface/src/queries.rs41
-rw-r--r--compiler/rustc_interface/src/tests.rs3
-rw-r--r--compiler/rustc_interface/src/util.rs126
8 files changed, 80 insertions, 186 deletions
diff --git a/compiler/rustc_interface/Cargo.toml b/compiler/rustc_interface/Cargo.toml
index 6a4c5b4d3..e67dec31d 100644
--- a/compiler/rustc_interface/Cargo.toml
+++ b/compiler/rustc_interface/Cargo.toml
@@ -48,15 +48,9 @@ rustc_resolve = { path = "../rustc_resolve" }
rustc_trait_selection = { path = "../rustc_trait_selection" }
rustc_ty_utils = { path = "../rustc_ty_utils" }
-[target.'cfg(unix)'.dependencies]
-libc = "0.2"
-
-[target.'cfg(windows)'.dependencies]
-winapi = { version = "0.3", features = ["libloaderapi"] }
-
[dev-dependencies]
rustc_target = { path = "../rustc_target" }
[features]
llvm = ['rustc_codegen_llvm']
-rustc_use_parallel_compiler = ['rayon', 'rustc-rayon-core', 'rustc_query_impl/rustc_use_parallel_compiler']
+rustc_use_parallel_compiler = ['rayon', 'rustc-rayon-core', 'rustc_query_impl/rustc_use_parallel_compiler', 'rustc_errors/rustc_use_parallel_compiler']
diff --git a/compiler/rustc_interface/src/interface.rs b/compiler/rustc_interface/src/interface.rs
index 89aaa0b95..4c22ab68a 100644
--- a/compiler/rustc_interface/src/interface.rs
+++ b/compiler/rustc_interface/src/interface.rs
@@ -194,7 +194,7 @@ pub fn parse_check_cfg(specs: Vec<String>) -> CheckCfg {
for val in values {
if let Some(LitKind::Str(s, _)) =
- val.literal().map(|lit| &lit.kind)
+ val.lit().map(|lit| &lit.kind)
{
ident_values.insert(s.to_string());
} else {
@@ -304,7 +304,7 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
parse_sess_created(&mut sess.parse_sess);
}
- let temps_dir = sess.opts.unstable_opts.temps_dir.as_ref().map(|o| PathBuf::from(&o));
+ let temps_dir = sess.opts.unstable_opts.temps_dir.as_deref().map(PathBuf::from);
let compiler = Compiler {
sess: Lrc::new(sess),
diff --git a/compiler/rustc_interface/src/lib.rs b/compiler/rustc_interface/src/lib.rs
index a41a749ee..542b638bb 100644
--- a/compiler/rustc_interface/src/lib.rs
+++ b/compiler/rustc_interface/src/lib.rs
@@ -1,4 +1,5 @@
#![feature(box_patterns)]
+#![feature(decl_macro)]
#![feature(internal_output_capture)]
#![feature(thread_spawn_unchecked)]
#![feature(once_cell)]
diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs
index 7f1d21bf1..f808c1438 100644
--- a/compiler/rustc_interface/src/passes.rs
+++ b/compiler/rustc_interface/src/passes.rs
@@ -12,6 +12,7 @@ use rustc_ast::{self as ast, visit};
use rustc_borrowck as mir_borrowck;
use rustc_codegen_ssa::traits::CodegenBackend;
use rustc_data_structures::parallel;
+use rustc_data_structures::steal::Steal;
use rustc_data_structures::sync::{Lrc, OnceCell, WorkerLocal};
use rustc_errors::{ErrorGuaranteed, PResult};
use rustc_expand::base::{ExtCtxt, LintStoreExpand, ResolverExpand};
@@ -157,7 +158,7 @@ pub fn create_resolver(
sess: Lrc<Session>,
metadata_loader: Box<MetadataLoaderDyn>,
krate: &ast::Crate,
- crate_name: &str,
+ crate_name: Symbol,
) -> BoxedResolver {
trace!("create_resolver");
BoxedResolver::new(sess, move |sess, resolver_arenas| {
@@ -170,7 +171,7 @@ pub fn register_plugins<'a>(
metadata_loader: &'a dyn MetadataLoader,
register_lints: impl Fn(&Session, &mut LintStore),
mut krate: ast::Crate,
- crate_name: &str,
+ crate_name: Symbol,
) -> Result<(ast::Crate, LintStore)> {
krate = sess.time("attributes_injection", || {
rustc_builtin_macros::cmdline_attrs::inject(
@@ -207,10 +208,7 @@ pub fn register_plugins<'a>(
});
}
- let mut lint_store = rustc_lint::new_lint_store(
- sess.opts.unstable_opts.no_interleave_lints,
- sess.enable_internal_lints(),
- );
+ let mut lint_store = rustc_lint::new_lint_store(sess.enable_internal_lints());
register_lints(sess, &mut lint_store);
let registrars =
@@ -230,19 +228,21 @@ fn pre_expansion_lint<'a>(
lint_store: &LintStore,
registered_tools: &RegisteredTools,
check_node: impl EarlyCheckNode<'a>,
- node_name: &str,
+ node_name: Symbol,
) {
- sess.prof.generic_activity_with_arg("pre_AST_expansion_lint_checks", node_name).run(|| {
- rustc_lint::check_ast_node(
- sess,
- true,
- lint_store,
- registered_tools,
- None,
- rustc_lint::BuiltinCombinedPreExpansionLintPass::new(),
- check_node,
- );
- });
+ sess.prof.generic_activity_with_arg("pre_AST_expansion_lint_checks", node_name.as_str()).run(
+ || {
+ rustc_lint::check_ast_node(
+ sess,
+ true,
+ lint_store,
+ registered_tools,
+ None,
+ rustc_lint::BuiltinCombinedPreExpansionLintPass::new(),
+ check_node,
+ );
+ },
+ );
}
// Cannot implement directly for `LintStore` due to trait coherence.
@@ -256,7 +256,7 @@ impl LintStoreExpand for LintStoreExpandImpl<'_> {
node_id: ast::NodeId,
attrs: &[ast::Attribute],
items: &[rustc_ast::ptr::P<ast::Item>],
- name: &str,
+ name: Symbol,
) {
pre_expansion_lint(sess, self.0, registered_tools, (node_id, attrs, items), name);
}
@@ -270,7 +270,7 @@ pub fn configure_and_expand(
sess: &Session,
lint_store: &LintStore,
mut krate: ast::Crate,
- crate_name: &str,
+ crate_name: Symbol,
resolver: &mut Resolver<'_>,
) -> Result<ast::Crate> {
trace!("configure_and_expand");
@@ -464,7 +464,7 @@ fn generated_output_paths(
sess: &Session,
outputs: &OutputFilenames,
exact_name: bool,
- crate_name: &str,
+ crate_name: Symbol,
) -> Vec<PathBuf> {
let mut out_filenames = Vec::new();
for output_type in sess.opts.output_types.keys() {
@@ -663,7 +663,7 @@ pub fn prepare_outputs(
compiler: &Compiler,
krate: &ast::Crate,
boxed_resolver: &RefCell<BoxedResolver>,
- crate_name: &str,
+ crate_name: Symbol,
) -> Result<OutputFilenames> {
let _timer = sess.timer("prepare_outputs");
@@ -773,7 +773,7 @@ pub fn create_global_ctxt<'tcx>(
dep_graph: DepGraph,
resolver: Rc<RefCell<BoxedResolver>>,
outputs: OutputFilenames,
- crate_name: &str,
+ crate_name: Symbol,
queries: &'tcx OnceCell<TcxQueries<'tcx>>,
global_ctxt: &'tcx OnceCell<GlobalCtxt<'tcx>>,
arena: &'tcx WorkerLocal<Arena<'tcx>>,
@@ -804,6 +804,12 @@ pub fn create_global_ctxt<'tcx>(
TcxQueries::new(local_providers, extern_providers, query_result_on_disk_cache)
});
+ let ty::ResolverOutputs {
+ definitions,
+ global_ctxt: untracked_resolutions,
+ ast_lowering: untracked_resolver_for_lowering,
+ } = resolver_outputs;
+
let gcx = sess.time("setup_global_ctxt", || {
global_ctxt.get_or_init(move || {
TyCtxt::create_global_ctxt(
@@ -811,7 +817,8 @@ pub fn create_global_ctxt<'tcx>(
lint_store,
arena,
hir_arena,
- resolver_outputs,
+ definitions,
+ untracked_resolutions,
krate,
dep_graph,
queries.on_disk_cache.as_ref().map(OnDiskCache::as_dyn),
@@ -823,7 +830,12 @@ pub fn create_global_ctxt<'tcx>(
})
});
- QueryContext { gcx }
+ let mut qcx = QueryContext { gcx };
+ qcx.enter(|tcx| {
+ tcx.feed_unit_query()
+ .resolver_for_lowering(tcx.arena.alloc(Steal::new(untracked_resolver_for_lowering)))
+ });
+ qcx
}
/// Runs the resolution, type-checking, region checking and other
@@ -968,12 +980,10 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
pub fn start_codegen<'tcx>(
codegen_backend: &dyn CodegenBackend,
tcx: TyCtxt<'tcx>,
- outputs: &OutputFilenames,
) -> Box<dyn Any> {
info!("Pre-codegen\n{:?}", tcx.debug_stats());
- let (metadata, need_metadata_module) =
- rustc_metadata::fs::encode_and_write_metadata(tcx, outputs);
+ let (metadata, need_metadata_module) = rustc_metadata::fs::encode_and_write_metadata(tcx);
let codegen = tcx.sess.time("codegen_crate", move || {
codegen_backend.codegen_crate(tcx, metadata, need_metadata_module)
@@ -989,7 +999,7 @@ pub fn start_codegen<'tcx>(
info!("Post-codegen\n{:?}", tcx.debug_stats());
if tcx.sess.opts.output_types.contains_key(&OutputType::Mir) {
- if let Err(error) = rustc_mir_transform::dump_mir::emit_mir(tcx, outputs) {
+ if let Err(error) = rustc_mir_transform::dump_mir::emit_mir(tcx) {
tcx.sess.emit_err(CantEmitMIR { error });
tcx.sess.abort_if_errors();
}
diff --git a/compiler/rustc_interface/src/proc_macro_decls.rs b/compiler/rustc_interface/src/proc_macro_decls.rs
index 4c236c693..9bf7778bf 100644
--- a/compiler/rustc_interface/src/proc_macro_decls.rs
+++ b/compiler/rustc_interface/src/proc_macro_decls.rs
@@ -4,21 +4,16 @@ use rustc_middle::ty::TyCtxt;
use rustc_span::symbol::sym;
fn proc_macro_decls_static(tcx: TyCtxt<'_>, (): ()) -> Option<LocalDefId> {
- let mut finder = Finder { tcx, decls: None };
+ let mut decls = None;
for id in tcx.hir().items() {
- let attrs = finder.tcx.hir().attrs(id.hir_id());
- if finder.tcx.sess.contains_name(attrs, sym::rustc_proc_macro_decls) {
- finder.decls = Some(id.owner_id.def_id);
+ let attrs = tcx.hir().attrs(id.hir_id());
+ if tcx.sess.contains_name(attrs, sym::rustc_proc_macro_decls) {
+ decls = Some(id.owner_id.def_id);
}
}
- finder.decls
-}
-
-struct Finder<'tcx> {
- tcx: TyCtxt<'tcx>,
- decls: Option<LocalDefId>,
+ decls
}
pub(crate) fn provide(providers: &mut Providers) {
diff --git a/compiler/rustc_interface/src/queries.rs b/compiler/rustc_interface/src/queries.rs
index 91d180e1e..39e1f2204 100644
--- a/compiler/rustc_interface/src/queries.rs
+++ b/compiler/rustc_interface/src/queries.rs
@@ -17,9 +17,11 @@ use rustc_query_impl::Queries as TcxQueries;
use rustc_session::config::{self, OutputFilenames, OutputType};
use rustc_session::{output::find_crate_name, Session};
use rustc_span::symbol::sym;
+use rustc_span::Symbol;
use std::any::Any;
use std::cell::{Ref, RefCell, RefMut};
use std::rc::Rc;
+use std::sync::Arc;
/// Represent the result of a query.
///
@@ -33,11 +35,7 @@ pub struct Query<T> {
impl<T> Query<T> {
fn compute<F: FnOnce() -> Result<T>>(&self, f: F) -> Result<&Query<T>> {
- let mut result = self.result.borrow_mut();
- if result.is_none() {
- *result = Some(f());
- }
- result.as_ref().unwrap().as_ref().map(|_| self).map_err(|err| *err)
+ self.result.borrow_mut().get_or_insert_with(f).as_ref().map(|_| self).map_err(|&err| err)
}
/// Takes ownership of the query result. Further attempts to take or peek the query
@@ -77,7 +75,7 @@ pub struct Queries<'tcx> {
dep_graph_future: Query<Option<DepGraphFuture>>,
parse: Query<ast::Crate>,
- crate_name: Query<String>,
+ crate_name: Query<Symbol>,
register_plugins: Query<(ast::Crate, Lrc<LintStore>)>,
expansion: Query<(Lrc<ast::Crate>, Rc<RefCell<BoxedResolver>>, Lrc<LintStore>)>,
dep_graph: Query<DepGraph>,
@@ -138,7 +136,7 @@ impl<'tcx> Queries<'tcx> {
&*self.codegen_backend().metadata_loader(),
self.compiler.register_lints.as_deref().unwrap_or_else(|| empty),
krate,
- &crate_name,
+ crate_name,
)?;
// Compute the dependency graph (in the background). We want to do
@@ -152,7 +150,7 @@ impl<'tcx> Queries<'tcx> {
})
}
- pub fn crate_name(&self) -> Result<&Query<String>> {
+ pub fn crate_name(&self) -> Result<&Query<Symbol>> {
self.crate_name.compute(|| {
Ok({
let parse_result = self.parse()?;
@@ -168,7 +166,7 @@ impl<'tcx> Queries<'tcx> {
) -> Result<&Query<(Lrc<ast::Crate>, Rc<RefCell<BoxedResolver>>, Lrc<LintStore>)>> {
trace!("expansion");
self.expansion.compute(|| {
- let crate_name = self.crate_name()?.peek().clone();
+ let crate_name = *self.crate_name()?.peek();
let (krate, lint_store) = self.register_plugins()?.take();
let _timer = self.session().timer("configure_and_expand");
let sess = self.session();
@@ -176,10 +174,10 @@ impl<'tcx> Queries<'tcx> {
sess.clone(),
self.codegen_backend().metadata_loader(),
&krate,
- &crate_name,
+ crate_name,
);
let krate = resolver.access(|resolver| {
- passes::configure_and_expand(sess, &lint_store, krate, &crate_name, resolver)
+ passes::configure_and_expand(sess, &lint_store, krate, crate_name, resolver)
})?;
Ok((Lrc::new(krate), Rc::new(RefCell::new(resolver)), lint_store))
})
@@ -204,21 +202,21 @@ impl<'tcx> Queries<'tcx> {
pub fn prepare_outputs(&self) -> Result<&Query<OutputFilenames>> {
self.prepare_outputs.compute(|| {
let (krate, boxed_resolver, _) = &*self.expansion()?.peek();
- let crate_name = self.crate_name()?.peek();
+ let crate_name = *self.crate_name()?.peek();
passes::prepare_outputs(
self.session(),
self.compiler,
krate,
&*boxed_resolver,
- &crate_name,
+ crate_name,
)
})
}
pub fn global_ctxt(&'tcx self) -> Result<&Query<QueryContext<'tcx>>> {
self.global_ctxt.compute(|| {
- let crate_name = self.crate_name()?.peek().clone();
- let outputs = self.prepare_outputs()?.peek().clone();
+ let crate_name = *self.crate_name()?.peek();
+ let outputs = self.prepare_outputs()?.take();
let dep_graph = self.dep_graph()?.peek().clone();
let (krate, resolver, lint_store) = self.expansion()?.take();
Ok(passes::create_global_ctxt(
@@ -228,7 +226,7 @@ impl<'tcx> Queries<'tcx> {
dep_graph,
resolver,
outputs,
- &crate_name,
+ crate_name,
&self.queries,
&self.gcx,
&self.arena,
@@ -239,7 +237,6 @@ impl<'tcx> Queries<'tcx> {
pub fn ongoing_codegen(&'tcx self) -> Result<&Query<Box<dyn Any>>> {
self.ongoing_codegen.compute(|| {
- let outputs = self.prepare_outputs()?;
self.global_ctxt()?.peek_mut().enter(|tcx| {
tcx.analysis(()).ok();
@@ -253,7 +250,7 @@ impl<'tcx> Queries<'tcx> {
// Hook for UI tests.
Self::check_for_rustc_errors_attr(tcx);
- Ok(passes::start_codegen(&***self.codegen_backend(), tcx, &*outputs.peek()))
+ Ok(passes::start_codegen(&***self.codegen_backend(), tcx))
})
})
}
@@ -297,8 +294,10 @@ impl<'tcx> Queries<'tcx> {
let codegen_backend = self.codegen_backend().clone();
let dep_graph = self.dep_graph()?.peek().clone();
- let prepare_outputs = self.prepare_outputs()?.take();
- let crate_hash = self.global_ctxt()?.peek_mut().enter(|tcx| tcx.crate_hash(LOCAL_CRATE));
+ let (crate_hash, prepare_outputs) = self
+ .global_ctxt()?
+ .peek_mut()
+ .enter(|tcx| (tcx.crate_hash(LOCAL_CRATE), tcx.output_filenames(()).clone()));
let ongoing_codegen = self.ongoing_codegen()?.take();
Ok(Linker {
@@ -320,7 +319,7 @@ pub struct Linker {
// compilation outputs
dep_graph: DepGraph,
- prepare_outputs: OutputFilenames,
+ prepare_outputs: Arc<OutputFilenames>,
crate_hash: Svh,
ongoing_codegen: Box<dyn Any>,
}
diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs
index eb8e65a6d..2b8f6557c 100644
--- a/compiler/rustc_interface/src/tests.rs
+++ b/compiler/rustc_interface/src/tests.rs
@@ -666,7 +666,6 @@ fn test_unstable_options_tracking_hash() {
untracked!(mir_pretty_relative_line_numbers, true);
untracked!(nll_facts, true);
untracked!(no_analysis, true);
- untracked!(no_interleave_lints, true);
untracked!(no_leak_check, true);
untracked!(no_parallel_llvm, true);
untracked!(parse_only, true);
@@ -690,6 +689,7 @@ fn test_unstable_options_tracking_hash() {
untracked!(time_llvm_passes, true);
untracked!(time_passes, true);
untracked!(trace_macros, true);
+ untracked!(track_diagnostics, true);
untracked!(trim_diagnostic_paths, false);
untracked!(ui_testing, true);
untracked!(unpretty, Some("expanded".to_string()));
@@ -747,6 +747,7 @@ fn test_unstable_options_tracking_hash() {
tracked!(link_only, true);
tracked!(llvm_plugins, vec![String::from("plugin_name")]);
tracked!(location_detail, LocationDetail { file: true, line: false, column: false });
+ tracked!(maximal_hir_to_mir_coverage, true);
tracked!(merge_functions, Some(MergeFunctions::Disabled));
tracked!(mir_emit_retag, true);
tracked!(mir_enable_passes, vec![("DestProp".to_string(), false)]);
diff --git a/compiler/rustc_interface/src/util.rs b/compiler/rustc_interface/src/util.rs
index 519b8a7fc..4142964a0 100644
--- a/compiler/rustc_interface/src/util.rs
+++ b/compiler/rustc_interface/src/util.rs
@@ -9,6 +9,7 @@ use rustc_session as session;
use rustc_session::config::CheckCfg;
use rustc_session::config::{self, CrateType};
use rustc_session::config::{ErrorOutputType, Input, OutputFilenames};
+use rustc_session::filesearch::sysroot_candidates;
use rustc_session::lint::{self, BuiltinLintDiagnostics, LintBuffer};
use rustc_session::parse::CrateConfig;
use rustc_session::{early_error, filesearch, output, Session};
@@ -67,10 +68,7 @@ pub fn create_session(
let codegen_backend = if let Some(make_codegen_backend) = make_codegen_backend {
make_codegen_backend(&sopts)
} else {
- get_codegen_backend(
- &sopts.maybe_sysroot,
- sopts.unstable_opts.codegen_backend.as_ref().map(|name| &name[..]),
- )
+ get_codegen_backend(&sopts.maybe_sysroot, sopts.unstable_opts.codegen_backend.as_deref())
};
// target_override is documented to be called before init(), so this is okay
@@ -78,7 +76,7 @@ pub fn create_session(
let bundle = match rustc_errors::fluent_bundle(
sopts.maybe_sysroot.clone(),
- sysroot_candidates(),
+ sysroot_candidates().to_vec(),
sopts.unstable_opts.translate_lang.clone(),
sopts.unstable_opts.translate_additional_ftl.as_deref(),
sopts.unstable_opts.translate_directionality_markers,
@@ -259,7 +257,7 @@ pub fn rustc_path<'a>() -> Option<&'a Path> {
const BIN_PATH: &str = env!("RUSTC_INSTALL_BINDIR");
- RUSTC_PATH.get_or_init(|| get_rustc_path_inner(BIN_PATH)).as_ref().map(|v| &**v)
+ RUSTC_PATH.get_or_init(|| get_rustc_path_inner(BIN_PATH)).as_deref()
}
fn get_rustc_path_inner(bin_path: &str) -> Option<PathBuf> {
@@ -273,100 +271,6 @@ fn get_rustc_path_inner(bin_path: &str) -> Option<PathBuf> {
})
}
-fn sysroot_candidates() -> Vec<PathBuf> {
- let target = session::config::host_triple();
- let mut sysroot_candidates = vec![filesearch::get_or_default_sysroot()];
- let path = current_dll_path().and_then(|s| s.canonicalize().ok());
- if let Some(dll) = path {
- // use `parent` twice to chop off the file name and then also the
- // directory containing the dll which should be either `lib` or `bin`.
- if let Some(path) = dll.parent().and_then(|p| p.parent()) {
- // The original `path` pointed at the `rustc_driver` crate's dll.
- // Now that dll should only be in one of two locations. The first is
- // in the compiler's libdir, for example `$sysroot/lib/*.dll`. The
- // other is the target's libdir, for example
- // `$sysroot/lib/rustlib/$target/lib/*.dll`.
- //
- // We don't know which, so let's assume that if our `path` above
- // ends in `$target` we *could* be in the target libdir, and always
- // assume that we may be in the main libdir.
- sysroot_candidates.push(path.to_owned());
-
- if path.ends_with(target) {
- sysroot_candidates.extend(
- path.parent() // chop off `$target`
- .and_then(|p| p.parent()) // chop off `rustlib`
- .and_then(|p| p.parent()) // chop off `lib`
- .map(|s| s.to_owned()),
- );
- }
- }
- }
-
- return sysroot_candidates;
-
- #[cfg(unix)]
- fn current_dll_path() -> Option<PathBuf> {
- use std::ffi::{CStr, OsStr};
- use std::os::unix::prelude::*;
-
- unsafe {
- let addr = current_dll_path as usize as *mut _;
- let mut info = mem::zeroed();
- if libc::dladdr(addr, &mut info) == 0 {
- info!("dladdr failed");
- return None;
- }
- if info.dli_fname.is_null() {
- info!("dladdr returned null pointer");
- return None;
- }
- let bytes = CStr::from_ptr(info.dli_fname).to_bytes();
- let os = OsStr::from_bytes(bytes);
- Some(PathBuf::from(os))
- }
- }
-
- #[cfg(windows)]
- fn current_dll_path() -> Option<PathBuf> {
- use std::ffi::OsString;
- use std::io;
- use std::os::windows::prelude::*;
- use std::ptr;
-
- use winapi::um::libloaderapi::{
- GetModuleFileNameW, GetModuleHandleExW, GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
- };
-
- unsafe {
- let mut module = ptr::null_mut();
- let r = GetModuleHandleExW(
- GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
- current_dll_path as usize as *mut _,
- &mut module,
- );
- if r == 0 {
- info!("GetModuleHandleExW failed: {}", io::Error::last_os_error());
- return None;
- }
- let mut space = Vec::with_capacity(1024);
- let r = GetModuleFileNameW(module, space.as_mut_ptr(), space.capacity() as u32);
- if r == 0 {
- info!("GetModuleFileNameW failed: {}", io::Error::last_os_error());
- return None;
- }
- let r = r as usize;
- if r >= space.capacity() {
- info!("our buffer was too small? {}", io::Error::last_os_error());
- return None;
- }
- space.set_len(r);
- let os = OsString::from_wide(&space);
- Some(PathBuf::from(os))
- }
- }
-}
-
fn get_codegen_sysroot(maybe_sysroot: &Option<PathBuf>, backend_name: &str) -> MakeBackendFn {
// For now we only allow this function to be called once as it'll dlopen a
// few things, which seems to work best if we only do that once. In
@@ -420,7 +324,7 @@ fn get_codegen_sysroot(maybe_sysroot: &Option<PathBuf>, backend_name: &str) -> M
let mut file: Option<PathBuf> = None;
let expected_names = &[
- format!("rustc_codegen_{}-{}", backend_name, release_str().expect("CFG_RELEASE")),
+ format!("rustc_codegen_{}-{}", backend_name, env!("CFG_RELEASE")),
format!("rustc_codegen_{}", backend_name),
];
for entry in d.filter_map(|e| e.ok()) {
@@ -647,22 +551,12 @@ pub fn build_output_filenames(
}
}
-/// Returns a version string such as "1.46.0 (04488afe3 2020-08-24)"
-pub fn version_str() -> Option<&'static str> {
+/// Returns a version string such as "1.46.0 (04488afe3 2020-08-24)" when invoked by an in-tree tool.
+pub macro version_str() {
option_env!("CFG_VERSION")
}
-/// Returns a version string such as "0.12.0-dev".
-pub fn release_str() -> Option<&'static str> {
- option_env!("CFG_RELEASE")
-}
-
-/// Returns the full SHA1 hash of HEAD of the Git repo from which rustc was built.
-pub fn commit_hash_str() -> Option<&'static str> {
- option_env!("CFG_VER_HASH")
-}
-
-/// Returns the "commit date" of HEAD of the Git repo from which rustc was built as a static string.
-pub fn commit_date_str() -> Option<&'static str> {
- option_env!("CFG_VER_DATE")
+/// Returns the version string for `rustc` itself (which may be different from a tool version).
+pub fn rustc_version_str() -> Option<&'static str> {
+ version_str!()
}