Switch Python dependency management from pip to rules_pycross#619
Switch Python dependency management from pip to rules_pycross#619linzhp wants to merge 1 commit into
Conversation
|
FYI: @oxidase's https://github.com/oxidase/ofiuco could be an interesting alternative here |
|
At least when using bzlmod, standard rules_python supports cross building just fine. |
|
@ahans can you give an example bzlmod setup with rules_python that can cross compile numpy with correct .so files? |
|
hmm, somehow numpy is pulled by rules_ros2 is not cross-compiling with |
I think the issue is that here in In a repo where I use rules_ros2, I solved this by patching rules_ros2's
In my case, the main module's Python repo is called If things are not clear, I can extend the minimal example from above to include rules_ros2. |
|
Thanks for the pointer. I opened #620 as an alternative. That uses the multi-platform-support you suggested. However, like the doc pointed out:
So this PR may still be needed in the future if we run into that case. But #620 seems to work for now. |
|
rules_ros2 depends on psutil, which has C extension: And the current version in the lock doesn't have Linux aarch64 wheels. I am mildly worried.... |
We solved this by manually building an aarch64 wheel for psutil and putting that in our private PyPI. Since the
You should probably update #620 to also upgrade psutil to a version that has aarch64 wheels. However, I wonder if @mvukov would accept this, since promising cross-compilation compatibility also means one has to make sure it actually works, which in turn increases testing and maintaining efforts. IMHO adapting rules_ros2 by applying some small patches locally is a good enough solution. |
|
Slight worried about the major version upgrade of psutil, but I can do that if @mvukov thinks that's ok |
Sorry for being late to the party. Is there a way we can make this working without patches? This issue is bugging me for a long time now -- I haven't had time to look at recent rules_python... In particular, that we can inject / override rules_ros2_pip_deps while using bzlmod. Regarding psutil -- I am totally fine we upgrade it. One very high level question: is cross-compilation still a think these days when arm64 HW is a commodity? |
Yes, I made it work in #620
Unfortunately yes for Uber... Our dev machines are still mostly macOS and Linux x86-64, while some teams need to cross-compile to Linux-aarch64 |
|
Shall we then move with #620? Upgrading psutil is fine for me. But should be properly tested. We can look into aarch64 builds as well.
<--- This is still puzzling me: how to override rules_ros2_pip_deps without patching rules_ros2. Very probably unrelated to this PR. |
|
I am fine with moving with #620 and close this |
|
OKay, let's do it like that then. OK to retarget this change against the main branch? |
Sorry, do you want this change or #620? |
|
I'd say let's go with #620 since it's much simpler. WDYT? |
|
My bad. I just approved #620 . |
Problem
The current setup uses
rules_python'spip.parseextension to manage Python dependencies (rules_ros2_pip_deps). This works for host buildsbut breaks cross-compilation:
pip.parseresolves wheels for the host platform only, so when targetingaarch64the wrong (x86_64) wheelsare selected. This is the issue raised in #151 (comment).
Solution
Replace
pip.parsewith rules_pycross, which resolves and cross-compiles Python wheels per targetplatform. Dependencies are now declared via a
pyproject.toml/poetry.lockpair, and pycross handles platform-specific wheel selection andbuilding from source where needed.
empyis markedalways_build = Truebecause no pre-built aarch64 wheel is available on PyPI — pycross builds it from the sdist.Changes
MODULE.bazel— replacepipextension withpycross: addrules_pycrossas a direct dep; replacepip.parse(→rules_ros2_pip_deps) withlock_import.import_poetry(→rules_ros2_py_deps); configure cross-compilation environments forx86_64-unknown-linux-gnu,aarch64-unknown-linux-gnu,aarch64-apple-darwinBUILD.bazel/WORKSPACE— remove now-unusedcompile_pip_requirementstarget; exportpyproject.tomlandpoetry.lockpyproject.toml/poetry.lock— new files replacingrequirements.txt/requirements_lock.txtros2/interfaces.bzl,ros2/test.bzl— update allrequirement(...)calls to useLabel("@rules_ros2_py_deps//:<pkg>")now that thehub repo is renamed
repositories/*.BUILD.bazel— update remaining references fromrules_ros2_pip_depstorules_ros2_py_depsexamples/MODULE.bazel— addhermetic_cc_toolchain(Zig CC) to enable cross-compilation in the examples workspace as an e2e test. However, for this to work, I have to incorporate the change in Remove -latomic from linkopts #618 in this PR.Test plan
Note
This PR is created against feature/jazzy, because that is the branch we are using. I am happy to create another version for the main branch if that's preferred.