Skip to content

Commit 240f288

Browse files
jyn514Mark-Simulacrum
authored andcommitted
Move some more bootstrap logic from python to rust
Same rationale as rust-lang#76544; it would be nice to make python entirely optional at some point. This also removes $ROOT as an option for the build directory; I haven't been using it, and like Alex said in rust-lang#76544 (comment) it seems like a misfeature. This allows running `cargo run` from src/bootstrap, although that still gives lots of compile errors if you don't use the beta toolchain.
1 parent 03918ba commit 240f288

File tree

3 files changed

+16
-23
lines changed

3 files changed

+16
-23
lines changed

src/bootstrap/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name = "bootstrap"
33
version = "0.0.0"
44
edition = "2021"
55
build = "build.rs"
6+
default-run = "bootstrap"
67

78
[lib]
89
path = "lib.rs"

src/bootstrap/bootstrap.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1267,7 +1267,7 @@ def bootstrap(help_triggered):
12671267
build.check_vendored_status()
12681268

12691269
build_dir = build.get_toml('build-dir', 'build') or 'build'
1270-
build.build_dir = os.path.abspath(build_dir.replace("$ROOT", build.rust_root))
1270+
build.build_dir = os.path.abspath(build_dir)
12711271

12721272
with open(os.path.join(build.rust_root, "src", "stage0.json")) as f:
12731273
data = json.load(f)
@@ -1302,7 +1302,6 @@ def bootstrap(help_triggered):
13021302
env = os.environ.copy()
13031303
env["BOOTSTRAP_PARENT_ID"] = str(os.getpid())
13041304
env["BOOTSTRAP_PYTHON"] = sys.executable
1305-
env["BUILD_DIR"] = build.build_dir
13061305
env["RUSTC_BOOTSTRAP"] = '1'
13071306
if toml_path:
13081307
env["BOOTSTRAP_CONFIG"] = toml_path

src/bootstrap/config.rs

+14-21
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use std::cmp;
77
use std::collections::{HashMap, HashSet};
88
use std::env;
9-
use std::ffi::OsString;
109
use std::fmt;
1110
use std::fs;
1211
use std::path::{Path, PathBuf};
@@ -392,7 +391,6 @@ derive_merge! {
392391
build: Option<String>,
393392
host: Option<Vec<String>>,
394393
target: Option<Vec<String>>,
395-
// This is ignored, the rust code always gets the build directory from the `BUILD_DIR` env variable
396394
build_dir: Option<String>,
397395
cargo: Option<String>,
398396
rustc: Option<String>,
@@ -588,18 +586,6 @@ derive_merge! {
588586
}
589587

590588
impl Config {
591-
fn path_from_python(var_key: &str) -> PathBuf {
592-
match env::var_os(var_key) {
593-
Some(var_val) => Self::normalize_python_path(var_val),
594-
_ => panic!("expected '{}' to be set", var_key),
595-
}
596-
}
597-
598-
/// Normalizes paths from Python slightly. We don't trust paths from Python (#49785).
599-
fn normalize_python_path(path: OsString) -> PathBuf {
600-
Path::new(&path).components().collect()
601-
}
602-
603589
pub fn default_opts() -> Config {
604590
let mut config = Config::default();
605591
config.llvm_optimize = true;
@@ -625,7 +611,7 @@ impl Config {
625611
let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
626612
// Undo `src/bootstrap`
627613
config.src = manifest_dir.parent().unwrap().parent().unwrap().to_owned();
628-
config.out = Config::path_from_python("BUILD_DIR");
614+
config.out = PathBuf::from("build");
629615

630616
config.initial_cargo = PathBuf::from(env!("CARGO"));
631617
config.initial_rustc = PathBuf::from(env!("RUSTC"));
@@ -655,12 +641,6 @@ impl Config {
655641
config.llvm_profile_use = flags.llvm_profile_use;
656642
config.llvm_profile_generate = flags.llvm_profile_generate;
657643

658-
if config.dry_run {
659-
let dir = config.out.join("tmp-dry-run");
660-
t!(fs::create_dir_all(&dir));
661-
config.out = dir;
662-
}
663-
664644
#[cfg(test)]
665645
let get_toml = |_| TomlConfig::default();
666646
#[cfg(not(test))]
@@ -695,6 +675,19 @@ impl Config {
695675

696676
let build = toml.build.unwrap_or_default();
697677

678+
set(&mut config.out, build.build_dir.map(String::into));
679+
t!(fs::create_dir_all(&config.out));
680+
config.out = t!(
681+
config.out.canonicalize(),
682+
format!("failed to canonicalize {}", config.out.display())
683+
);
684+
685+
if config.dry_run {
686+
let dir = config.out.join("tmp-dry-run");
687+
t!(fs::create_dir_all(&dir));
688+
config.out = dir;
689+
}
690+
698691
config.hosts = if let Some(arg_host) = flags.host {
699692
arg_host
700693
} else if let Some(file_host) = build.host {

0 commit comments

Comments
 (0)