bazel-lib icon indicating copy to clipboard operation
bazel-lib copied to clipboard

Add platform_transition_binary rule

Open kormide opened this issue 2 years ago • 8 comments

@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

kormide avatar Nov 22 '22 00:11 kormide

@f0rmiga and @illicitonion would be good reviewers

alexeagle avatar Nov 22 '22 00:11 alexeagle

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.

illicitonion avatar Nov 22 '22 10:11 illicitonion

add me back as a reviewer once the test is added?

alexeagle avatar Dec 01 '22 18:12 alexeagle

add me back as a reviewer once the test is added?

Yup, sorry I've been meaning to get back to this one.

kormide avatar Dec 01 '22 18:12 kormide

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?

kormide avatar Dec 01 '22 22:12 kormide

It depends. You may be able to disable CGO if no C code is being used. What target needs it?

f0rmiga avatar Dec 02 '22 01:12 f0rmiga

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 avatar Dec 05 '22 11:12 illicitonion

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.

kormide avatar Dec 06 '22 18:12 kormide