soniaai / rules_poetry

Bazel rules that use Poetry for Python package management
MIT License
73 stars 22 forks source link

Does rules_poetry understand target platforms / cross-compilation? #16

Open njlr opened 2 years ago

njlr commented 2 years ago

I was wondering how rules_poetry might handle this scenario:

  1. Host machine is macOS
  2. A py_binary called //:app with dependencies from rules_poetry
  3. And a Docker image called //:app_image constructed using container_image (from rules_docker) that is based on Linux AMD64 that contains the py_binary

Now, when doing bazel run //:app, Poetry should install for the host machine (in this case macOS)

But when doing bazel build //:app_image , Poetry should install for Linux AMD64, since this is the base of the Docker image

Is there a way to configure rules_poetry for this?

Perhaps with two calls in the WORKSPACE?

poetry(
  name = "poetry_host",
  lockfile = "//:poetry.lock",
  pyproject = "//:pyproject.toml",
)

poetry(
  name = "poetry_linux_amd64",
  lockfile = "//:poetry.lock",
  pyproject = "//:pyproject.toml",
  target = [ "linux_x64" ],
)

Is this possible or even required?

NathanHowell commented 1 year ago

I haven't check into this. If there are binary wheels available for the target platform it should be possible to make this work with transitions, though other language rules have been running into issues with rules_docker's transitions support. it would be a great feature though.