MobileNativeFoundation / MobileNativeFoundation/rules_xcodeproj

Feature Request: generate a metal shader library target.

Open
#3,221 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature request
Dominant language
Swift
Stars
626
Forks
124
PR merge metrics
No merged PRs in 30d

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"]),
    ],

)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the BUILD.bazel example and the custom rule's XcodeProjAutomaticTargetProcessingInfo construction, especially xcode_targets and the missing product.original_basename error. Determine the provider data required for a top-level metal-library target, then verify that the generated Xcode project exposes the target and its Metal sources as requested.

Written by the indexing model from the issue text.

Assessment

Domain
build-system, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.