Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[draft] Sketched out an explicit QEMU mode #1773

Closed
wants to merge 7 commits into from
Closed
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
19 changes: 18 additions & 1 deletion cibuildwheel/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from ._compat.typing import assert_never
from .architecture import Architecture
from .logger import log
from .oci_container import OCIContainer
from .oci_container import OCIContainer, OCIPlatform
from .options import Options
from .typing import PathOrStr
from .util import (
Expand All @@ -28,6 +28,14 @@
unwrap,
)

ArchitectureOCIPlatformMap = {
Architecture.x86_64: OCIPlatform.AMD64,
Architecture.i686: OCIPlatform.i386,
Architecture.aarch64: OCIPlatform.ARM64,
Architecture.ppc64le: OCIPlatform.PPC64LE,
Architecture.s390x: OCIPlatform.S390X,
}


@dataclass(frozen=True)
class PythonConfiguration:
Expand Down Expand Up @@ -431,11 +439,20 @@ def build(options: Options, tmp_path: Path) -> None: # noqa: ARG001

print(f"info: This container will host the build for {', '.join(ids_to_build)}...")

for wheel_platform, oci_platform in ArchitectureOCIPlatformMap.items():
if build_step.platform_tag.endswith(wheel_platform.name):
this_build_platform = oci_platform
break
else:
msg = f"Unexpected build platform: {build_step.platform_tag}."
raise ValueError(msg)

with OCIContainer(
image=build_step.container_image,
enforce_32_bit=build_step.platform_tag.endswith("i686"),
cwd=container_project_path,
engine=options.globals.container_engine,
oci_platform=this_build_platform,
) as container:
build_in_container(
options=options,
Expand Down
12 changes: 12 additions & 0 deletions cibuildwheel/oci_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import uuid
from collections.abc import Mapping, Sequence
from dataclasses import dataclass
from enum import Enum
from pathlib import Path, PurePath, PurePosixPath
from types import TracebackType
from typing import IO, Dict, Literal
Expand All @@ -29,6 +30,14 @@
ContainerEngineName = Literal["docker", "podman"]


class OCIPlatform(Enum):
AMD64 = "linux/amd64"
i386 = "linux/386"
ARM64 = "linux/arm64"
PPC64LE = "linux/ppc64le"
S390X = "linux/s390x"


@dataclass(frozen=True)
class OCIContainerEngineConfig:
name: ContainerEngineName
Expand Down Expand Up @@ -111,6 +120,7 @@ def __init__(
enforce_32_bit: bool = False,
cwd: PathOrStr | None = None,
engine: OCIContainerEngineConfig = DEFAULT_ENGINE,
oci_platform: OCIPlatform | None = None,
):
if not image:
msg = "Must have a non-empty image to run."
Expand All @@ -121,6 +131,7 @@ def __init__(
self.cwd = cwd
self.name: str | None = None
self.engine = engine
self.oci_platform = oci_platform

def __enter__(self) -> Self:
self.name = f"cibuildwheel-{uuid.uuid4()}"
Expand Down Expand Up @@ -149,6 +160,7 @@ def __enter__(self) -> Self:
[
self.engine.name,
"create",
*((f"--platform={self.oci_platform.value}",) if self.oci_platform else ()),
"--env=CIBUILDWHEEL",
"--env=SOURCE_DATE_EPOCH",
f"--name={self.name}",
Expand Down
Loading