Skip to content

Commit 7a7f599

Browse files
authored
Unrolled build for #141624
Rollup merge of #141624 - jyn514:env-var-stubs, r=BoxyUwU unstable-book: Add stubs for environment variables; document some of the important ones This uses a very hacky regex that will probably miss some variables. But having some docs seems better than none at all. In particular, this documents the following env vars explicitly (cc ````````@madsmtm```````` ````````@flba-eb```````` - do the docs for SDKROOT and QNX_TARGET look right?): - COLORTERM - QNX_TARGET - SDKROOT - TERM and generates stubs for the following env vars: - RUST_BACKTRACE - RUSTC_BLESS - RUSTC_BREAK_ON_ICE - RUSTC_CTFE_BACKTRACE - RUSTC_FORCE_RUSTC_VERSION - RUSTC_GRAPHVIZ_FONT - RUSTC_ICE - RUSTC_LOG - RUSTC_RETRY_LINKER_ON_SEGFAULT - RUSTC_TRANSLATION_NO_DEBUG_ASSERT - RUST_DEP_GRAPH_FILTER - RUST_DEP_GRAPH - RUST_FORBID_DEP_GRAPH_EDGE - RUST_MIN_STACK - RUST_TARGET_PATH - UNSTABLE_RUSTDOC_TEST_LINE - UNSTABLE_RUSTDOC_TEST_PATH rendered: ![screenshot of unstable-book running locally, with 14 environment variables shown in the sidebar](https://github.com/user-attachments/assets/8238d094-fb7a-456f-ad43-7c07aa2c44dd)
2 parents 7f7b8ef + f4d3dd0 commit 7a7f599

File tree

9 files changed

+109
-6
lines changed

9 files changed

