1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//! The five variables bootstrap sets, supplied here so that `cargo add frontend` compiles.
//!
//! # Why a build script and not `.cargo/config.toml`
//!
//! This repository has a `.cargo/config.toml` that sets these, and it works when you build *here*.
//! It does nothing for anyone who depends on this crate: cargo reads config from the directory the
//! command was run in and its ancestors, never from a dependency's own directory. So a consumer
//! who runs `cargo add frontend` gets a compile error from `env!("CFG_RELEASE")` inside somebody
//! else's crate, with nothing to say which knob is missing.
//!
//! Two of the reads are `env!` rather than `option_env!` - `CFG_RELEASE` and `CFG_RELEASE_CHANNEL`
//! - so their absence is a hard error rather than a degraded default. Everything else rustc reads
//! is `option_env!` and copes.
//!
//! # These are defaults, and a consumer overrides them
//!
//! Every variable below is passed through unchanged if it is already set, so the local
//! `.cargo/config.toml`, an `[env]` table in a consumer's config, or an exported shell variable
//! all still win. This script only fills in what nobody supplied.
//!
//! # `CFG_VERSION` is not set here on purpose
//!
//! It decides which sysroot the built compiler can read, and it is the one that should not be
//! guessed: an older sysroot desyncs inside a serializer and a newer one fails in type checking,
//! and neither failure names the version. `rustc_interface::Config::rustc_version` sets it per
//! session instead, from the sysroot actually being used:
//!
//! ```ignore
//! config.rustc_version = rustc_interface::util::rustc_version_of_sysroot(&sysroot);
//! ```
//!
//! which asks that sysroot rather than making anyone write the string down twice. It is
//! `option_env!`, so leaving it unset is fine and the runtime value is what counts.
use env;
/// Set `key` to `value` unless the environment already has it.
///
/// `cargo::rustc-env` applies to the `rustc` invocation for this crate, which is what makes it
/// able to supply `RUSTC_BOOTSTRAP` as well as the `CFG_*` strings.