Skip to content

Commit 2f6befe

Browse files
committed
universal wheels
1 parent 8020151 commit 2f6befe

File tree

2 files changed

+47
-6
lines changed

2 files changed

+47
-6
lines changed

devtools/subproject.py

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import os
12
import pathlib
23
import subprocess
34
import shlex
45
import shutil
56
import sys
67
import tempfile
8+
import textwrap
79
import typing as T
810

911
from packaging.requirements import Requirement
@@ -43,9 +45,14 @@ def is_meson_project(self) -> bool:
4345
# Tasks
4446
#
4547

46-
def _cmd(self, *args: str, cwd=None):
48+
def _cmd(self, *args: str, cwd=None, env=None):
4749
print("+", shlex.join(args))
48-
subprocess.check_call(args, cwd=cwd)
50+
if env:
51+
envc = os.environ.copy()
52+
envc.update(env)
53+
env = envc
54+
55+
subprocess.check_call(args, cwd=cwd, env=env)
4956

5057
def _run_pip(self, *args: str, cwd=None):
5158
self._cmd(
@@ -119,6 +126,8 @@ def build_wheel(
119126
# TODO: eventually it would be nice to use build isolation
120127

121128
with tempfile.TemporaryDirectory() as td:
129+
tdp = pathlib.Path(td)
130+
122131
# I wonder if we should use hatch build instead?
123132
self._cmd(
124133
sys.executable,
@@ -131,9 +140,39 @@ def build_wheel(
131140
cwd=self.path,
132141
)
133142

134-
tdp = pathlib.Path(td)
135-
twhl = list(tdp.glob("*.whl"))[0]
136-
dst_whl = wheel_path / self._fix_wheel_name(twhl.name)
143+
# On macOS we need to build two wheels and merge them together to build
144+
# a universal wheel. Fun?
145+
# - Since this script is for CI, we assume that we are building on arm64
146+
if sys.platform == "darwin" and self.is_meson_project():
147+
148+
self._cmd(
149+
sys.executable,
150+
"-m",
151+
"build",
152+
"--no-isolation",
153+
"--outdir",
154+
td,
155+
*config_args,
156+
cwd=self.path,
157+
env=dict(ARCHFLAGS="-arch x86_64", SEMIWRAP_SKIP_PYI="1"),
158+
)
159+
160+
native_wheels = list(map(str, tdp.glob("*.whl")))
161+
162+
self._cmd(
163+
sys.executable,
164+
"-m",
165+
"delocate.cmd.delocate_merge",
166+
"-vv",
167+
*native_wheels,
168+
)
169+
170+
twhl = (set(map(str, tdp.glob("*.whl"))) - set(native_wheels)).pop()
171+
dst_whl = wheel_path / pathlib.Path(twhl).name
172+
else:
173+
twhl = list(tdp.glob("*.whl"))[0]
174+
dst_whl = wheel_path / self._fix_wheel_name(twhl.name)
175+
137176
shutil.move(twhl, dst_whl)
138177

139178
if install:

rdev_requirements.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ toposort
1010
validobj~=1.2
1111
wheel
1212

13+
delocate; platform_system == 'Darwin'
14+
15+
hatch-meson @ git+https://github.com/virtuald/hatch-meson@more-macos-cross-binaries
1316
semiwrap @ git+https://github.com/robotpy/robotpy-build@semiwrap
14-
hatch-meson
1517
hatch-robotpy @ git+https://github.com/robotpy/hatch-robotpy@main
1618
hatch-nativelib @ git+https://github.com/robotpy/hatch-nativelib@rm-macos-relink
1719
ninja

0 commit comments

Comments
 (0)