Skip to content

Commit 0404788

Browse files
authored
Rollup merge of #73317 - davidtwco:bootstrap-config-env-var, r=Mark-Simulacrum
bootstrap: read config from $RUST_BOOTSTRAP_CONFIG This PR modifies bootstrap so that `config.toml` is read first from `RUST_BOOTSTRAP_CONFIG`, then `--config` and finally `config.toml` in the current directory. This is a subjective change, intended to improve the ergnomics when using "development shells" for rustc development (for example, using tools such as Nix) which set environment variables to ensure a reproducible environment (these development shells can then be version controlled, e.g. [my rustc shell](https://github.com/davidtwco/veritas/blob/6b74a5c170b6efb2c7b094352932f9158f97eec0/nix/shells/rustc.nix)). By optionally reading `config.toml` from an environment variable, a `config.toml` can be defined in the development shell and a path to it exposed in the `RUST_BOOTSTRAP_CONFIG` environment variable - avoiding the need to manually symlink the contents of this file to `config.toml` in the working directory.
2 parents 45aa36b + 93022be commit 0404788

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

src/bootstrap/bootstrap.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ def bootstrap(help_triggered):
894894
build.clean = args.clean
895895

896896
try:
897-
toml_path = args.config or 'config.toml'
897+
toml_path = os.getenv('RUST_BOOTSTRAP_CONFIG') or args.config or 'config.toml'
898898
if not os.path.exists(toml_path):
899899
toml_path = os.path.join(build.rust_root, toml_path)
900900

@@ -947,6 +947,7 @@ def bootstrap(help_triggered):
947947
env["SRC"] = build.rust_root
948948
env["BOOTSTRAP_PARENT_ID"] = str(os.getpid())
949949
env["BOOTSTRAP_PYTHON"] = sys.executable
950+
env["BOOTSTRAP_CONFIG"] = toml_path
950951
env["BUILD_DIR"] = build.build_dir
951952
env["RUSTC_BOOTSTRAP"] = '1'
952953
env["CARGO"] = build.cargo()

src/bootstrap/flags.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! This module implements the command-line parsing of the build system which
44
//! has various flags to configure how it's run.
55
6-
use std::fs;
6+
use std::env;
77
use std::path::PathBuf;
88
use std::process;
99

@@ -438,13 +438,7 @@ Arguments:
438438
// Get any optional paths which occur after the subcommand
439439
let paths = matches.free[1..].iter().map(|p| p.into()).collect::<Vec<PathBuf>>();
440440

441-
let cfg_file = matches.opt_str("config").map(PathBuf::from).or_else(|| {
442-
if fs::metadata("config.toml").is_ok() {
443-
Some(PathBuf::from("config.toml"))
444-
} else {
445-
None
446-
}
447-
});
441+
let cfg_file = env::var_os("BOOTSTRAP_CONFIG").map(PathBuf::from);
448442

449443
// All subcommands except `clean` can have an optional "Available paths" section
450444
if matches.opt_present("verbose") {

0 commit comments

Comments
 (0)