rules_proto icon indicating copy to clipboard operation
rules_proto copied to clipboard

generate a wrong platform protoc.exe when cross compile

Open xiedeacc opened this issue 3 years ago • 9 comments

my project import rules_proto and grpc, when I cross compile for arm with with --incompatible_enable_cc_toolchain_resolution and --platforms, it generated protoc.exe for arm, so protoc.exe cannot executed on build host( x86_64 linux), so build grpc will fail, I'm not sure it's grpc problem or rules_proto problem. here it's a demo: https://github.com/xiedeacc/tbox

I also open an issue at grpc: https://github.com/grpc/grpc/issues/30103

xiedeacc avatar Jun 24 '22 07:06 xiedeacc

@Yannic can U see see?

xiedeacc avatar Jun 28 '22 02:06 xiedeacc

@thii can u cc?

xiedeacc avatar Jun 29 '22 07:06 xiedeacc

can anybody take a look please?

xiedeacc avatar Jul 01 '22 10:07 xiedeacc

protoc is built for the execution platform (since we need to run it as part of the build), so it seems to me that the execution platform is somehow misconfigured. Can you share the exact command you're running?

Yannic avatar Jul 07 '22 11:07 Yannic

protoc is built for the execution platform (since we need to run it as part of the build), so it seems to me that the execution platform is somehow misconfigured. Can you share the exact command you're running?

clear && bazel build --incompatible_enable_cc_toolchain_resolution --platforms=@bazel_build_file//platforms:linux_gcc11_aarch64_none_musleabi -s --copt=-g3 --strip=never //...

xiedeacc avatar Jul 07 '22 12:07 xiedeacc

@Yannic demo may have toolchain download problem, but I have checked, it's fine, if demo has any problem, tell me, I'll fix it

xiedeacc avatar Jul 07 '22 13:07 xiedeacc

after I check rules_proto source code, I found my platforms value passby was

platform(
    name = "linux_gcc11_aarch64_none_musleabi",
    constraint_values = [
        "@platforms//cpu:aarch64",
        "@platforms//os:linux",
        ":gcc_11",
        ":musleabi",
    ],
)

and I defined a toolchain

toolchain(
    name = "gcc11_arm_aarch64_none_gnueabi_xcompile_toolchain",
    exec_compatible_with = [
        "@platforms//cpu:x86_64",
        "@platforms//os:linux",
    ],
    target_compatible_with = [
        "@platforms//cpu:aarch64",
        "@platforms//os:linux",
        "//platforms:gcc_11",
        "//platforms:gnueabi",
    ],
    toolchain = "@gcc11_arm_aarch64_none_gnueabi//:cc_toolchain",
    toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)

exec_compatible_with indicate it's for cross compiling, but rules_proto use target_compatible_with values I guess,

so cpu:aarch64 and os:linux will be recognised by rule_proto in BUILD.release, so :linux-aarch64": "@com_google_protobuf_protoc_linux_aarch64//:protoc" be selected.

as a conclusion: rules_proto not support cross compile? can update rules_proto support cross compile?

@Yannic

xiedeacc avatar Jul 09 '22 03:07 xiedeacc

maybe it's not rules_proto problem, I think may need bazel make select more flexible

xiedeacc avatar Jul 09 '22 03:07 xiedeacc

rules_proto need choose protoc platform by detect bazel excution platform(host), not by select, use select cannot support cross compile

xiedeacc avatar Jul 09 '22 03:07 xiedeacc