-
Notifications
You must be signed in to change notification settings - Fork 111
Description
rules_apple has a rule named apple_metal_library which can create a metallib, but it is not a top level target for rules_xcodeproj, it used as resource to copy.
Xcode has a template of metal-library target and Xcode seems to be the only IDE support metal shader file, so i want to create a custom rule for make a top level target and support features like code highlight, jump to definition and show live issues on Xcode.
Support such target may not meet design goals of rules_xcodeproj,so I just write simple rule to compile metal shader on my own and using "XcodeProjAutomaticTargetProcessingInfo" provider to generate a top level target, but failed with message:
"Error in fail: "@@//Programs/Test:my-metallib-target" does not have "product.original_basename" set."
due to lack of example of how to using XcodeProjAutomaticTargetProcessingInfo, i could not figure out a way to solve this problem. any solution and more detail about provider's attr xcode_targets? thanks.
here are some code from rule.
def _create_xcodeproj_provider(ctx):
provider = XcodeProjAutomaticTargetProcessingInfo(
app_icons = None,
args = None,
bundle_id = None,
collect_uncategorized_files = False,
deps = [],
entitlements = None,
env = None,
extra_files = [],
implementation_deps = [] ,
is_header_only_library = False,
is_mixed_language = False,
is_supported = True,
is_top_level = True,
label = ctx.label,
link_mnemonics = [],
non_arc_srcs = [],
provisioning_profile = [],
srcs = ctx.files.srcs,
target_type = "compile",
xcode_targets = {},
)
return provider
def _metal_library_impl(ctx):
# toolchain setup code ...
output_file = ctx.actions.declare_file(ctx.attr.name + ".metallib")
# actions code ....
# for xcodegen
xcodeproj_target_provider = _create_xcodeproj_provider(ctx)
return [DefaultInfo(files = depset([output_file])), xcodeproj_target_provider]
metal_library = rule(
implementation = _metal_library_impl,
attrs = {
"srcs": attr.label_list(allow_files = [".metal"]), #using file ext .metal
"hdrs": attr.label_list(allow_files = True)
},
executable = False,
toolchains = [":metal_toolchain_type"]
)
# BUILD.bazel
xcodeproj(
name = "hello-metal-xcproj",
project_name = "HelloMetal",
tags = ["manual"],
target_name_mode = "label",
top_level_targets = [
top_level_target(":my-metallib-target", target_environments = ["device"]),
],
)