Skip to content

Commit 5c29332

Browse files
committed
Make graphviz font configurable
Alternative to PR ##76776. To change the graphviz output to use an alternative `fontname` value, add a command line option like: `rustc --graphviz-font=monospace`.
1 parent f7aee33 commit 5c29332

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

compiler/rustc_graphviz/src/lib.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -591,14 +591,14 @@ pub trait GraphWalk<'a> {
591591
fn target(&'a self, edge: &Self::Edge) -> Self::Node;
592592
}
593593

594-
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
594+
#[derive(Clone, PartialEq, Eq, Debug)]
595595
pub enum RenderOption {
596596
NoEdgeLabels,
597597
NoNodeLabels,
598598
NoEdgeStyles,
599599
NoNodeStyles,
600600

601-
Monospace,
601+
Fontname(String),
602602
DarkTheme,
603603
}
604604

@@ -633,11 +633,14 @@ where
633633
// Global graph properties
634634
let mut graph_attrs = Vec::new();
635635
let mut content_attrs = Vec::new();
636-
if options.contains(&RenderOption::Monospace) {
637-
let font = r#"fontname="Courier, monospace""#;
638-
graph_attrs.push(font);
639-
content_attrs.push(font);
640-
};
636+
let font;
637+
if let Some(fontname) = options.iter().find_map(|option| {
638+
if let RenderOption::Fontname(fontname) = option { Some(fontname) } else { None }
639+
}) {
640+
font = format!(r#"fontname="{}""#, fontname);
641+
graph_attrs.push(&font[..]);
642+
content_attrs.push(&font[..]);
643+
}
641644
if options.contains(&RenderOption::DarkTheme) {
642645
graph_attrs.push(r#"bgcolor="black""#);
643646
content_attrs.push(r#"color="white""#);

compiler/rustc_mir/src/dataflow/framework/engine.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,8 @@ where
306306
let mut buf = Vec::new();
307307

308308
let graphviz = graphviz::Formatter::new(body, def_id, results, style);
309-
let mut render_opts = vec![dot::RenderOption::Monospace];
309+
let mut render_opts =
310+
vec![dot::RenderOption::Fontname(tcx.sess.opts.debugging_opts.graphviz_font.clone())];
310311
if tcx.sess.opts.debugging_opts.graphviz_dark_mode {
311312
render_opts.push(dot::RenderOption::DarkTheme);
312313
}

compiler/rustc_mir/src/util/graphviz.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ where
5555
writeln!(w, "{} {}Mir_{} {{", kind, cluster, def_name)?;
5656

5757
// Global graph properties
58-
let font = r#"fontname="Courier, monospace""#;
59-
let mut graph_attrs = vec![font];
60-
let mut content_attrs = vec![font];
58+
let font = format!(r#"fontname="{}""#, tcx.sess.opts.debugging_opts.graphviz_font);
59+
let mut graph_attrs = vec![&font[..]];
60+
let mut content_attrs = vec![&font[..]];
6161

6262
let dark_mode = tcx.sess.opts.debugging_opts.graphviz_dark_mode;
6363
if dark_mode {

compiler/rustc_session/src/options.rs

+2
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
909909
"set the optimization fuel quota for a crate"),
910910
graphviz_dark_mode: bool = (false, parse_bool, [UNTRACKED],
911911
"use dark-themed colors in graphviz output (default: no)"),
912+
graphviz_font: String = ("Courier, monospace".to_string(), parse_string, [UNTRACKED],
913+
"use the given `fontname` in graphviz output (default: `Courier, monospace`)"),
912914
hir_stats: bool = (false, parse_bool, [UNTRACKED],
913915
"print some statistics about AST and HIR (default: no)"),
914916
human_readable_cgu_names: bool = (false, parse_bool, [TRACKED],

0 commit comments

Comments
 (0)