From 444a6b75f4f9397ca122b90dee7accaa66329bf2 Mon Sep 17 00:00:00 2001 From: Jieyou Xu Date: Fri, 7 Nov 2025 19:50:01 +0800 Subject: [PATCH 1/5] compiletest: don't pickup a Python from `PYTHONPATH` in debuginfo --- src/tools/compiletest/src/common.rs | 5 ----- src/tools/compiletest/src/runtest.rs | 2 -- src/tools/compiletest/src/runtest/debuginfo.rs | 18 ++---------------- 3 files changed, 2 insertions(+), 23 deletions(-) diff --git a/src/tools/compiletest/src/common.rs b/src/tools/compiletest/src/common.rs index 1f893fecb54b0..48b1d452dd6db 100644 --- a/src/tools/compiletest/src/common.rs +++ b/src/tools/compiletest/src/common.rs @@ -524,9 +524,6 @@ pub struct Config { /// /// FIXME: the fallback path when `gdb` isn't provided tries to find *a* `gdb` or `gdb.exe` from /// `PATH`, which is... arguably questionable. - /// - /// FIXME: we are propagating a python from `PYTHONPATH`, not from an explicit config for gdb - /// debugger script. pub gdb: Option, /// Version of GDB, encoded as ((major * 1000) + minor) * 1000 + patch @@ -587,8 +584,6 @@ pub struct Config { pub adb_device_status: bool, /// Path containing LLDB's Python module. - /// - /// FIXME: `PYTHONPATH` takes precedence over this flag...? See `runtest::run_lldb`. pub lldb_python_dir: Option, /// Verbose dump a lot of info. diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 8b776f7e92895..aafcbdebcb9b8 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -196,14 +196,12 @@ pub fn compute_stamp_hash(config: &Config) -> String { Some(Debugger::Gdb) => { config.gdb.hash(&mut hash); env::var_os("PATH").hash(&mut hash); - env::var_os("PYTHONPATH").hash(&mut hash); } Some(Debugger::Lldb) => { config.python.hash(&mut hash); config.lldb_python_dir.hash(&mut hash); env::var_os("PATH").hash(&mut hash); - env::var_os("PYTHONPATH").hash(&mut hash); } None => {} diff --git a/src/tools/compiletest/src/runtest/debuginfo.rs b/src/tools/compiletest/src/runtest/debuginfo.rs index bc597597ce12e..077f8ac7e46d2 100644 --- a/src/tools/compiletest/src/runtest/debuginfo.rs +++ b/src/tools/compiletest/src/runtest/debuginfo.rs @@ -303,14 +303,7 @@ impl TestCx<'_> { &["-quiet".as_ref(), "-batch".as_ref(), "-nx".as_ref(), &debugger_script]; let mut gdb = Command::new(self.config.gdb.as_ref().unwrap()); - - // FIXME: we are propagating `PYTHONPATH` from the environment, not a compiletest flag! - let pythonpath = if let Ok(pp) = std::env::var("PYTHONPATH") { - format!("{pp}:{rust_pp_module_abs_path}") - } else { - rust_pp_module_abs_path.to_string() - }; - gdb.args(debugger_opts).env("PYTHONPATH", pythonpath); + gdb.args(debugger_opts); debugger_run_result = self.compose_and_run(gdb, self.config.run_lib_path.as_path(), None, None); @@ -449,19 +442,12 @@ impl TestCx<'_> { // Prepare the lldb_batchmode which executes the debugger script let lldb_script_path = self.config.src_root.join("src/etc/lldb_batchmode.py"); - // FIXME: `PYTHONPATH` takes precedence over the flag...? - let pythonpath = if let Ok(pp) = std::env::var("PYTHONPATH") { - format!("{pp}:{}", self.config.lldb_python_dir.as_ref().unwrap()) - } else { - self.config.lldb_python_dir.clone().unwrap() - }; self.run_command_to_procres( Command::new(&self.config.python) .arg(&lldb_script_path) .arg(test_executable) .arg(debugger_script) - .env("PYTHONUNBUFFERED", "1") // Help debugging #78665 - .env("PYTHONPATH", pythonpath), + .env("PYTHONUNBUFFERED", "1"), // Help debugging #78665 ) } } From b1b65e1f61077663ded5d3fc84093bc4865bcc8e Mon Sep 17 00:00:00 2001 From: Jieyou Xu Date: Fri, 7 Nov 2025 19:52:50 +0800 Subject: [PATCH 2/5] [DO NOT MERGE] ----- commit stack separator ----- From e40280732f2600137d91e9de63c14d4aaec665ca Mon Sep 17 00:00:00 2001 From: Seth Junot Date: Thu, 6 Nov 2025 23:00:35 -0800 Subject: [PATCH 3/5] [DO NOT MERGE] bootstrap: respect `build.python` on macOS The `python()` method was hardcoded to return `/usr/bin/python3` on macOS, ignoring the `build.python` config option. This change respects the config while maintaining the system Python as the default. --- src/bootstrap/src/lib.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index d646e3badb415..dfee211c2ab66 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -1525,10 +1525,11 @@ impl Build { /// Path to the python interpreter to use fn python(&self) -> &Path { if self.config.host_target.ends_with("apple-darwin") { - // Force /usr/bin/python3 on macOS for LLDB tests because we're loading the - // LLDB plugin's compiled module which only works with the system python - // (namely not Homebrew-installed python) - Path::new("/usr/bin/python3") + // LLDB tests require the Python version the LLDB plugin was built for. + // On macOS, the system Python/LLDB are compatible. Many users install + // Homebrew Python but not Homebrew LLVM, so default to system Python. + // Can be overridden via `build.python` for custom LLVM installations. + self.config.python.as_deref().unwrap_or_else(|| Path::new("/usr/bin/python3")) } else { self.config .python From dc68e65f95885f2f05889c5d1250b640ae194e3d Mon Sep 17 00:00:00 2001 From: Seth Junot Date: Fri, 7 Nov 2025 02:39:45 -0800 Subject: [PATCH 4/5] [DO NOT MERGE] The default on macOS is clarified in bootstrap.example.toml --- bootstrap.example.toml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bootstrap.example.toml b/bootstrap.example.toml index 6f37e51a47de2..1fa28ece62c96 100644 --- a/bootstrap.example.toml +++ b/bootstrap.example.toml @@ -322,7 +322,9 @@ # Python interpreter to use for various tasks throughout the build, notably # rustdoc tests, the lldb python interpreter, and some dist bits and pieces. # -# Defaults to the Python interpreter used to execute x.py. +# Defaults to the Python interpreter used to execute x.py, or /usr/bin/python3 +# on macOS. Note that LLDB tests require a Python version compatible with the +# LLDB plugin to be loaded. #build.python = "python" # The path to (or name of) the resource compiler executable to use on Windows. From 790ea73edd5f3dd5d4757bed98bc21802a57d06e Mon Sep 17 00:00:00 2001 From: Seth Junot Date: Fri, 7 Nov 2025 03:11:59 -0800 Subject: [PATCH 5/5] [DO NOT MERGE] The change to bootstrap.example.toml is noted in change_tracker.rs --- src/bootstrap/src/utils/change_tracker.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/bootstrap/src/utils/change_tracker.rs b/src/bootstrap/src/utils/change_tracker.rs index 921f57eb66d6e..3766eab1f4be1 100644 --- a/src/bootstrap/src/utils/change_tracker.rs +++ b/src/bootstrap/src/utils/change_tracker.rs @@ -576,4 +576,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[ severity: ChangeSeverity::Info, summary: "`llvm.enzyme` now works with `download-ci-llvm=true`.", }, + ChangeInfo { + change_id: 148636, + severity: ChangeSeverity::Info, + summary: "The `build.python` option is now respected on macOS (previously ignored).", + }, ];