Skip to content

Commit

Permalink
Add helpers for cross-compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
romainthomas committed Nov 26, 2023
1 parent 6ddc7e4 commit 47a7807
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions api/python/backend/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ def cmake_dump(self) -> List[str]:
class CrossCompilation(BaseModel):
osx_arch: Optional[str] = Field(None, alias="osx-arch")
platform: Optional[str] = None
pyversion: Optional[str] = None
abi: Optional[str] = None

def cmake_dump(self) -> List[str]:
out: List[str] = []
Expand Down
25 changes: 25 additions & 0 deletions api/python/backend/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

DEFAULT_CONF = CWD / ".." / "config-default.toml"

_WHEEL_TAG_COMPUTE_BEST = None

@lru_cache(maxsize=1)
def get_config():
from config import Config
Expand All @@ -21,6 +23,24 @@ def get_config():
return Config.from_file(config_path)
return Config.from_file(DEFAULT_CONF.as_posix())


def _compute_best(cls, *arg, **kwargs):
from scikit_build_core.builder.wheel_tag import WheelTag
best_tag = _WHEEL_TAG_COMPUTE_BEST(cls, *arg, **kwargs)
config = get_config()

pyvers = best_tag.pyvers
abis = best_tag.abis
archs = best_tag.archs

if version := config.cross_compilation.pyversion:
pyvers = [version]

if abi := config.cross_compilation.abi:
abis = [abi]

return WheelTag(pyvers, abis, archs)

def _fix_env():
config = get_config()
if sys.platform.startswith("win"):
Expand All @@ -42,6 +62,11 @@ def _fix_env():
os.environ["ARCHFLAGS"]= f"-arch {config.osx_arch}"

if platform := config.cross_compilation.platform:
global _WHEEL_TAG_COMPUTE_BEST
from scikit_build_core.builder.wheel_tag import WheelTag
_WHEEL_TAG_COMPUTE_BEST = WheelTag.compute_best
WheelTag.compute_best = _compute_best

os.environ["_PYTHON_HOST_PLATFORM"] = platform

if os.name == 'nt' and platform == 'win32':
Expand Down

0 comments on commit 47a7807

Please sign in to comment.