Skip to content

Commit 0d1250a

Browse files
Chris Thompsonfacebook-github-bot
authored andcommitted
Support selector for functions.yaml and custom_ops.yaml targets in et_operator_library (#5957)
Summary: Pull Request resolved: #5957 executorch_generated_library accepts functions_yaml_target: A Buck target pointing to the `functions.yaml` file to use. Optional, but at least one of `functions_yaml_target` and `custom_ops_yaml_target` must be specified. custom_ops_yaml_target: A Buck target pointing to the `custom_ops.yaml` file to use. Optional, but at least one of `functions_yaml_target` and `custom_ops_yaml_target` must be specified. However the rule expects these targets to be the string of the exact target "//xplat/..../functions_yaml:functions.yaml" and had issues with the parameter being of type 'selector' select({"//arvr:my_constraint": "//xplat/..../functions_yaml:functions.yaml", ....}) Selectively providing this target based off of config/constraint can be helpful, and it seems like the limitation was the formatting done on the strings prior to calling genrules inside of the rule. What this enables: Building the same et_operator_library target while specifying the functions.yaml and custom_ops.yaml targets as a function of a constraint, like processor type. Example: D64004596 Reviewed By: tarun292, larryliu0820 Differential Revision: D63043331 fbshipit-source-id: 9ef00f2a7625b0b29ae860513d1044923d0a4a34
1 parent ed9f50f commit 0d1250a

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

shim/xplat/executorch/codegen/codegen.bzl

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "get_default_executorch_platforms", "is_xplat", "runtime", "struct_to_json")
2+
load("@fbsource//xplat/executorch/build:selects.bzl", "selects")
23
load("@fbsource//xplat/executorch/kernels/portable:op_registration_util.bzl", "portable_header_list", "portable_source_list")
34

45
# Headers that declare the function signatures of the C++ functions that
@@ -261,8 +262,13 @@ def _prepare_custom_ops_genrule_and_lib(
261262
"headers": [],
262263
"srcs": custom_ops_sources,
263264
}
265+
my_cmd = ""
266+
for rule_substr in genrule_cmd:
267+
if my_cmd != "":
268+
my_cmd += " "
269+
my_cmd += rule_substr
264270
genrules[genrule_name] = {
265-
"cmd": " ".join(genrule_cmd),
271+
"cmd": my_cmd,
266272
"outs": {out: [out] for out in CUSTOM_OPS_NATIVE_FUNCTION_HEADER + custom_ops_sources},
267273
}
268274
return genrules, libs
@@ -294,7 +300,7 @@ def exir_custom_ops_aot_lib(
294300
"""
295301
genrules, libs = _prepare_custom_ops_genrule_and_lib(
296302
name = name,
297-
custom_ops_yaml_path = "$(location {})".format(yaml_target),
303+
custom_ops_yaml_path = selects.apply(yaml_target, lambda y: "$(location {})".format(y)),
298304
kernels = kernels,
299305
deps = deps,
300306
)
@@ -495,9 +501,8 @@ def executorch_generated_lib(
495501
# merge functions.yaml with fallback yaml
496502
if functions_yaml_target:
497503
merge_yaml_name = name + "_merge_yaml"
498-
cmd = ("$(exe fbsource//xplat/executorch/codegen/tools:merge_yaml) " +
499-
"--functions_yaml_path=$(location {}) ".format(functions_yaml_target) +
500-
"--output_dir=$OUT ")
504+
cmd = selects.apply(functions_yaml_target, lambda value: "$(exe fbsource//xplat/executorch/codegen/tools:merge_yaml) " +
505+
"--functions_yaml_path=$(location {}) --output_dir=$OUT ".format(value))
501506
if fallback_yaml_target:
502507
cmd = cmd + "--fallback_yaml_path=$(location {}) ".format(fallback_yaml_target)
503508
runtime.genrule(
@@ -512,7 +517,7 @@ def executorch_generated_lib(
512517
else:
513518
functions_yaml_path = None
514519
if custom_ops_yaml_target:
515-
custom_ops_yaml_path = "$(location {})".format(custom_ops_yaml_target)
520+
custom_ops_yaml_path = selects.apply(custom_ops_yaml_target, lambda value: "$(location {})".format(value))
516521
else:
517522
custom_ops_yaml_path = None
518523

@@ -559,9 +564,14 @@ def executorch_generated_lib(
559564
genrules[genrule_name]["cmd"].append(
560565
"--op_selection_yaml_path=$(location :{}[selected_operators.yaml])".format(oplist_dir_name),
561566
)
567+
my_cmd = ""
568+
for rule_substr in genrules[genrule_name]["cmd"]:
569+
if my_cmd != "":
570+
my_cmd += " "
571+
my_cmd += rule_substr
562572
runtime.genrule(
563573
name = genrule_name,
564-
cmd = " ".join(genrules[genrule_name]["cmd"]),
574+
cmd = my_cmd,
565575
outs = {f: [f] for f in genrules[genrule_name]["outs"]},
566576
default_outs = ["."],
567577
platforms = platforms,

0 commit comments

Comments
 (0)