Tools in local-only genrule are not built with the correct local exec platform
- Dominant language
- Java
- Stars
- 25.8k
- Forks
- 4.6k
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 75
Description
### Description of the bug:
Internally we have a macro with a genrule like this
```python
def some_macro(name, ...):
...
native.genrule(
name = name,
...
cmd = "$(location //tools/my_tool) ...",
local = True,
tags = ["manual"],
tools = [
"//tools/my_tool",
],
)
```
this runs fine on a local-exec build. However, using a remote exec where host=MacOS/arm64 and exec+target=linux/amd64 would cause this genrule to use a linux/amd64 version of `//tools/my_tool`.
We fixed this by adding
```diff
@@ -1,3 +1,5 @@
+load("@local_config_platform//:constraints.bzl", "HOST_CONSTRAINTS")
+
...
+ exec_compatible_with = HOST_CONSTRAINTS,
```
to the genrule to force it to use a MacOS/arm64 version of `//tools/my_tool`.
I think it would make sense for this exec_compatible_with to be applied automatically when `local = True` is set.
### Which category does this issue belong to?
Configurability
### What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
_No response_
### Which operating system are you running Bazel on?
7.4.1
### What is the output of `bazel info release`?
_No response_
### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.
_No response_
### What's the output of `git remote get-url origin; git rev-parse HEAD` ?
```text
```
### If this is a regression, please try to identify the Bazel commit where the bug was introduced with bazelisk --bisect.
_No response_
### Have you found anything relevant by searching the web?
_No response_
### Any other information, logs, or outputs that you want to share?
_No response_
Contributor guide
Research direction
Start at Bazel's genrule implementation and the platform-selection path used when local=True; compare it with the explicit exec_compatible_with=HOST_CONSTRAINTS workaround in the issue. Done means a local-only genrule selects the host-compatible tool under the described MacOS/arm64 and Linux/amd64 configuration, with coverage for the cross-platform case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- linux, macos
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100