Metal Shader inside Swift Package not found?

Hello everyone! I am trying to wrap a ViewModifier inside a Swift Package that bundles a metal shader file to be used in the modifier. Everything works as expected in the Preview, in the Simulator and on a real device for iOS. It also works in Preview and in the Simulator for tvOS but not on a real AppleTV. I have tried this on a 4th generation Apple TV running tvOS 26.3 using Xcode 26.2.0.

Xcode logs the following: The metallib is processed and exists in the bundle.

Compiler failed to build request
precondition failure: pipeline error: custom_effect-fg2a5cia7fmha4: error: unresolved visible function reference: custom_fn
  Reason: visible function not loaded
Compiler failed to build request
precondition failure: pipeline error: custom_effect-fg2a5cia7fmha4: error: unresolved visible function reference: custom_fn
  Reason: visible function not loaded
Compiler failed to build request
precondition failure: pipeline error: custom_effect-fg2a5cia7fmha4: error: unresolved visible function reference: custom_fn
  Reason: visible function not loaded
Compiler failed to build request
precondition failure: pipeline error: custom_effect-fg2a5cia7fmha4: error: unresolved visible function reference: custom_fn
  Reason: visible function not loaded
Compiler failed to build request
precondition failure: pipeline error: custom_effect-fg2a5cia7fmha4: error: unresolved visible function reference: custom_fn
  Reason: visible function not loaded
Compiler failed to build request
precondition failure: pipeline error: custom_effect-fg2a5cia7fmha4: error: unresolved visible function reference: custom_fn
  Reason: visible function not loaded

Contents of Package.swift:

import PackageDescription

let package = Package(
    name: "Test",
    platforms: [
        .iOS(.v17),
        .tvOS(.v17)
    ],
    products: [
        .library(
            name: "Test",
            targets: [
                "Test"
            ]
        )
    ],
    targets: [
        .target(
            name: "Test",
            resources: [
                .process("Shaders")
            ]
        ),
        .testTarget(
            name: "TestTests",
            dependencies: [
                "Test"
            ]
        )
    ]
)

Content of my metal file:

#include <metal_stdlib>
using namespace metal;

[[ stitchable ]] float2 complexWave(float2 position, float time, float2 size, float speed, float strength, float frequency) {
    float2 normalizedPosition = position / size;
    float moveAmount = time * speed;

    position.x += sin((normalizedPosition.x + moveAmount) * frequency) * strength;
    position.y += cos((normalizedPosition.y + moveAmount) * frequency) * strength;

    return position;
}

And my ViewModifier:

import MetalKit
import SwiftUI

extension ShaderFunction {
    static let complexWave: ShaderFunction = {
        ShaderFunction(
            library: .bundle(.module),
            name: "complexWave"
        )
    }()
}

extension Shader {
    static func complexWave(arguments: [Shader.Argument]) -> Shader {
        Shader(function: .complexWave, arguments: arguments)
    }
}

struct WaveModifier: ViewModifier {
    let start: Date = .now

    func body(content: Content) -> some View {
        TimelineView(.animation) { context in
            let delta = context.date.timeIntervalSince(start)

            content
                .visualEffect { view, proxy in
                    view.distortionEffect(
                        .complexWave(
                            arguments: [
                                .float(delta),
                                .float2(proxy.size),
                                .float(0.5),
                                .float(8),
                                .float(10)
                            ]
                        ),
                        maxSampleOffset: .zero
                    )
                }
        }
        .onAppear {
            let paths = Bundle.module.paths(forResourcesOfType: "metallib", inDirectory: nil)
            print(paths)
        }
    }
}

extension View {
    public func wave() -> some View {
        modifier(WaveModifier())
    }
}

#Preview {
    Image(systemName: "cart")
        .wave()
}

Any help is appreciated.

Metal Shader inside Swift Package not found?
 
 
Q