+109
-6
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# `COLORTERM`
2+
3+
This environment variable is used by [`-Zterminal-urls`] to detect if URLs are supported by the terminal emulator.
4+
5+
[`-Zterminal-urls`]: ../compiler-flags/terminal-urls.html
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# `QNX_TARGET`
2+
3+
----
4+
5+
This environment variable is mandatory when linking on `nto-qnx*_iosock` platforms. It is used to determine an `-L` path to pass to the QNX linker.
6+
7+
You should [set this variable] by running `source qnxsdp-env.sh`.
8+
See [the QNX docs] for more background information.
9+
10+
[set this variable]: https://www.qnx.com/developers/docs/qsc/com.qnx.doc.qsc.inst_larg_org/topic/build_server_developer_steps.html
11+
[the QNX docs]: https://www.qnx.com/developers/docs/7.1/#com.qnx.doc.neutrino.io_sock/topic/migrate_app.html.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# `SDKROOT`
2+
3+
This environment variable is used on Apple targets.
4+
It is passed through to the linker (currently either as `-isysroot` or `-syslibroot`).
5+
6+
Note that this variable is not always respected. When the SDKROOT is clearly wrong (e.g. when the platform of the SDK does not match the `--target` used by rustc), this is ignored and rustc does its own detection.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# `TERM`
2+
3+
This environment variable is used by [`-Zterminal-urls`] to detect if URLs are supported by the terminal emulator.
4+
5+
[`-Zterminal-urls`]: ../compiler-flags/terminal-urls.html
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# `-Z terminal-urls`
2+
3+
The tracking feature for this issue is [#125586]
4+
5+
[#125586]: https://github.com/rust-lang/rust/issues/125586
6+
7+
---
8+
9+
This flag takes either a boolean or the string "auto".
10+
11+
When enabled, use the OSC 8 hyperlink terminal specification to print hyperlinks in the compiler output.
12+
Use "auto" to try and autodetect whether the terminal emulator supports hyperlinks.
13+
Currently, "auto" only enables hyperlinks if `COLORTERM=truecolor` and `TERM=xterm-256color`.

src/tools/tidy/src/features.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
//! * All unstable lang features have tests to ensure they are actually unstable.
1010
//! * Language features in a group are sorted by feature name.
1111
12+
use std::collections::BTreeSet;
1213
use std::collections::hash_map::{Entry, HashMap};
1314
use std::ffi::OsStr;
1415
use std::num::NonZeroU32;
@@ -21,6 +22,7 @@ use crate::walk::{filter_dirs, filter_not_rust, walk, walk_many};
2122
mod tests;
2223

2324
mod version;
25+
use regex::Regex;
2426
use version::Version;
2527

2628
const FEATURE_GROUP_START_PREFIX: &str = "// feature-group-start";
@@ -623,3 +625,36 @@ fn map_lib_features(
623625
},
624626
);
625627
}
628+
629+
fn should_document(var: &str) -> bool {
630+
if var.starts_with("RUSTC_") || var.starts_with("RUST_") || var.starts_with("UNSTABLE_RUSTDOC_")
631+
{
632+
return true;
633+
}
634+
["SDKROOT", "QNX_TARGET", "COLORTERM", "TERM"].contains(&var)
635+
}
636+
637+
pub fn collect_env_vars(compiler: &Path) -> BTreeSet<String> {
638+
let env_var_regex: Regex = Regex::new(r#"env::var(_os)?\("([^"]+)"#).unwrap();
639+
640+
let mut vars = BTreeSet::new();
641+
walk(
642+
compiler,
643+
// skip build scripts, tests, and non-rust files
644+
|path, _is_dir| {
645+
filter_dirs(path)
646+
|| filter_not_rust(path)
647+
|| path.ends_with("build.rs")
648+
|| path.ends_with("tests.rs")
649+
},
650+
&mut |_entry, contents| {
651+
for env_var in env_var_regex.captures_iter(contents).map(|c| c.get(2).unwrap().as_str())
652+
{
653+
if should_document(env_var) {
654+
vars.insert(env_var.to_owned());
655+
}
656+
}
657+
},
658+
);
659+
vars
660+
}

src/tools/tidy/src/unstable_book.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ use crate::features::{CollectedFeatures, Features, Status};
66

77
pub const PATH_STR: &str = "doc/unstable-book";
88

9+
pub const ENV_VARS_DIR: &str = "src/compiler-environment-variables";
10+
911
pub const COMPILER_FLAGS_DIR: &str = "src/compiler-flags";
1012

1113
pub const LANG_FEATURES_DIR: &str = "src/language-features";

src/tools/unstable-book-gen/src/main.rs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ use std::env;
55
use std::fs::{self, write};
66
use std::path::Path;
77

8-
use tidy::features::{Features, collect_lang_features, collect_lib_features};
8+
use tidy::features::{Features, collect_env_vars, collect_lang_features, collect_lib_features};
99
use tidy::t;
1010
use tidy::unstable_book::{
11-
LANG_FEATURES_DIR, LIB_FEATURES_DIR, PATH_STR, collect_unstable_book_section_file_names,
12-
collect_unstable_feature_names,
11+
ENV_VARS_DIR, LANG_FEATURES_DIR, LIB_FEATURES_DIR, PATH_STR,
12+
collect_unstable_book_section_file_names, collect_unstable_feature_names,
1313
};
1414

1515
fn generate_stub_issue(path: &Path, name: &str, issue: u32, description: &str) {
@@ -27,6 +27,11 @@ fn generate_stub_no_issue(path: &Path, name: &str, description: &str) {
2727
t!(write(path, content), path);
2828
}
2929

30+
fn generate_stub_env_var(path: &Path, name: &str) {
31+
let content = format!(include_str!("stub-env-var.md"), name = name);
32+
t!(write(path, content), path);
33+
}
34+
3035
fn set_to_summary_str(set: &BTreeSet<String>, dir: &str) -> String {
3136
set.iter()
3237
.map(|ref n| format!(" - [{}]({}/{}.md)", n.replace('-', "_"), dir, n))
@@ -59,7 +64,7 @@ fn generate_summary(path: &Path, lang_features: &Features, lib_features: &Featur
5964
t!(write(&summary_path, content), summary_path);
6065
}
6166

62-
fn generate_unstable_book_files(src: &Path, out: &Path, features: &Features) {
67+
fn generate_feature_files(src: &Path, out: &Path, features: &Features) {
6368
let unstable_features = collect_unstable_feature_names(features);
6469
let unstable_section_file_names = collect_unstable_book_section_file_names(src);
6570
t!(fs::create_dir_all(&out));
@@ -83,6 +88,16 @@ fn generate_unstable_book_files(src: &Path, out: &Path, features: &Features) {
8388
}
8489
}
8590

91+
fn generate_env_files(src: &Path, out: &Path, env_vars: &BTreeSet<String>) {
92+
let env_var_file_names = collect_unstable_book_section_file_names(src);
93+
t!(fs::create_dir_all(&out));
94+
for env_var in env_vars - &env_var_file_names {
95+
let file_name = format!("{env_var}.md");
96+
let out_file_path = out.join(&file_name);
97+
generate_stub_env_var(&out_file_path, &env_var);
98+
}
99+
}
100+
86101
fn copy_recursive(from: &Path, to: &Path) {
87102
for entry in t!(fs::read_dir(from)) {
88103
let e = t!(entry);
@@ -112,21 +127,23 @@ fn main() {
112127
.into_iter()
113128
.filter(|&(ref name, _)| !lang_features.contains_key(name))
114129
.collect();
130+
let env_vars = collect_env_vars(compiler_path);
115131

116132
let doc_src_path = src_path.join(PATH_STR);
117133

118134
t!(fs::create_dir_all(&dest_path));
119135

120-
generate_unstable_book_files(
136+
generate_feature_files(
121137
&doc_src_path.join(LANG_FEATURES_DIR),
122138
&dest_path.join(LANG_FEATURES_DIR),
123139
&lang_features,
124140
);
125-
generate_unstable_book_files(
141+
generate_feature_files(
126142
&doc_src_path.join(LIB_FEATURES_DIR),
127143
&dest_path.join(LIB_FEATURES_DIR),
128144
&lib_features,
129145
);
146+
generate_env_files(&doc_src_path.join(ENV_VARS_DIR), &dest_path.join(ENV_VARS_DIR), &env_vars);
130147

131148
copy_recursive(&doc_src_path, &dest_path);
132149

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# `{name}`
2+
3+
Environment variables have no tracking issue. This environment variable has no documentation, and therefore is likely internal to the compiler and not meant for general use.
4+
5+
See [the code][github search] for more information.
6+
7+
[github search]: https://github.com/search?q=repo%3Arust-lang%2Frust+%22{name}%22+path%3Acompiler&type=code
8+
9+
------------------------

0 commit comments

Comments
 (0)