Skip to content

Commit da92aec

Browse files
Use base executable when it exists, to avoid recompiling when switching venv
1 parent 70fc951 commit da92aec

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

setuptools_rust/build.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -610,9 +610,13 @@ def _replace_vendor_with_unknown(target: str) -> Optional[str]:
610610
def _prepare_build_environment() -> Dict[str, str]:
611611
"""Prepares environment variables to use when executing cargo build."""
612612

613+
executable = getattr(sys, "_base_executable", sys.executable)
614+
if not os.path.exists(executable):
615+
executable = sys.executable
616+
613617
# Make sure that if pythonXX-sys is used, it builds against the current
614618
# executing python interpreter.
615-
bindir = os.path.dirname(sys.executable)
619+
bindir = os.path.dirname(executable)
616620

617621
env = os.environ.copy()
618622
env.update(
@@ -622,9 +626,9 @@ def _prepare_build_environment() -> Dict[str, str]:
622626
# interpreter from the path.
623627
"PATH": os.path.join(bindir, os.environ.get("PATH", "")),
624628
"PYTHON_SYS_EXECUTABLE": os.environ.get(
625-
"PYTHON_SYS_EXECUTABLE", sys.executable
629+
"PYTHON_SYS_EXECUTABLE", executable
626630
),
627-
"PYO3_PYTHON": os.environ.get("PYO3_PYTHON", sys.executable),
631+
"PYO3_PYTHON": os.environ.get("PYO3_PYTHON", executable),
628632
}
629633
)
630634
return env

0 commit comments

Comments
 (0)