Migrate rules_go for incompatible_use_platforms_repo_for_constraints#2257
Migrate rules_go for incompatible_use_platforms_repo_for_constraints#2257hlopko wants to merge 3 commits intobazel-contrib:masterfrom
Conversation
|
I'm not sure how this passes with the latest Bazel version but fails with 0.23.0 (current minimum supported). Is the Is there any need to drop support for Bazel 0.23.0 or will this work automatically back that far? Mainly I'm wondering whether this should be cherry-picked to release branches. rules_go might make Bazel 1.0.1 the minimum supported version in the next release. We'll need to pick up support for the new |
|
Oh wow I didn't know you support Bazels back to 0.23. Yeah in that case I can add @platforms explicitly (it's bundled in Bazel since 0.28 but if there are @platforms already in the workspace Bazel's version is not activated). |
|
Cool, that would be awesome. I try not to break compatibility unless we need to (it was a big user complaint a while back, so lessons learned). If it's predeclared in Bazel 0.28, does it show up in |
|
Bazel appends stuff to the WORKSPACE file and that's how @platforms are patched. We use the same maybe approach as rules_go, just that our call is below rules_go's. Does it make sense? |
|
Hmm ok buildkite tells me I broke things :) I'll have to take a look tomorrow. |
I think so. So that means that I'd suggest we add an additional guard: About BuildKite failures: not sure why this would break toolchain resolution for 0.23.0. I think there was an old version of |
|
Oh I actually think rules_go should override the default platforms repo that is bundled in Bazel. Ideally we wouldn't bundle it in Bazel at all but some things are not ready for that yet. This way rules_go are in control, and you have a good mechanism to update platforms repo should you need to do it (e.g. after adding more constraints that rules_go need). But I'm happy to add the guard if you prefer that. Now off to the 0.23 investigations. |
|
Ok, this is quite complicated. We need to use labels to @bazel_tools//platforms for Bazel < 0.28 and labels to @platforms for >= 0.28. Which we could do using the nice def platforms_cpu_constraint_value(value):
if not native.bazel_version or versions.parse(native.bazel_version) >= (0, 28, 0):
return "@platforms//cpu:" + value
else:
return "@bazel_tools//platforms:" + valueBut there's a problem with that too - go/private/platforms.bzl is currently loaded in both repository context and in rule context. And native.bazel_version is only defined in the repository context. I might be able to fix that using hasattr, in the spirit of: def platforms_cpu_constraint_value(value):
if not hasattr(native, "bazel_version"):
# means we are in the rule context and compat repository is already defined
return "@io_bazel_rules_go_compat//:cpu:" + value
else if not native.bazel_version or versions.parse(native.bazel_version) >= (0, 28, 0):
return "@platforms//cpu:" + value
else:
return "@bazel_tools//platforms:" + valueI'll try that tomorrow, but if you have better ideas feel free to stop me :) |
|
Superceded by #2275 |
…azel-contrib#2257) This avoids the tag being added when it doesn't need to be, which can look confusing to users without context about what it means. Work towards bazel-contrib#1361
bazelbuild/bazel#8622