I am struggling to configure copt, per_file_copt and action_action in transitions.
I try to configure action_env, copt and per_file_copt in .bzl file as follows:
def _impl(settings, attr):
_ignore = (settings, attr)
return {
"Platform A": {"//command_line_option:platforms": "@local_config_platform//:host"},
"Platform B": {
"//command_line_option:platforms": "@external_repo//platforms:ccarm",
"//command_line_option:action_env": "HOME=/home/user",
"//command_line_option:copt": "-std=c99",
"//command_line_option:per_file_copt": "[A-za-z0-9/]*.*\\.c$@-std=c99",
},
}
multi_arch_transition = transition(
implementation = _impl,
inputs = [],
outputs = [
"//command_line_option:platforms",
"//command_line_option:action_env",
"//command_line_option:copt",
"//command_line_option:per_file_copt",
],
)
def _rule_impl(ctx):
binary_a_platform_a = ctx.split_attr.binary_a["Platform A"]
binary_b_platform_b = ctx.split_attr.binary_b["Platform B"]
files = binary_a_platform_a.files.to_list() +
binary_b_platform_b.files.to_list()
return [DefaultInfo(
files = depset(direct = files),
)]
my_custom_multi_arch_rule = rule(
implementation = _rule_impl,
attrs = {
"_allowlist_function_transition": attr.label(
default =
"@bazel_tools//tools/allowlists/function_transition_allowlist",
),
"binary_a": attr.label(cfg = multi_arch_transition),
"binary_b": attr.label(cfg = multi_arch_transition),
},
)
And BUILD file
cc_binary(
name = "binary_platform_a",
srcs = ["src/main.c"],
deps = [
"//libraries/myOtherLib:myotherlib",
],
)
cc_binary(
name = "binary_platform_b",
srcs = ["src/main.c"],
deps = [
"//libraries/myOtherLib:myotherlib",
],
)
my_custom_multi_arch_rule(
name = "multiarch_build",
binary_a = ":binary_platform_a",
binary_b = ":binary_platform_b",
)
bazel build //path/to/my:multiarch_build
I expect to build two different binaries with two different toolchain configuration and action_env, copt etc.
I am getting the below error:
bazel crashed due to an internal error. Printing stack trace: java.lang.RuntimeException: Unrecoverable error while evaluating node 'BuildConfigurationKey[04f9fccc4a24c26345d63ba2951a1f83c7180224a7c90c9dcc74c3d50e15fbd5]' (requested by nodes 'ConfiguredTargetKey{label=//:multiarch_build, config=BuildConfigurationKey[704ad2962296774f59f0107d929a77b589ffc83a6582dcc6286bae4cd37bd13c]}') at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:633) at com.google.devtools.build.lib.concurrent.AbstractQueueVisitor$WrappedRunnable.run(AbstractQueueVisitor.java:365) at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(Unknown Source) at java.base/java.util.concurrent.ForkJoinTask.doExec(Unknown Source) at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(Unknown Source) at java.base/java.util.concurrent.ForkJoinPool.scan(Unknown Source) at java.base/java.util.concurrent.ForkJoinPool.runWorker(Unknown Source) at java.base/java.util.concurrent.ForkJoinWorkerThread.run(Unknown Source) Caused by: java.lang.ClassCastException: class java.lang.String cannot be cast to class java.util.Map$Entry (java.lang.String and java.util.Map$Entry are in module java.base of loader 'bootstrap') at com.google.devtools.build.lib.bazel.rules.BazelRuleClassProvider.lambda$static$0(BazelRuleClassProvider.java:251) at com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider.getActionEnvironment(ConfiguredRuleClassProvider.java:930) at com.google.devtools.build.lib.analysis.config.BuildConfigurationValue.create(BuildConfigurationValue.java:181) at com.google.devtools.build.lib.skyframe.BuildConfigurationFunction.compute(BuildConfigurationFunction.java:117) at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:562)
Pls help me to fix on this.