setup: make sure Rust build its extension for the right python stable
authorPierre-Yves David <pierre-yves.david@octobus.net>
Wed, 13 Nov 2024 16:13:28 +0100
branchstable
changeset 52246 124c944b71b2
parent 52245 d57d1606049c
child 52247 309f58964a9e
setup: make sure Rust build its extension for the right python Strictly speaking, only "PYTHON_SYS_EXECUTABLE" seems to be necessary, but I don't want to take a chances, as in testing "PYTHON" also had an effect.
setup.py
--- a/setup.py	Wed Nov 13 13:33:36 2024 +0100
+++ b/setup.py	Wed Nov 13 16:13:28 2024 +0100
@@ -1566,6 +1566,15 @@
 
             env['HOME'] = pwd.getpwuid(os.getuid()).pw_dir
 
+        # Wildy shooting in the dark to make sure rust-cpython use the right
+        # python
+        if not sys.executable:
+            msg = "Cannot determine which Python to compile Rust for"
+            raise RustCompilationError(msg)
+        env['PYTHON_SYS_EXECUTABLE'] = sys.executable
+        env['PYTHONEXECUTABLE'] = sys.executable
+        env['PYTHON'] = sys.executable
+
         cargocmd = ['cargo', 'rustc', '--release']
 
         rust_features = env.get("HG_RUST_FEATURES")