Skip to content

Commit

Permalink
Forcibly use the bundled version of @platforms for loading the host…
Browse files Browse the repository at this point in the history
… platform repo rule

#21877 happened because, even though we define `@platforms` to be the bundled version shipped with Bazel (which is 0.0.9 on HEAD), people tend to define their own versions of `@platforms` in WORKSPACE. If this ends up being a lower version (very likely), the subsequent `load` to use the `host_platform_repo` repo rule (which is a Starlark version of `local_config_platform`) will fail because that repo rule was only introduced in `platforms` version 0.0.9.

To resolve this conundrum, we define a new repo `@internal_platforms_do_not_use` that _also_ points to the bundled version of `@platforms`. Nobody is likely to define this repo, so we can fairly reliably get the Starlark repo rule, and also still allow people to override the actual `@platforms` targets they use.

This only affects WORKSPACE users; if `--enable_bzlmod` is set, the `@host_platform` seen by `@bazel_tools` will come from the module extension instead.

Work towards #18285.

Fixes #21877.

Closes #21902.

PiperOrigin-RevId: 622238362
Change-Id: I6335ab1bc26ba9ef54473d8a21fc5a8510a3ace5
  • Loading branch information
Wyverald authored and Copybara-Service committed Apr 5, 2024
1 parent 5882a0d commit 77469e0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@ maybe(
path = __embedded_dir__ + "/platforms",
)

maybe(
local_repository,
"internal_platforms_do_not_use",
path = __embedded_dir__ + "/platforms",
)

maybe(
local_config_platform,
"local_config_platform",
)

load("@platforms//host:extension.bzl", "host_platform_repo")
load("@internal_platforms_do_not_use//host:extension.bzl", "host_platform_repo")
maybe(
host_platform_repo,
"host_platform",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ public ImmutableList<String> getWorkspaceContents(MockToolsConfig config) {
"bind(name = 'has_androidsdk', actual = '@bazel_tools//tools/android:always_false')",
"local_repository(name = 'bazel_tools', path = '" + bazelToolWorkspace + "')",
"local_repository(name = 'platforms', path = '" + bazelPlatformsWorkspace + "')",
"local_repository(name = 'internal_platforms_do_not_use', path = '"
+ bazelPlatformsWorkspace
+ "')",
"local_repository(name = 'local_config_xcode', path = '" + xcodeWorkspace + "')",
"local_repository(name = 'com_google_protobuf', path = '" + protobufWorkspace + "')",
"local_repository(name = 'rules_java', path = '" + rulesJavaWorkspace + "')",
Expand Down Expand Up @@ -108,6 +111,7 @@ public ImmutableList<String> getWorkspaceRepos() {
"com_google_protobuf",
"local_config_xcode",
"platforms",
"internal_platforms_do_not_use",
"rules_java",
"rules_java_builtin",
"build_bazel_apple_support");
Expand Down

0 comments on commit 77469e0

Please sign in to comment.