Skip to content

Commit aa14d51

Browse files
authored
Merge pull request #209 from robotpy/fix-cross-compilation
Fix installation of build dependencies for cross compilation
2 parents 9956007 + 046847e commit aa14d51

File tree

5 files changed

+60
-25
lines changed

5 files changed

+60
-25
lines changed

.github/workflows/dist.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ jobs:
258258
- name: Install deps
259259
shell: bash
260260
run: |
261-
/build/venv/bin/cross-pip --disable-pip-version-check install -r rdev_requirements.txt
261+
/build/venv/bin/build-pip --disable-pip-version-check install -r rdev_requirements.txt
262262
263263
- name: Build + test wheels
264264
shell: bash
@@ -320,7 +320,7 @@ jobs:
320320
- name: Install deps
321321
shell: bash
322322
run: |
323-
/build/venv/bin/cross-pip --disable-pip-version-check install -r rdev_requirements.txt
323+
/build/venv/bin/build-pip --disable-pip-version-check install -r rdev_requirements.txt
324324
325325
- name: Build wheels
326326
shell: bash

devtools/__main__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from .ctx import Context
88
from . import ci
99
from . import update_pyproject
10-
from . import util
1110

1211

1312
#
@@ -83,7 +82,7 @@ def install_prereqs(ctx: Context):
8382
if req.name not in repo_deps:
8483
reqs.add(req)
8584

86-
util.run_pip("install", *map(str, reqs))
85+
ctx.run_pip("install", *map(str, reqs))
8786

8887

8988
@main.command()

devtools/ctx.py

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
import subprocess
44
import sys
55
import sysconfig
6-
import typing
6+
import typing as T
77

88
import toposort
99

1010
from . import config
1111
from .subproject import Subproject
12-
from .util import run_pip
12+
from .util import run_cmd
1313

1414

1515
class Context:
@@ -27,13 +27,13 @@ def __init__(self, verbose: bool) -> None:
2727
self.wheel_path = self.root_path / "dist"
2828
self.other_wheel_path = self.root_path / "dist-other"
2929

30-
subprojects: typing.List[Subproject] = []
30+
subprojects: T.List[Subproject] = []
3131
for project, cfg in self.cfg.subprojects.items():
3232
# Skip projects that aren't compatible with the robot
3333
if self.is_robot and not cfg.robot:
3434
continue
3535

36-
subprojects.append(Subproject(cfg, self.subprojects_path / project))
36+
subprojects.append(Subproject(self, cfg, self.subprojects_path / project))
3737

3838
# Create a sorted dictionary of subprojects ordered by build order
3939
si = {p.pyproject_name: i for i, p in enumerate(subprojects)}
@@ -47,6 +47,29 @@ def __init__(self, verbose: bool) -> None:
4747
for i in toposort.toposort_flatten(ti, sort=False)
4848
}
4949

