Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions pycross/private/build/tools/utils/sysconfig_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
from pycross.private.build.tools.utils.venv_utils import find_site_dir


def determine_target_path_from_exec(exec_python_exe: Path, target_python_exe: Path) -> List[Path]:
def determine_target_path_from_exec(exec_python_exe: Path, target_python_exe: Path, env: Dict[str, str]) -> List[Path]:
"""Query target sys.path using host Python relative references."""
query_args = (
exec_python_exe,
"-c",
"import json, sys; print(json.dumps(dict(exec=sys.executable, path=sys.path)))",
)
try:
out_json = subprocess.check_output(args=query_args, env={})
out_json = subprocess.check_output(args=query_args, env=env)
query_result = json.loads(out_json)
except subprocess.CalledProcessError as cpe:
print("Failed to query exec_python for target path", file=sys.stderr)
Expand Down Expand Up @@ -63,7 +63,13 @@ def find_sysconfig_data(search_paths: List[Path]) -> Dict[str, Any]:
return {}


def _query_interpreter(python_exe: Path) -> Optional[Dict[str, Any]]:
def _query_interpreter(
python_exe: Path,
env: Optional[Dict[str, str]] = None,
*,
# Some toolchain interpreters exceeded the previous 5-second query timeout in CI.
timeout: int = 30,
) -> Optional[Dict[str, Any]]:
query_args = (
python_exe,
"-c",
Expand All @@ -85,7 +91,7 @@ def _query_interpreter(python_exe: Path) -> Optional[Dict[str, Any]]:
),
)
try:
out_json = subprocess.check_output(args=query_args, timeout=5, stderr=subprocess.DEVNULL)
out_json = subprocess.check_output(args=query_args, timeout=timeout, stderr=subprocess.DEVNULL, env=env)
return json.loads(out_json)
except Exception as e:
print(
Expand All @@ -99,12 +105,14 @@ def load_target_sysconfig(ctx: BuildContext) -> Dict[str, Any]:
# Try to query the target python directly first (works for host and same-arch target toolchains).
# Falls back to static _sysconfigdata for cross-compilation where the target
# interpreter cannot be executed on the host.
result = _query_interpreter(ctx.target_python)
result = _query_interpreter(ctx.target_python, ctx.build_env)
if result is not None:
return result

# Fallback for cross-compilation: load static _sysconfigdata
target_sys_path = determine_target_path_from_exec(ctx.exec_python, ctx.target_python)
query_env = ctx.build_env.copy()
query_env.pop("PYTHONPATH", None)
target_sys_path = determine_target_path_from_exec(ctx.exec_python, ctx.target_python, query_env)
return find_sysconfig_data(target_sys_path)


Expand Down
Loading