Skip to content

Commit 9901e39

Browse files
committed
fix platform inference macos
1 parent c658ce4 commit 9901e39

2 files changed

Lines changed: 61 additions & 11 deletions

File tree

livekit-rtc/hatch_build.py

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import os
16+
import platform
1517
import sys
1618

1719
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
@@ -29,17 +31,55 @@ def initialize(self, version, build_data):
2931
build_data["pure_python"] = False
3032
build_data["infer_tag"] = False
3133

32-
# Get the platform tag using hatchling's logic (handles MACOSX_DEPLOYMENT_TARGET, etc.)
33-
from packaging.tags import sys_tags
34+
if sys.platform == "darwin":
35+
plat_tag = self._get_macos_platform_tag()
36+
else:
37+
from packaging.tags import sys_tags
3438

35-
tag = next(
36-
t for t in sys_tags() if "manylinux" not in t.platform and "musllinux" not in t.platform
37-
)
38-
platform = tag.platform
39+
tag = next(
40+
t
41+
for t in sys_tags()
42+
if "manylinux" not in t.platform and "musllinux" not in t.platform
43+
)
44+
plat_tag = tag.platform
3945

40-
if sys.platform == "darwin":
41-
from hatchling.builders.macos import process_macos_plat_tag
46+
build_data["tag"] = f"py3-none-{plat_tag}"
47+
48+
def _get_macos_platform_tag(self):
49+
"""Build macOS platform tag from MACOSX_DEPLOYMENT_TARGET env var."""
50+
deployment_target = os.environ.get("MACOSX_DEPLOYMENT_TARGET")
51+
if not deployment_target:
52+
# Fall back to current macOS version
53+
deployment_target = platform.mac_ver()[0]
54+
# Use only major.minor
55+
parts = deployment_target.split(".")
56+
deployment_target = f"{parts[0]}.{parts[1] if len(parts) > 1 else '0'}"
57+
58+
# Convert version to wheel tag format (e.g., "11.0" -> "11_0")
59+
version_tag = deployment_target.replace(".", "_")
4260

43-
platform = process_macos_plat_tag(platform, compat=True)
61+
# Get target architecture from ARCHFLAGS (set by cibuildwheel for cross-compilation)
62+
# or fall back to host machine architecture
63+
arch = self._get_macos_target_arch()
64+
65+
return f"macosx_{version_tag}_{arch}"
66+
67+
def _get_macos_target_arch(self):
68+
"""Detect target architecture for macOS builds.
69+
70+
Cibuildwheel sets ARCHFLAGS for cross-compilation (e.g., "-arch x86_64").
71+
Falls back to host machine architecture if not set.
72+
"""
73+
archflags = os.environ.get("ARCHFLAGS", "")
74+
if "-arch arm64" in archflags:
75+
return "arm64"
76+
elif "-arch x86_64" in archflags:
77+
return "x86_64"
4478

45-
build_data["tag"] = f"py3-none-{platform}"
79+
# Fall back to host architecture
80+
machine = platform.machine()
81+
if machine == "x86_64":
82+
return "x86_64"
83+
elif machine == "arm64":
84+
return "arm64"
85+
return machine

livekit-rtc/pyproject.toml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,14 @@ manylinux-ppc64le-image = "manylinux_2_28"
6565
manylinux-s390x-image = "manylinux_2_28"
6666
manylinux-pypy_x86_64-image = "manylinux_2_28"
6767
manylinux-pypy_i686-image = "manylinux_2_28"
68-
manylinux-pypy_aarch64-image = "manylinux_2_28"
68+
manylinux-pypy_aarch64-image = "manylinux_2_28"
69+
70+
# macOS deployment targets must match the FFI binaries (see rust-sdks/.github/workflows/ffi-builds.yml)
71+
# x86_64 supports macOS 10.15+, arm64 requires macOS 11.0+
72+
[[tool.cibuildwheel.overrides]]
73+
select = "*macosx_x86_64"
74+
environment = { MACOSX_DEPLOYMENT_TARGET = "10.15" }
75+
76+
[[tool.cibuildwheel.overrides]]
77+
select = "*macosx_arm64"
78+
environment = { MACOSX_DEPLOYMENT_TARGET = "11.0" }

0 commit comments

Comments
 (0)