50+
# build_python is for build dependencies, python is for the target environment
51+
# - if crossenv is specified, then we use that instead
52+
self._build_python = None
53+
self.python = sys.executable
54+
55+
@property
56+
def build_python(self):
57+
if self._build_python is None:
58+
self._build_python = self.python
59+
60+
# try to detect if we're running in crossenv's cross python and
61+
# use the build python instead
62+
if getattr(sys, "cross_compiling", False) == True:
63+
pth = pathlib.Path(self._build_python).resolve()
64+
if pth.parts[-3:-1] == ("cross", "bin"):
65+
self._build_python = str(
66+
pathlib.Path(
67+
*(pth.parts[:-3] + ("build", "bin", pth.parts[-1]))
68+
)
69+
)
70+
71+
return self._build_python
72+
5073
def git_commit(self, msg: str, *relpath: str):
5174
subprocess.run(
5275
["git", "commit", "-F", "-", "--"] + list(relpath),
@@ -102,13 +125,14 @@ def install_build_deps(
102125
external.append(req)
103126

104127
if external:
105-
run_pip(
128+
self.run_pip(
106129
"install",
107130
*[str(req) for req in external],
131+
installing_build_deps=True,
108132
)
109133

110134
if internal:
111-
run_pip(
135+
self.run_pip(
112136
"install",
113137
"--no-index",
114138
"--find-links",
@@ -117,3 +141,11 @@ def install_build_deps(
117141
str(self.other_wheel_path),
118142
*[str(req) for req in internal],
119143
)
144+
145+
def run_pip(self, *args: str, cwd=None, installing_build_deps: bool = False):
146+
if installing_build_deps:
147+
python = self.build_python
148+
else:
149+
python = self.python
150+
151+
run_cmd(python, "-m", "pip", "--disable-pip-version-check", *args, cwd=cwd)

devtools/subproject.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,17 @@
88
import tomli
99

1010
from .config import SubprojectConfig
11-
from .util import run_cmd, run_pip
11+
from .util import run_cmd
12+
13+
if T.TYPE_CHECKING:
14+
from .ctx import Context
1215

1316

1417
class Subproject:
15-
def __init__(self, cfg: SubprojectConfig, path: pathlib.Path) -> None:
18+
def __init__(
19+
self, ctx: "Context", cfg: SubprojectConfig, path: pathlib.Path
20+
) -> None:
21+
self.ctx = ctx
1622
self.cfg = cfg
1723
self.path = path
1824
self.pyproject_path = self.path / "pyproject.toml"
@@ -43,15 +49,17 @@ def is_meson_project(self) -> bool:
4349
#
4450

4551
def develop(self):
46-
run_pip("install", "-v", "-e", ".", "--no-build-isolation", cwd=self.path)
52+
self.ctx.run_pip(
53+
"install", "-v", "-e", ".", "--no-build-isolation", cwd=self.path
54+
)
4755

4856
def uninstall(self):
49-
run_pip("uninstall", "-y", self.pyproject_name)
57+
self.ctx.run_pip("uninstall", "-y", self.pyproject_name)
5058

5159
def scan_headers(self):
5260
"""Returns True if no headers found or False if missing headers were found"""
5361
result = run_cmd(
54-
sys.executable,
62+
self.ctx.python,
5563
"-m",
5664
"semiwrap",
5765
"scan-headers",
@@ -64,7 +72,7 @@ def scan_headers(self):
6472
def update_yaml(self):
6573
"""Resyncs the yaml files with their header files"""
6674
result = run_cmd(
67-
sys.executable,
75+
self.ctx.python,
6876
"-m",
6977
"semiwrap",
7078
"update-yaml",
@@ -76,7 +84,7 @@ def update_yaml(self):
7684

7785
def update_init(self):
7886
run_cmd(
79-
sys.executable,
87+
self.ctx.python,
8088
"-m",
8189
"semiwrap",
8290
"update-init",
@@ -91,14 +99,14 @@ def test(self, *, install_requirements=False):
9199
if install_requirements:
92100
requirements = tests_path / "requirements.txt"
93101
if requirements.exists():
94-
run_pip(
102+
self.ctx.run_pip(
95103
"install",
96104
"-r",
97105
str(requirements),
98106
)
99107

100108
run_cmd(
101-
sys.executable,
109+
self.ctx.python,
102110
"run_tests.py",
103111
cwd=tests_path,
104112
)
@@ -120,7 +128,7 @@ def build_wheel(
120128
with tempfile.TemporaryDirectory() as td:
121129
# I wonder if we should use hatch build instead?
122130
run_cmd(
123-
sys.executable,
131+
self.ctx.python,
124132
"-m",
125133
"build",
126134
"--no-isolation",
@@ -138,7 +146,7 @@ def build_wheel(
138146

139147
if install:
140148
# Install the wheel
141-
run_pip(
149+
self.ctx.run_pip(
142150
"install",
143151
"--find-links",
144152
str(wheel_path),

devtools/util.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,3 @@ def parse_input(value: typing.Any, spec: typing.Type[T], fname) -> T:
4747
def run_cmd(*args: str, cwd=None, check=True):
4848
print("+", shlex.join(args))
4949
return subprocess.run(args, cwd=cwd, check=check)
50-
51-
52-
def run_pip(*args: str, cwd=None):
53-
run_cmd(sys.executable, "-m", "pip", "--disable-pip-version-check", *args, cwd=cwd)

0 commit comments

Comments
 (0)