Skip to content

Toolchain uses target_compatible_with for platform compatibility #1739

@matzipan

Description

@matzipan

🐞 bug report

Affected Rule

python_toolchain_build_file_content

Is this a regression?

Unsure

Description

When it configures py_toolchain_suite, it uses target_compatible_with to configure the platform compatibilties.

It should instead use exec_compatible_with.

Yes, on most systems where rules_python runs this is one and the same. But if I want to use rules_python in my cross compilation toolchain, I can't do it. target_compatible_with would say it's incompatible. See here.

The following change allows me to do that:

diff --git a/python/private/toolchains_repo.bzl b/python/private/toolchains_repo.bzl
index c586208..38648ee 100644
--- a/python/private/toolchains_repo.bzl
+++ b/python/private/toolchains_repo.bzl
@@ -63,11 +63,11 @@ def python_toolchain_build_file_content(
 py_toolchain_suite(
     user_repository_name = "{user_repository_name}_{platform}",
     prefix = "{prefix}{platform}",
-    target_compatible_with = {compatible_with},
+    exec_compatible_with = {exec_compatible_with},
     python_version = "{python_version}",
     set_python_version_constraint = "{set_python_version_constraint}",
 )""".format(
-            compatible_with = meta.compatible_with,
+            exec_compatible_with = meta.exec_compatible_with,
             platform = platform,
             set_python_version_constraint = set_python_version_constraint,
             user_repository_name = user_repository_name,
diff --git a/python/versions.bzl b/python/versions.bzl
index 9a28f15..11aa267 100644
--- a/python/versions.bzl
+++ b/python/versions.bzl
@@ -408,7 +408,7 @@ MINOR_MAPPING = {
 
 PLATFORMS = {
     "aarch64-apple-darwin": struct(
-        compatible_with = [
+        exec_compatible_with = [
             "@platforms//os:macos",
             "@platforms//cpu:aarch64",
         ],
@@ -418,7 +418,7 @@ PLATFORMS = {
         arch = "arm64",
     ),
     "aarch64-unknown-linux-gnu": struct(
-        compatible_with = [
+        exec_compatible_with = [
             "@platforms//os:linux",
             "@platforms//cpu:aarch64",
         ],
@@ -429,7 +429,7 @@ PLATFORMS = {
         arch = "aarch64",
     ),
     "ppc64le-unknown-linux-gnu": struct(
-        compatible_with = [
+        exec_compatible_with = [
             "@platforms//os:linux",
             "@platforms//cpu:ppc",
         ],
@@ -440,7 +440,7 @@ PLATFORMS = {
         arch = "ppc64le",
     ),
     "s390x-unknown-linux-gnu": struct(
-        compatible_with = [
+        exec_compatible_with = [
             "@platforms//os:linux",
             "@platforms//cpu:s390x",
         ],
@@ -451,7 +451,7 @@ PLATFORMS = {
         arch = "s390x",
     ),
     "x86_64-apple-darwin": struct(
-        compatible_with = [
+        exec_compatible_with = [
             "@platforms//os:macos",
             "@platforms//cpu:x86_64",
         ],
@@ -459,7 +459,7 @@ PLATFORMS = {
         arch = "x86_64",
     ),
     "x86_64-pc-windows-msvc": struct(
-        compatible_with = [
+        exec_compatible_with = [
             "@platforms//os:windows",
             "@platforms//cpu:x86_64",
         ],
@@ -467,7 +467,7 @@ PLATFORMS = {
         arch = "x86_64",
     ),
     "x86_64-unknown-linux-gnu": struct(
-        compatible_with = [
+        exec_compatible_with = [
             "@platforms//os:linux",
             "@platforms//cpu:x86_64",
         ],

🔬 Minimal Reproduction

Define a platform which doesn't match your host platform and try to use it, as if for cross-compilation.

🔥 Exception or Error

No matching toolchain.

🌍 Your Environment

Operating System:

Linux, x86_64

Output of bazel version:

6.3.2

Rules_python version:

0.29.0

Anything else relevant?

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: toolchainRelated to the toolchains provided by rules_python

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions