Skip to content

Commit 4f6d373

Browse files
committed
Move default Python selection to sanity.rs
1 parent 8295d33 commit 4f6d373

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

src/bootstrap/src/core/sanity.rs

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
//! Sanity checking performed by bootstrap before actually executing anything.
1+
//! Sanity checking and tool selection performed by bootstrap.
22
//!
3-
//! This module contains the implementation of ensuring that the build
4-
//! environment looks reasonable before progressing. This will verify that
5-
//! various programs like git and python exist, along with ensuring that all C
6-
//! compilers for cross-compiling are found.
3+
//! This module ensures that the build environment is correctly set up before
4+
//! executing any build tasks. It verifies that required programs exist (like
5+
//! git and cmake when needed), selects appropriate tools based on the environment
6+
//! and platform requirements (like choosing the correct Python interpreter),
7+
//! and validates that C compilers for cross-compiling are available.
78
//!
89
//! In theory if we get past this phase it's a bug if a build fails, but in
910
//! practice that's likely not true!
@@ -165,15 +166,34 @@ than building it.
165166
crate::exit!(1);
166167
}
167168

168-
build.config.python = build
169-
.config
170-
.python
171-
.take()
172-
.map(|p| cmd_finder.must_have(p))
173-
.or_else(|| env::var_os("BOOTSTRAP_PYTHON").map(PathBuf::from)) // set by bootstrap.py
174-
.or_else(|| cmd_finder.maybe_have("python"))
175-
.or_else(|| cmd_finder.maybe_have("python3"))
176-
.or_else(|| cmd_finder.maybe_have("python2"));
169+
// Select the Python interpreter to use throughout the build.
170+
//
171+
// On macOS, LLDB tests require the Python version the LLDB plugin was built for.
172+
// The system Python/LLDB are compatible, and many users install Homebrew Python
173+
// but not Homebrew LLVM, so we default to the system Python (/usr/bin/python3).
174+
// This can be overridden via the `build.python` config option for custom LLVM installations.
175+
//
176+
// On other platforms, we prefer the Python interpreter that invoked bootstrap.py
177+
// (available via the BOOTSTRAP_PYTHON env var), then fall back to searching PATH
178+
// for python, python3, or python2.
179+
build.config.python = if build.host_target.ends_with("apple-darwin") {
180+
build
181+
.config
182+
.python
183+
.take()
184+
.map(|p| cmd_finder.must_have(p))
185+
.or_else(|| Some(PathBuf::from("/usr/bin/python3")))
186+
} else {
187+
build
188+
.config
189+
.python
190+
.take()
191+
.map(|p| cmd_finder.must_have(p))
192+
.or_else(|| env::var_os("BOOTSTRAP_PYTHON").map(PathBuf::from)) // set by bootstrap.py
193+
.or_else(|| cmd_finder.maybe_have("python"))
194+
.or_else(|| cmd_finder.maybe_have("python3"))
195+
.or_else(|| cmd_finder.maybe_have("python2"))
196+
};
177197

178198
build.config.nodejs = build
179199
.config

0 commit comments

Comments
 (0)