Skip to content
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions docs/guide/crosscompile.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
8 changes: 7 additions & 1 deletion src/scikit_build_core/builder/wheel_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import dataclasses
import itertools
import os
import sys
import sysconfig
from typing import TYPE_CHECKING
Expand Down Expand Up @@ -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]]
Expand Down
19 changes: 19 additions & 0 deletions tests/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Loading