我如何"选择"执行目标?



我有以下规则,但它不起作用,因为select正在评估target platform而不是host platformexecution platform

有谁知道怎么让它工作吗?

cargo_build_script(
name = "build_script",
srcs = ["build.rs"],
build_script_env = select({
"@bazel_tools//src/conditions:linux_aarch64": {
"PROTOC": "$(execpath @com_google_protobuf_protoc_linux_aarch64//:protoc)",
"RUSTFMT": "$(execpath @rust_linux_aarch64//:rustfmt_bin)",
},
"@bazel_tools//src/conditions:linux_x86_64": {
"PROTOC": "$(execpath @com_google_protobuf_protoc_linux_x86_64//:protoc)",
"RUSTFMT": "$(execpath @rust_linux_x86_64//:rustfmt_bin)",
},
"@bazel_tools//src/conditions:darwin_arm64": {
"PROTOC": "$(execpath @com_google_protobuf_protoc_macos_aarch64//:protoc)",
"RUSTFMT": "$(execpath @rust_darwin_aarch64//:rustfmt_bin)",
},
"@bazel_tools//src/conditions:darwin_x86_64": {
"PROTOC": "$(execpath @com_google_protobuf_protoc_macos_x86_64//:protoc)",
"RUSTFMT": "$(execpath @rust_darwin_x86_64//:rustfmt_bin)",
},
}),
crate_features = [
"transport",
],
data = [
"//api/protos:protos",
"@com_google_protobuf//:protoc",
"@com_google_protobuf//:well_known_protos",
] + select({
"@bazel_tools//src/conditions:linux_aarch64": [
"@rust_linux_aarch64//:rustfmt_bin",
"@com_google_protobuf_protoc_linux_aarch64//:protoc",
],
"@bazel_tools//src/conditions:linux_x86_64": [
"@rust_linux_x86_64//:rustfmt_bin",
"@com_google_protobuf_protoc_linux_x86_64//:protoc",
],
"@bazel_tools//src/conditions:darwin_arm64": [
"@rust_darwin_aarch64//:rustfmt_bin",
"@com_google_protobuf_protoc_macos_aarch64//:protoc",
],
"@bazel_tools//src/conditions:darwin_x86_64": [
"@rust_darwin_x86_64//:rustfmt_bin",
"@com_google_protobuf_protoc_macos_x86_64//:protoc",
],
}),
deps = [
"@raze__tonic_build__0_6_2//:tonic_build",
],
)

我知道每个规则都有一个exex_compatible_with选项,但这没有帮助。我必须为每个execution platform创建一个规则,然后再次选择给定平台的每个规则。

最后,我用:

cargo_build_script(
name = "build_script",
srcs = ["build.rs"],
build_script_env = {
"PROTOC": "$(execpath @com_google_protobuf//:protoc)",
"RUSTFMT": "$(rootpath @rules_rust//rust/toolchain:current_rustfmt_files)",
},
crate_features = [
"transport",
],
data = [
"//api/protos",
"@com_google_protobuf//:well_known_protos",
"@rules_rust//rust/toolchain:current_rustfmt_files",
],
tools = [
"@com_google_protobuf//:protoc",
],
deps = all_crate_deps(
normal = True,
normal_dev = True,
),
)

执行平台在规则内部处理。

相关内容

最新更新