Skip to content

unstable-book: Add stubs for environment variables; document some of the important ones #141624

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# `COLORTERM`

This environment variable is used by [`-Zterminal-urls`] to detect if URLs are supported by the terminal emulator.

[`-Zterminal-urls`]: ../compiler-flags/terminal-urls.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# `QNX_TARGET`

----

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.

You should [set this variable] by running `source qnxsdp-env.sh`.
See [the QNX docs] for more background information.

[set this variable]: https://www.qnx.com/developers/docs/qsc/com.qnx.doc.qsc.inst_larg_org/topic/build_server_developer_steps.html
[the QNX docs]: https://www.qnx.com/developers/docs/7.1/index.html#com.qnx.doc.neutrino.io_sock/topic/migrate_app.html.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# `SDKROOT`

This environment variable is used on MacOS targets.
It is passed through to the linker (either as `-isysroot` or `-syslibroot`) without changes.

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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# `TERM`

This environment variable is used by [`-Zterminal-urls`] to detect if URLs are supported by the terminal emulator.

[`-Zterminal-urls`]: ../compiler-flags/terminal-urls.html
13 changes: 13 additions & 0 deletions src/doc/unstable-book/src/compiler-flags/terminal-urls.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# `-Z terminal-urls`

The tracking feature for this issue is [#125586]

[#125586]: https://github.com/rust-lang/rust/issues/125586

---

This flag takes either a boolean or the string "auto".

When enabled, use the OSC 8 hyperlink terminal specification to print hyperlinks in the compiler output.
Use "auto" to try and autodetect whether the terminal emulator supports hyperlinks.
Currently, "auto" only enables hyperlinks if `COLORTERM=truecolor` and `TERM=xterm-256color`.
35 changes: 35 additions & 0 deletions src/tools/tidy/src/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
//! * All unstable lang features have tests to ensure they are actually unstable.
//! * Language features in a group are sorted by feature name.

use std::collections::BTreeSet;
use std::collections::hash_map::{Entry, HashMap};
use std::ffi::OsStr;
use std::num::NonZeroU32;
Expand All @@ -21,6 +22,7 @@ use crate::walk::{filter_dirs, filter_not_rust, walk, walk_many};
mod tests;

mod version;
use regex::Regex;
use version::Version;

const FEATURE_GROUP_START_PREFIX: &str = "// feature-group-start";
Expand Down Expand Up @@ -610,3 +612,36 @@ fn map_lib_features(
},
);
}

fn should_document(var: &str) -> bool {
if var.starts_with("RUSTC_") || var.starts_with("RUST_") || var.starts_with("UNSTABLE_RUSTDOC_")
{
return true;
}
["SDKROOT", "QNX_TARGET", "COLORTERM", "TERM"].contains(&var)
}

pub fn collect_env_vars(compiler: &Path) -> BTreeSet<String> {
let env_var_regex: Regex = Regex::new(r#"env::var(_os)?\("([^"]+)"#).unwrap();

let mut vars = BTreeSet::new();
walk(
compiler,
// skip build scripts, tests, and non-rust files
|path, _is_dir| {
filter_dirs(path)
|| filter_not_rust(path)
|| path.ends_with("build.rs")
|| path.ends_with("tests.rs")
},
&mut |_entry, contents| {
for env_var in env_var_regex.captures_iter(contents).map(|c| c.get(2).unwrap().as_str())
{
if should_document(env_var) {
vars.insert(env_var.to_owned());
}
}
},
);
vars
}
2 changes: 2 additions & 0 deletions src/tools/tidy/src/unstable_book.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use crate::features::{CollectedFeatures, Features, Status};

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

pub const ENV_VARS_DIR: &str = "src/compiler-environment-variables";

pub const COMPILER_FLAGS_DIR: &str = "src/compiler-flags";

pub const LANG_FEATURES_DIR: &str = "src/language-features";
Expand Down
29 changes: 23 additions & 6 deletions src/tools/unstable-book-gen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ use std::env;
use std::fs::{self, write};
use std::path::Path;

use tidy::features::{Features, collect_lang_features, collect_lib_features};
use tidy::features::{Features, collect_env_vars, collect_lang_features, collect_lib_features};
use tidy::t;
use tidy::unstable_book::{
LANG_FEATURES_DIR, LIB_FEATURES_DIR, PATH_STR, collect_unstable_book_section_file_names,
collect_unstable_feature_names,
ENV_VARS_DIR, LANG_FEATURES_DIR, LIB_FEATURES_DIR, PATH_STR,
collect_unstable_book_section_file_names, collect_unstable_feature_names,
};

fn generate_stub_issue(path: &Path, name: &str, issue: u32) {
Expand All @@ -22,6 +22,11 @@ fn generate_stub_no_issue(path: &Path, name: &str) {
t!(write(path, content), path);
}

fn generate_stub_env_var(path: &Path, name: &str) {
let content = format!(include_str!("stub-env-var.md"), name = name);
t!(write(path, content), path);
}

fn set_to_summary_str(set: &BTreeSet<String>, dir: &str) -> String {
set.iter()
.map(|ref n| format!(" - [{}]({}/{}.md)", n.replace('-', "_"), dir, n))
Expand Down Expand Up @@ -54,7 +59,7 @@ fn generate_summary(path: &Path, lang_features: &Features, lib_features: &Featur
t!(write(&summary_path, content), summary_path);
}

fn generate_unstable_book_files(src: &Path, out: &Path, features: &Features) {
fn generate_feature_files(src: &Path, out: &Path, features: &Features) {
let unstable_features = collect_unstable_feature_names(features);
let unstable_section_file_names = collect_unstable_book_section_file_names(src);
t!(fs::create_dir_all(&out));
Expand All @@ -72,6 +77,16 @@ fn generate_unstable_book_files(src: &Path, out: &Path, features: &Features) {
}
}

fn generate_env_files(src: &Path, out: &Path, env_vars: &BTreeSet<String>) {
let env_var_file_names = collect_unstable_book_section_file_names(src);
t!(fs::create_dir_all(&out));
for env_var in env_vars - &env_var_file_names {
let file_name = format!("{env_var}.md");
let out_file_path = out.join(&file_name);
generate_stub_env_var(&out_file_path, &env_var);
}
}

fn copy_recursive(from: &Path, to: &Path) {
for entry in t!(fs::read_dir(from)) {
let e = t!(entry);
Expand Down Expand Up @@ -101,21 +116,23 @@ fn main() {
.into_iter()
.filter(|&(ref name, _)| !lang_features.contains_key(name))
.collect();
let env_vars = collect_env_vars(compiler_path);

let doc_src_path = src_path.join(PATH_STR);

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

generate_unstable_book_files(
generate_feature_files(
&doc_src_path.join(LANG_FEATURES_DIR),
&dest_path.join(LANG_FEATURES_DIR),
&lang_features,
);
generate_unstable_book_files(
generate_feature_files(
&doc_src_path.join(LIB_FEATURES_DIR),
&dest_path.join(LIB_FEATURES_DIR),
&lib_features,
);
generate_env_files(&doc_src_path.join(ENV_VARS_DIR), &dest_path.join(ENV_VARS_DIR), &env_vars);

copy_recursive(&doc_src_path, &dest_path);

Expand Down
9 changes: 9 additions & 0 deletions src/tools/unstable-book-gen/src/stub-env-var.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# `{name}`

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.

See [the code][github search] for more information.

[github search]: https://github.com/search?q=repo%3Arust-lang%2Frust+%22{name}%22+path%3Acompiler&type=code

------------------------
Loading