bazel-contrib / bazel-contrib/rules_multitool
Using as a native_binary / native_test
- Dominant language
- Starlark
- Stars
- 25
- Forks
- 11
- PR merge metrics
- No merged PRs in 30d
Description
This is honestly probably a doc suggestion, I think, though I'm not quite sure how to phrase it. If you want to use the multitool binary as a _tool_, i.e. as part of the build, it seems like:
- If you want it to be safe under cross-compilation, you must use the `:cwd` target to ensure that there is a transition to `cfg=exec` (otherwise, when you run with `--platforms `, it'll download the wrong binary)
- If you want it to work on windows, you have to use a file extension that matches the original one (in other words, `.bat`).
I think this means that this is exactly what you need to invoke (for, let's say, using ruff as a test):
```python
load("@bazel_skylib//rules:native_binary.bzl", "native_test")
native_test(
name = "ruff_lint",
# use cwd to run the binary through a cfg=exec label, so things don't break when target != exec
src = "@multitool//tools/ruff:cwd",
# use .bat because unix doesn't care about the extension, but windows won't work otherwise
out = "ruff_lint.bat",
args = [
"--version",
],
data = [
"@multitool//tools/ruff:cwd",
]
)
```
I'm curious if you know if a better way to handle this.
Contributor guide
Assessment
This issue has not been assessed yet.