Skip to content

Commit 3bf66ae

Browse files
authored
Rollup merge of #76794 - richkadel:graphviz-font, r=ecstatic-morse
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`. r? @ecstatic-morse
2 parents d3c6321 + 3875abe commit 3bf66ae

File tree

5 files changed

+22
-11
lines changed

5 files changed

+22
-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/config.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1762,6 +1762,10 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
17621762
debugging_opts.symbol_mangling_version = SymbolManglingVersion::V0;
17631763
}
17641764

1765+
if let Ok(graphviz_font) = std::env::var("RUSTC_GRAPHVIZ_FONT") {
1766+
debugging_opts.graphviz_font = graphviz_font;
1767+
}
1768+
17651769
if !cg.embed_bitcode {
17661770
match cg.lto {
17671771
LtoCli::No | LtoCli::Unspecified => {}

compiler/rustc_session/src/options.rs

+3
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,9 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
911911
"set the optimization fuel quota for a crate"),
912912
graphviz_dark_mode: bool = (false, parse_bool, [UNTRACKED],
913913
"use dark-themed colors in graphviz output (default: no)"),
914+
graphviz_font: String = ("Courier, monospace".to_string(), parse_string, [UNTRACKED],
915+
"use the given `fontname` in graphviz output; can be overridden by setting \
916+
environment variable `RUSTC_GRAPHVIZ_FONT` (default: `Courier, monospace`)"),
914917
hir_stats: bool = (false, parse_bool, [UNTRACKED],
915918
"print some statistics about AST and HIR (default: no)"),
916919
human_readable_cgu_names: bool = (false, parse_bool, [TRACKED],

0 commit comments

Comments
 (0)