From d1c135574e9b2fc86936e864794e9bdab3c2d61c Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Sat, 10 Jun 2023 11:16:53 -0400 Subject: [PATCH] tests: add a cross-compile test Signed-off-by: Henry Schreiner --- .../builder/cross_compile.py | 2 +- tests/test_cross_compile.py | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 tests/test_cross_compile.py diff --git a/src/scikit_build_core/builder/cross_compile.py b/src/scikit_build_core/builder/cross_compile.py index 0577f296c..f1f8a1bac 100644 --- a/src/scikit_build_core/builder/cross_compile.py +++ b/src/scikit_build_core/builder/cross_compile.py @@ -9,7 +9,7 @@ from .._logging import logger -__all__ = ["set_cross_compile_env"] +__all__ = ["set_cross_compile_env", "auto_cross_compile_env"] def __dir__() -> list[str]: diff --git a/tests/test_cross_compile.py b/tests/test_cross_compile.py new file mode 100644 index 000000000..1d43b95b4 --- /dev/null +++ b/tests/test_cross_compile.py @@ -0,0 +1,36 @@ +from __future__ import annotations + +import os +import subprocess +import sys +import sysconfig + +import pytest + +from scikit_build_core.builder.cross_compile import set_cross_compile_env + + +@pytest.mark.skipif( + sysconfig.get_config_var("SOABI") != "cp311-win_amd64", + reason="Only tests 'cp311-win_amd64', got {sysconfig.get_config_var('SOABI')!r}", +) +def test_environment(): + env = os.environ.copy() + cmd = [ + sys.executable, + "-c", + "import sysconfig; print(sysconfig.get_config_var('SOABI'), sysconfig.get_config_var('EXT_SUFFIX'))", + ] + + with set_cross_compile_env(".cp311-win_arm64.pyd", env): + result = subprocess.run( + cmd, check=True, capture_output=True, text=True, env=env + ) + soabi, ext_suffix = result.stdout.strip().split() + assert soabi == "cp311-win_arm64" + assert ext_suffix == ".cp311-win_arm64.pyd" + + result = subprocess.run(cmd, check=True, capture_output=True, text=True, env=env) + soabi, ext_suffix = result.stdout.strip().split() + assert soabi == "cp311-win_amd64" + assert ext_suffix == ".cp311-win_amd64.pyd"