diff --git a/docs/guide/crosscompile.md b/docs/guide/crosscompile.md index 97b24531..3423c91f 100644 --- a/docs/guide/crosscompile.md +++ b/docs/guide/crosscompile.md @@ -64,3 +64,6 @@ by setting `_PYTHON_SYSCONFIGDATA_NAME`. This causes values like `SOABI` and This is unfortunately incorrectly stripped from the cmake wrapper pyodide uses, so FindPython will report the wrong values, but pyodide-build will rename the .so's afterwards. + +pyodide-build will also set `_PYTHON_HOST_PLATFORM` to the target Pyodide +platform, so scikit-build-core can use that to compute the correct wheel name. diff --git a/src/scikit_build_core/builder/wheel_tag.py b/src/scikit_build_core/builder/wheel_tag.py index 979b64dc..5b81e9b0 100644 --- a/src/scikit_build_core/builder/wheel_tag.py +++ b/src/scikit_build_core/builder/wheel_tag.py @@ -2,6 +2,7 @@ import dataclasses import itertools +import os import sys import sysconfig from typing import TYPE_CHECKING @@ -60,7 +61,12 @@ def compute_best( interp, abi, *plats = (best_tag.interpreter, best_tag.abi, best_tag.platform) pyvers = [interp] - if sys.platform.startswith("win") and archs: + # Check for _PYTHON_HOST_PLATFORM environment variable to override platform + host_platform = os.environ.get("_PYTHON_HOST_PLATFORM") + if host_platform: + # Convert sysconfig platform format to wheel platform tag format + plats = [host_platform.replace("-", "_").replace(".", "_")] + elif sys.platform.startswith("win") and archs: plats = [x.replace("-", "_") for x in archs] elif sys.platform.startswith("darwin"): pairs: Iterable[tuple[str | None, bool]] diff --git a/tests/test_builder.py b/tests/test_builder.py index 27ace40c..f1040701 100644 --- a/tests/test_builder.py +++ b/tests/test_builder.py @@ -264,3 +264,22 @@ def test_wheel_tag_with_abi_darwin(monkeypatch): tags = WheelTag.compute_best(["x86_64"], py_api="py2.py3") assert str(tags) == "py2.py3-none-macosx_10_10_x86_64" + + +def test_wheel_tag_host_platform_override(monkeypatch): + """Test that _PYTHON_HOST_PLATFORM environment variable overrides platform detection.""" + get_config_var = sysconfig.get_config_var + monkeypatch.setattr( + sysconfig, + "get_config_var", + lambda x: None if x == "Py_GIL_DISABLED" else get_config_var(x), + ) + monkeypatch.setattr(sys, "platform", "linux") + + monkeypatch.setenv("_PYTHON_HOST_PLATFORM", "macosx-11.0-arm64") + tags = WheelTag.compute_best(["x86_64"], py_api="py3") + assert str(tags) == "py3-none-macosx_11_0_arm64" + + monkeypatch.setenv("_PYTHON_HOST_PLATFORM", "emscripten-4.0.9-wasm32") + tags = WheelTag.compute_best(["x86_64"], py_api="py3") + assert str(tags) == "py3-none-emscripten_4_0_9_wasm32"