Skip to content

Commit 7d3b293

Browse files
committed
Use sess.cfg_version instead of rustc_version_str()
This makes it easier to patch cg_clif to be statically linked as part of rustc.
1 parent 24361a1 commit 7d3b293

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

src/debuginfo/mod.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,14 @@ use gimli::write::{
1313
};
1414
use gimli::{Encoding, Format, LineEncoding, RunTimeEndian};
1515
use indexmap::IndexSet;
16+
use rustc_session::Session;
1617

1718
pub(crate) use self::emit::{DebugReloc, DebugRelocName};
1819
pub(crate) use self::unwind::UnwindContext;
1920
use crate::prelude::*;
2021

21-
pub(crate) fn producer() -> String {
22-
format!(
23-
"rustc version {} with cranelift {}",
24-
rustc_interface::util::rustc_version_str().unwrap_or("unknown version"),
25-
cranelift_codegen::VERSION,
26-
)
22+
pub(crate) fn producer(sess: &Session) -> String {
23+
format!("rustc version {} with cranelift {}", sess.cfg_version, cranelift_codegen::VERSION)
2724
}
2825

2926
pub(crate) struct DebugContext {
@@ -67,7 +64,7 @@ impl DebugContext {
6764

6865
let should_remap_filepaths = tcx.sess.should_prefer_remapped_for_codegen();
6966

70-
let producer = producer();
67+
let producer = producer(tcx.sess);
7168
let comp_dir = tcx
7269
.sess
7370
.opts

src/driver/aot.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ fn emit_cgu(
143143
debug: Option<DebugContext>,
144144
unwind_context: UnwindContext,
145145
global_asm_object_file: Option<PathBuf>,
146+
producer: &str,
146147
) -> Result<ModuleCodegenResult, String> {
147148
let mut product = module.finish();
148149

@@ -152,8 +153,14 @@ fn emit_cgu(
152153

153154
unwind_context.emit(&mut product);
154155

155-
let module_regular =
156-
emit_module(output_filenames, prof, product.object, ModuleKind::Regular, name.clone())?;
156+
let module_regular = emit_module(
157+
output_filenames,
158+
prof,
159+
product.object,
160+
ModuleKind::Regular,
161+
name.clone(),
162+
producer,
163+
)?;
157164

158165
Ok(ModuleCodegenResult {
159166
module_regular,
@@ -174,6 +181,7 @@ fn emit_module(
174181
mut object: cranelift_object::object::write::Object<'_>,
175182
kind: ModuleKind,
176183
name: String,
184+
producer_str: &str,
177185
) -> Result<CompiledModule, String> {
178186
if object.format() == cranelift_object::object::BinaryFormat::Elf {
179187
let comment_section = object.add_section(
@@ -182,7 +190,7 @@ fn emit_module(
182190
cranelift_object::object::SectionKind::OtherString,
183191
);
184192
let mut producer = vec![0];
185-
producer.extend(crate::debuginfo::producer().as_bytes());
193+
producer.extend(producer_str.as_bytes());
186194
producer.push(0);
187195
object.set_section_data(comment_section, producer, 1);
188196
}
@@ -321,6 +329,8 @@ fn module_codegen(
321329
(cgu_name, cx, module, codegened_functions)
322330
});
323331

332+
let producer = crate::debuginfo::producer(tcx.sess);
333+
324334
OngoingModuleCodegen::Async(std::thread::spawn(move || {
325335
cx.profiler.clone().generic_activity_with_arg("compile functions", &*cgu_name).run(|| {
326336
cranelift_codegen::timing::set_thread_profiler(Box::new(super::MeasuremeProfiler(
@@ -348,6 +358,7 @@ fn module_codegen(
348358
cx.debug_context,
349359
cx.unwind_context,
350360
global_asm_object_file,
361+
&producer,
351362
)
352363
});
353364
std::mem::drop(token);
@@ -453,6 +464,7 @@ pub(crate) fn run_aot(
453464
product.object,
454465
ModuleKind::Allocator,
455466
"allocator_shim".to_owned(),
467+
&crate::debuginfo::producer(tcx.sess),
456468
) {
457469
Ok(allocator_module) => Some(allocator_module),
458470
Err(err) => tcx.dcx().fatal(err),

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ extern crate rustc_fs_util;
1818
extern crate rustc_hir;
1919
extern crate rustc_incremental;
2020
extern crate rustc_index;
21-
extern crate rustc_interface;
2221
extern crate rustc_metadata;
2322
extern crate rustc_session;
2423
extern crate rustc_span;

0 commit comments

Comments
 (0)