Cross compilation workaround #3332
Replies: 2 comments 1 reply
-
I'm not sure this is supported / well-defined behavior? @aignas The requirements_lock attribute doesn't have a good understanding of multiplatform-ness. I think if there are env markers in the file, it's doable, but if not, then its. Useful debugging information: |
Beta Was this translation helpful? Give feedback.
-
The issue that is tracking this work is #260. Unless you use our experimental feature enabled via The |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi folks,
We are using Bazel to build our application and running into trouble with "cross-compilation" of our python projects. Specifically, we are trying to set up bazel such that we can run the projects on MacOS as well as build Debian-based docker containers locally.
For reference, we are on Bazel version 7.6 and rules_python 1.6.3
I have read through #260 and the related issues, as well as the docs at:
https://rules-python.readthedocs.io/en/latest/howto/multi-platform-pypi-deps.html
https://rules-python.readthedocs.io/en/latest/pypi/download.html#bazel-downloader-and-multi-platform-wheel-hub-repository
https://rules-python.readthedocs.io/en/latest/api/rules_python/python/extensions/pip.html#pip.parse
The issue is, when building containers, the python interpreter is correctly chosen (linux aarch64) but the dependency wheels are built for MacOS.
The command we use to build the container:
bazel build //services/service:service_oci_image --platforms=@toolchains_llvm//platforms:linux-aarch64 --extra_toolchains=@llvm_toolchain_cc//:cc-toolchain-aarch64-linux
Load it:
bazel run //:service_load --platforms=@toolchains_llvm//platforms:linux-aarch64
And finally run it:
docker run service:latest
This fails due to the wrong wheel being chosen (in the container):
find /services/service -type f -name "*_pydantic_core*.so"
/services/service/service_bin.runfiles/rules_python~~pip~pip_312_pydantic_core/site-packages/pydantic_core/_pydantic_core.cpython-312-darwin.so
Here's what we do:
MODULE.bazel
BUILD.bazel
services/service/BUILD.bazel
Our requirements files are compiled on the respective platforms and contain package hashes.
Is there an intermediate solution until #260 is complete that we can use?
Additionally, it would be nice if the solution can play well with gazelle.
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions