bazel-lib
bazel-lib copied to clipboard
Add platform_transition_binary rule
@alexeagle this was mostly copy-pasta'ed from https://github.com/bazelbuild/rules_rust/issues/276#issuecomment-1320198911.
Transitions are a new topic in Bazel for me. I'm not sure how to properly exercise or test the rule
@f0rmiga and @illicitonion would be good reviewers
Looks great, thanks!
Test-wise, I'd suggest an integration test in lib/tests/transitions/BUILD.bazel that looks something like:
go_binary(
name = "generic_go_binary",
srcs = [...],
tags = ["manual"],
)
platform_transition_binary(
name = "transitioned_go_binary_x86_64",
target_platform = ":x86_64_linux",
)
platform_transition_binary(
name = "transitioned_go_binary_armv7_linux",
target_platform = ":armv7_linux",
)
sh_test(
name = "test_go_binary_is_x86_64",
srcs = [...],
data = [":transitioned_go_binary_x86_64"],
args = ["$(rootpath :transitioned_go_binary_x86_64)"],
)
and then a sh_test
which runs file "$(realpath "$1")"
and asserts the output looks like it's for the right platform.
add me back as a reviewer once the test is added?
add me back as a reviewer once the test is added?
Yup, sorry I've been meaning to get back to this one.
I'm getting this error when I try to declare a platform_transition_binary
with a target platform that doesn't match my linux x64 machine (for the tests):
ERROR: /home/derek/.cache/bazel/_bazel_derek/cb18fde45e94a264d41b0ba5b41ae079/external/io_bazel_rules_go/BUILD.bazel:86:17: While resolving toolchains for target @io_bazel_rules_go//:cgo_context_data: No matching toolchains found for types @bazel_tools//tools/cpp:toolchain_type.
Is there something I need to do to register a cpp toolchain?
It depends. You may be able to disable CGO if no C code is being used. What target needs it?
Yeah, I suspect setting pure = "on"
will make this go away, but if you push a WIP I'm happy to play around with it locally!
Yeah, I suspect setting
pure = "on"
will make this go away, but if you push a WIP I'm happy to play around with it locally!
@illicitonion I tried pure = "on"
but that didn't solve the missing cpp toolchain issue. I pushed up what I have locally to reproduce it.