Skip to content

Commit 34d6b44

Browse files
committed
Auto merge of #71994 - jyn514:path-independent, r=Mark-Simulacrum
x.py: allow configuring the build directory This allows configuring the directory for build artifacts, instead of having it always be `./build`. This means you can set it to a constant location, letting you reuse the same cache while working in several different directories. The configuration lives in `config.toml` under `build.build-dir`. By default, it keeps the existing default of `./build`, but it can be configured to any relative or absolute path. Additionally, it allows making outputs relative to the root of the git repository using `$ROOT`. r? @Mark-Simulacrum
2 parents 945d110 + df36ec0 commit 34d6b44

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

config.toml.example

+4
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@
131131
# for each target triple.
132132
#target = ["x86_64-unknown-linux-gnu"] # defaults to just the build triple
133133

134+
# Use this directory to store build artifacts.
135+
# You can use "$ROOT" to indicate the root of the git repository.
136+
#build-dir = "build"
137+
134138
# Instead of downloading the src/stage0.txt version of Cargo specified, use
135139
# this Cargo binary instead to build all Rust code
136140
#cargo = "/path/to/bin/cargo"

src/bootstrap/bootstrap.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ def __init__(self):
332332
self.rustc_channel = ''
333333
self.rustfmt_channel = ''
334334
self.build = ''
335-
self.build_dir = os.path.join(os.getcwd(), "build")
335+
self.build_dir = ''
336336
self.clean = False
337337
self.config_toml = ''
338338
self.rust_root = ''
@@ -891,7 +891,11 @@ def bootstrap(help_triggered):
891891
build.clean = args.clean
892892

893893
try:
894-
with open(args.config or 'config.toml') as config:
894+
toml_path = args.config or 'config.toml'
895+
if not os.path.exists(toml_path):
896+
toml_path = os.path.join(build.rust_root, toml_path)
897+
898+
with open(toml_path) as config:
895899
build.config_toml = config.read()
896900
except (OSError, IOError):
897901
pass
@@ -906,6 +910,9 @@ def bootstrap(help_triggered):
906910

907911
build.check_vendored_status()
908912

913+
build_dir = build.get_toml('build-dir', 'build') or 'build'
914+
build.build_dir = os.path.abspath(build_dir.replace("$ROOT", build.rust_root))
915+
909916
data = stage0_data(build.rust_root)
910917
build.date = data['date']
911918
build.rustc_channel = data['rustc']

src/bootstrap/config.rs

+2
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ struct Build {
212212
host: Vec<String>,
213213
#[serde(default)]
214214
target: Vec<String>,
215+
// This is ignored, the rust code always gets the build directory from the `BUILD_DIR` env variable
216+
build_dir: Option<String>,
215217
cargo: Option<String>,
216218
rustc: Option<String>,
217219
rustfmt: Option<String>, /* allow bootstrap.py to use rustfmt key */

0 commit comments

Comments
 (0)